Beispiel #1
0
        public async Task <UserCreateModel> UpdateUser(UserCreateModel model)
        {
            try
            {
                tblUserProfile data = await Task.Run(() => UserOperations.UpdateUser(model.ConvertTotblUser()));

                return(data.ConvertToUser());
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #2
0
        public async Task <UserCreateModel> GetUser(string Id)
        {
            try
            {
                tblUserProfile data = await Task.Run(() => UserOperations.GetUser(Id));

                return(data.ConvertToUser());
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #3
0
        internal static async Task <UserRolesModel> GetUserRolesn(string UserID)
        {
            try
            {
                using (db = new eMSPEntities())
                {
                    UserRolesModel user = new UserRolesModel();

                    //user.roles = await Task.Run(() => db.tblUserProfiles.Where(x => x.AspNetUser.Id == UserID)
                    //                                              .Join(db.AspNetRoleGroups,
                    //                                              u => u.RoleGroupId,
                    //                                              rg => rg.Id, (u, rg) => new
                    //                                              {
                    //                                                  RoleGroupId = rg.Id
                    //                                              }).Join(db.AspNetRoleGroupRoles,
                    //                                              r => r.RoleGroupId,
                    //                                              rgr => rgr.RoleGroupId, (r, rgr) => new
                    //                                              {
                    //                                                  rolesId = rgr.RoleId
                    //                                              }).Join(db.AspNetRoles,
                    //                                              ro => ro.rolesId,
                    //                                              b => b.Id, (ro, b) => new RoleModel
                    //                                              {
                    //                                                  id = b.Id,

                    //                                                  Name = b.Name
                    //                                              }).ToList());

                    var objlist = db.AspNetUsers.Where(x => x.Id == UserID).SingleOrDefault();

                    user.roles = objlist.AspNetRoles.Select(X => new RoleModel()
                    {
                        Name = X.Name, id = X.Id
                    }).ToList();


                    //user.roles = await (from profile in db.tblUserProfiles
                    //                    join rolegrp in db.AspNetRoleGroups on profile.RoleGroupId equals rolegrp.Id
                    //                    join grpRoles in db.AspNetRoleGroupRoles on rolegrp.Id equals grpRoles.RoleGroupId
                    //                    join role in db.AspNetRoles on grpRoles.RoleId equals role.Id
                    //                    select new RoleModel { id = role.Id, Name = role.Name }).ToListAsync();

                    //db.AspNetRoleGroupRoles.Where(x=>x.RoleGroupId==)

                    tblUserProfile up = db.tblUserProfiles.Where(a => a.UserID == UserID)
                                        .Include(a => a.tblCountry)
                                        .Include(a => a.tblCountryState)
                                        .SingleOrDefault();
                    user.user = new UserModel();

                    user.user.user   = up.ConvertToUser();
                    user.user.userId = UserID;

                    long mspId = db.tblUserProfiles.Where(x => x.AspNetUser.Id == UserID).Join(db.tblMSPUsers, u => u.UserID, rg => rg.UserID, (l, r) => new { l, r }).Select(b => b.r.MSPID).FirstOrDefault();
                    long supId = db.tblUserProfiles.Where(x => x.AspNetUser.Id == UserID).Join(db.tblSupplierUsers, u => u.UserID, rg => rg.UserID, (l, r) => new { l, r }).Select(b => b.r.SupplierID).FirstOrDefault();
                    long cutId = db.tblUserProfiles.Where(x => x.AspNetUser.Id == UserID).Join(db.tblCustomerUsers, u => u.UserID, rg => rg.UserID, (l, r) => new { l, r }).Select(b => b.r.CustomerID).FirstOrDefault();

                    if (mspId != 0)
                    {
                        user.user.companyId   = mspId;
                        user.user.companyType = "MSP";
                    }
                    else if (supId != 0)
                    {
                        user.user.companyId   = supId;
                        user.user.companyType = "Supplier";
                    }
                    else if (supId != 0)
                    {
                        user.user.companyId   = cutId;
                        user.user.companyType = "Customer";
                    }

                    return(user);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }