Posts

Thinking about model changes when doing MongoDb Aggregations

When writing mongoDB Aggregation quarries in C# it will write as bellow. var UserAccount = new UserAccountModel(); var matchEmail = new BsonDocument { { "$match", new BsonDocument { { "Email", Email } } } }; var projectProfiles = new BsonDocument { { "$project", new BsonDocument { { "_id", 0 }, { "Profile", "UserAccount.UserProfiles" } } } }; var unwindProfile = new BsonDocument { { "$unwind", "$Profile" } }; var matchCompanyId = new BsonDocument { { "$match", new BsonDocument { { "Profile.UserCompanyID", CompanyId } } } }; The result of the above quarry depends on the model  CompanyModel  and if it has been changed the aggregation will throw an error. As an example, UserAccount.UserProfiles  change into  UserAccount.UserProfileList To make safe this will not be happen and to get notify when the model has been changed at the compilation level, you can use the following way. ...

Remove objects from an mongoDB Array

mongoDB Collection {     "_id" : ObjectId("58d0e87a0fa052d188424bc7"),     "_CompanyID" : BinData(3, "+4IlRPd+6UmiuIJ7sNHwfQ=="),     "CompanyName" : "dprsales7200",     "CustomRoles" : [         {             "RoleId" : NumberInt(3),             "Name" : "ss"         },         {             "RoleId" : NumberInt(4),             "Name" : "sssdd"         }     ]     } } Q. I want to remove a Custom Role from the CustomRoles array which matches the RoleID. C# Solution public async Task<byte> deleteCustomRoleToCompany(Guid companyId, IdentityUserRole role)         {             var companyCollection = dbRepo.GetDbCollection().GetCollection<CompanyModel...

Issue with AngularJs filter in ng-repeat

When using a filter inside ng-repeat I found a problem where it behaving strange and showing the same value in two location even I filtered it using javascript logic. Then I found out the problem is with the text of the label. AngularLogic: ng-repeat="item in customRole.userActions | filter:item.ActionGroup='Chat'" What I'm getting from the C#: [Description("Create Ticket From Chat")] Since the description is containing the text 'Chat' it will filter the wrong actions and show them in wrong places.

mongoDB Aggregations to C#

mongoDB Aggregations to C# mongoDB Aggregation  db.UserAccount.aggregate(   // Pipeline   [     // Stage 1     {       $match: {                "UserProfiles.UserCompanyID": BinData(3, "mwOPobw5rtf6XidzEfd4PA==")       }     },     // Stage 2     {       $project: {                Roles: "$UserProfiles.UserRoles"       }     },     // Stage 3     {       $unwind: "$Roles"     }   ] ); C#  var collection = dbRepo.GetDbCollection().GetCollection<BsonDocument>(DBColletions.CollectionUserAccount);   ...

Query mongoDB with C# LINQ

Query mongoDB with C# LINQ 1. Project     Get property of the model directly from the database. Eg: var isActive = await collection.Find(a => a.userID == userId). Project (s => s.IsActive).FirstOrDefaultAsync(); without using: var isActive = (await collection.FindAsync(a => a.userID == userId).Result.FirstOrDefaultAsync()).IsActive; which gets the entire model and query it for the property; IsActive.

Passing values betwwen Windows Forms in Realtime - Using Delegates and Events

Image
Hi all, in this post I'll explain how to use delegates to pass value to another form. To demonstrate this I'll use windows forms. Task: 1. There is a Windows form called Tool. And there is another Windows form called Register. 2. We need to get the name of the user from the Register form to the Tool form. I have created a Windows form project and named it as BaseNumbers. You can use any number as you like. Then I have designed the 2 forms as bellow. To make the things work we have to use delegates and events. Register Form namespace BaseNumbers { public delegate void RegisterUser(string name); public partial class Register : Form { public event RegisterUser registerUser; public Register() { InitializeComponent(); } private void btnRegister_Click(object sender, EventArgs e) { if (txtUsername.Text != "") { if (registerUser != null) ...

ASP.Net Multi-Tier Architecture : With Product sample

Image
In this post I'll explain how to manage a much more better structure in your web applications with Multi-Tier architectures. In this post we are going to experience the Three-Tier architecture. Even-though we name this as a Three-Tier architecture we can divide it into more levels to manage the complexity of the project. This is the architecture we are going to implement in this post.   Responsibilities of each layers: 1. Application Layer - This is the top level and the layer which the end user getting access to. Which simply means this is the web site interface which include all the aspx files, css files and other scripts. 2. Business Layer - This is the main layer of the application which holds the business logic. I have divide this layer in to 2 layers. Business Logic Layer - This layer holds the pure business logic itself. Business Domain Layer - This holds the domain objects of the solution which require in the business logic. (Ex: Product, User) 3. Database L...