public HttpResponseMessage Post(HttpRequestMessage request, ApplicationGroupViewModel appGroup)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             var newAppGroup = new ApplicationGroup();
             newAppGroup.UpdateApplicationGroup(appGroup);
             var result = _appGroupService.Add(newAppGroup);
             if (result.IsSuccessStatusCode)
             {
                 var newGroup = result.Content.ReadAsAsync <ApplicationGroupViewModel>().Result;
                 response = request.CreateResponse(result.StatusCode, newGroup);
             }
             else
             {
                 response = request.CreateErrorResponse(result.StatusCode, result.Content.ReadAsStringAsync().Result);
             }
         }
         return response;
     }));
 }
Esempio n. 2
0
        public HttpResponseMessage Create(HttpRequestMessage request, ApplicationGroupViewModel applicationGroupViewModel)
        {
            if (ModelState.IsValid)
            {
                var newAppGroup = new ApplicationGroup();
                newAppGroup.Name = applicationGroupViewModel.Name;
                try
                {
                    var appGroup = _applicationGroupService.Add(newAppGroup);
                    _applicationGroupService.Save();

                    var listRoleGroup = new List <ApplicationRoleGroup>();
                    foreach (var role in applicationGroupViewModel.Roles)
                    {
                        listRoleGroup.Add(new ApplicationRoleGroup()
                        {
                            GroupId = appGroup.ID,
                            RoleId  = role.Id
                        });
                    }
                    _applicationRoleService.AddRolesToGroup(listRoleGroup, appGroup.ID);
                    _applicationRoleService.Save();

                    return(request.CreateResponse(HttpStatusCode.OK, applicationGroupViewModel));
                }
                catch (NameDuplicatedException dex)
                {
                    return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
                }
            }
            else
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
Esempio n. 3
0
 public static void UpdateApplicationGroup(this ApplicationGroup appGroup, ApplicationGroupViewModel appGroupViewModel)
 {
     appGroup.ID          = appGroupViewModel.ID;
     appGroup.Name        = appGroupViewModel.Name;
     appGroup.Description = appGroupViewModel.Description;
     appGroup.IsDeleted   = appGroupViewModel.IsDeleted;
 }
        public async Task <HttpResponseMessage> Update(HttpRequestMessage request, ApplicationGroupViewModel appGroupViewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var appGroup = _appGroupService.GetDetail(appGroupViewModel.ID);

                    appGroup.UpdateApplicationGroup(appGroupViewModel);

                    _appGroupService.Update(appGroup);

                    _appGroupService.Save();

                    //save group
                    var listRoleGroup = new List <ApplicationRoleGroup>();

                    foreach (var role in appGroupViewModel.Roles)
                    {
                        listRoleGroup.Add(new ApplicationRoleGroup()
                        {
                            GroupId = appGroup.ID,
                            RoleId  = role.Id
                        });
                    }
                    _appRoleService.AddRolesToGroup(listRoleGroup, appGroup.ID);

                    _appRoleService.Save();

                    //add role to user
                    var listRole = _appRoleService.GetListRoleByGroupId(appGroup.ID);

                    var listUserInGroup = _appGroupService.GetListUserByGroupId(appGroup.ID);

                    foreach (var user in listUserInGroup)
                    {
                        foreach (var roleName in listRole.Select(x => x.Name).ToArray())
                        {
                            await _userManager.RemoveFromRoleAsync(user.Id, roleName);

                            await _userManager.AddToRoleAsync(user.Id, roleName);
                        }
                    }

                    return(request.CreateResponse(HttpStatusCode.OK, appGroupViewModel));
                }
                catch (NameDuplicatedException dex)
                {
                    return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
                }
                catch (Exception ex)
                {
                    return(request.CreateResponse(HttpStatusCode.OK, ex.Message));
                }
            }
            else
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
Esempio n. 5
0
        public HttpResponseMessage Add(HttpRequestMessage request, ApplicationGroupViewModel appGroupVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var appGroup    = Mapper.Map <ApplicationGroup>(appGroupVM);
                    var newAppGroup = _appGroupService.Add(appGroup);
                    _appGroupService.Save();

                    ////save group
                    //var listRoleGroup = new List<ApplicationRoleGroup>();
                    //foreach (var role in appGroupVM.Roles)
                    //{
                    //    listRoleGroup.Add(new ApplicationRoleGroup()
                    //    {
                    //        GroupId = appGroup.ID,
                    //        RoleId = role.Id
                    //    });
                    //}
                    //_appRoleService.AddRolesToGroup(listRoleGroup, appGroup.ID);
                    // _appRoleService.Save();

                    return(request.CreateResponse(HttpStatusCode.OK, appGroupVM));
                }
                catch (NameDuplicatedException dex)
                {
                    return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
                }
            }
            else
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
        public HttpResponseMessage Created(HttpRequestMessage request, ApplicationGroupViewModel applicationGroupVM)
        {
            return(CreateReponse(request, () =>
            {
                HttpResponseMessage response;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newApplicationGroup = new ApplicationGroup();
                    newApplicationGroup.UpdateApplicationGroup(applicationGroupVM);
                    var appGroup = _applicationGroupService.Add(newApplicationGroup);
                    _applicationGroupService.save();

                    var list = new List <ApplicationRoleGroup>();
                    foreach (var role in applicationGroupVM.Roles)
                    {
                        list.Add(new ApplicationRoleGroup()
                        {
                            RoleId = role.Id,
                            GroupId = appGroup.Id
                        });
                    }
                    _applicationRoleService.AddRoleGroup(list, appGroup.Id);
                    _applicationRoleService.Save();
                    response = request.CreateResponse(HttpStatusCode.OK, appGroup);
                }
                return response;
            }));
        }
Esempio n. 7
0
 public static void UpdateApplicationGroup(this ApplicationGroup appGroup, ApplicationGroupViewModel appGroupViewModel)
 {
     appGroup.Id          = appGroupViewModel.Id;
     appGroup.Name        = appGroupViewModel.Name;
     appGroup.Description = appGroupViewModel.Description;
     appGroup.Roles       = appGroupViewModel.Roles;
     appGroup.DangSuDung  = appGroupViewModel.DangSuDung;
 }
Esempio n. 8
0
 public static void UpdateApplicationGroup(this ApplicationGroup appGroup, ApplicationGroupViewModel appGroupViewModel)
 {
     appGroup.ID   = appGroupViewModel.ID;
     appGroup.Name = appGroupViewModel.Name;
     //foreach (var item in appGroupViewModel.Roles)
     //{
     //    appGroup.Description = item.Description;
     //}
 }
Esempio n. 9
0
        // [Authorize(Roles = "AddUserGroup")]
        public IActionResult Create([FromBody] ApplicationGroupViewModel appGroupViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            IActionResult result    = new ObjectResult(false);
            GenericResult addResult = null;

            try
            {
                var newAppGroup = new ApplicationGroup();
                newAppGroup.Name = appGroupViewModel.Name;
                var appGroup = _appGroupService.Add(newAppGroup);
                _appGroupService.Save();

                //save group
                var listRoleGroup = new List <ApplicationRoleGroup>();
                var roles         = appGroupViewModel.Roles.Where(x => x.Check).ToList();
                foreach (var role in roles)
                {
                    listRoleGroup.Add(new ApplicationRoleGroup()
                    {
                        GroupId = appGroup.Entity.ID,
                        RoleId  = role.Id
                    });
                }
                _appRoleService.AddRolesToGroup(listRoleGroup, appGroup.Entity.ID);
                _appRoleService.Save();


                addResult = new GenericResult()
                {
                    Succeeded = true,
                    Message   = "Thêm nhóm người dùng thành công"
                };
            }
            catch (Exception ex)
            {
                addResult = new GenericResult()
                {
                    Succeeded = false,
                    Message   = ex.Message
                };

                _loggingRepository.Add(new Error()
                {
                    Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now
                });
                _loggingRepository.Commit();
            }

            result = new ObjectResult(addResult);
            return(result);
        }
Esempio n. 10
0
        public async Task <HttpResponseMessage> Put(HttpRequestMessage request, ApplicationGroupViewModel applicationGroupViewModel)
        {
            HttpResponseMessage response = null;

            if (!ModelState.IsValid)
            {
                request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
            else
            {
                var applicationGroupDb = _applicationGroupService.GetDetail(applicationGroupViewModel.ID);
                try
                {
                    applicationGroupDb.UpdateApplicationGroup(applicationGroupViewModel);
                    _applicationGroupService.Update(applicationGroupDb);

                    var listRoleGroup = new List <ApplicationRoleGroup>();
                    foreach (var item in applicationGroupViewModel.Roles)
                    {
                        listRoleGroup.Add(new ApplicationRoleGroup
                        {
                            GroupId = applicationGroupDb.ID,
                            RoleId  = item.Id
                        });
                    }

                    _applicationRoleService.AddRolesToGroup(listRoleGroup, applicationGroupDb.ID);
                    _applicationRoleService.Save();

                    var listRole        = _applicationRoleService.GetListRoleByGroupId(applicationGroupDb.ID);
                    var listUserInGroup = _applicationGroupService.GetListUserByGroupId(applicationGroupDb.ID);
                    foreach (var user in listUserInGroup)
                    {
                        var listRoleName = listRole.Select(x => x.Name).ToArray();
                        foreach (var roleName in listRoleName)
                        {
                            await this._applicationUserManager.RemoveFromRoleAsync(user.Id, roleName);

                            await this._applicationUserManager.AddToRoleAsync(user.Id, roleName);
                        }
                    }

                    response = request.CreateResponse(HttpStatusCode.OK);
                }
                catch (NameDuplicatedException nameDuplicatedException)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, nameDuplicatedException.Message);
                }
            }

            return(response);
        }
        public async Task <HttpResponseMessage> Updated(HttpRequestMessage request, ApplicationGroupViewModel applicationGroupVM)
        {
            HttpResponseMessage response;

            if (!ModelState.IsValid)
            {
                response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
            }
            else
            {
                try
                {
                    var oldApplicationGroup = _applicationGroupService.GetDetail(applicationGroupVM.Id);
                    oldApplicationGroup.UpdateApplicationGroup(applicationGroupVM);
                    _applicationGroupService.Update(oldApplicationGroup);
                    _applicationGroupService.save();

                    var list = new List <ApplicationRoleGroup>();
                    foreach (var role in applicationGroupVM.Roles)
                    {
                        list.Add(new ApplicationRoleGroup()
                        {
                            RoleId  = role.Id,
                            GroupId = applicationGroupVM.Id
                        });
                    }
                    _applicationRoleService.AddRoleGroup(list, applicationGroupVM.Id);
                    _applicationRoleService.Save();

                    var roles = _applicationRoleService.GetRoleByGroupId(applicationGroupVM.Id);
                    var users = _applicationGroupService.GetListUserByGroupId(applicationGroupVM.Id);

                    foreach (var user in users)
                    {
                        foreach (var role in roles)
                        {
                            await _userManager.RemoveFromRoleAsync(user.Id, role.Name);

                            await _userManager.AddToRoleAsync(user.Id, role.Name);
                        }
                    }

                    response = request.CreateResponse(HttpStatusCode.OK, applicationGroupVM);
                }
                catch (Exception ex)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
                }
            }
            return(response);
        }
        public async Task <HttpResponseMessage> Update(HttpRequestMessage request, ApplicationGroupViewModel applicaionGroupViewModel)
        {
            bool statusUpdate            = false;
            HttpResponseMessage response = null;

            if (!ModelState.IsValid)
            {
                response     = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                statusUpdate = false;
            }
            else
            {
                ApplicationGroup appGroup = new ApplicationGroup();
                appGroup.UpdateApplicationGroup(applicaionGroupViewModel);
                _applicationGroupService.Update(appGroup);
                var listRoleGroup = new List <ApplicationRoleGroup>();
                foreach (var item in applicaionGroupViewModel.Roles)
                {
                    listRoleGroup.Add(new ApplicationRoleGroup()
                    {
                        GroupId = applicaionGroupViewModel.ID,
                        RoleId  = item.Id
                    });
                }
                var role = _appRoleService.AddRolesToGroup(listRoleGroup, appGroup.ID);
                _applicationGroupService.Save();
                statusUpdate = true;
                var listRole        = _appRoleService.GetListRoleByGroupId(applicaionGroupViewModel.ID);
                var listUserInGroup = _applicationGroupService.GetListUserByGroupId(applicaionGroupViewModel.ID);
                foreach (var user in listUserInGroup)
                {
                    var listRoleName = listRole.Select(x => x.Name).ToArray();
                    foreach (var roleName in listRoleName)
                    {
                        await _appUsermanager.RemoveFromRoleAsync(user.Id, roleName);

                        await _appUsermanager.AddToRoleAsync(user.Id, roleName);
                    }
                }
                response = request.CreateResponse(HttpStatusCode.Created, statusUpdate);
            }
            return(response);
        }
 public HttpResponseMessage Create(HttpRequestMessage request, ApplicationGroupViewModel applivationGroupViewModel)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             ApplicationGroup appGroup = new ApplicationGroup();
             appGroup.UpdateApplicationGroup(applivationGroupViewModel);
             var model = _applicationGroupService.Add(appGroup);
             _applicationGroupService.Save();
             var mapperModel = Mapper.Map <ApplicationGroup, ApplicationGroupViewModel>(model);
             var listRoleGroup = new List <ApplicationRoleGroup>();
             foreach (var item in applivationGroupViewModel.Roles)
             {
                 listRoleGroup.Add(new ApplicationRoleGroup()
                 {
                     GroupId = model.ID,
                     RoleId = item.Id
                 });
             }
             var role = _appRoleService.AddRolesToGroup(listRoleGroup, mapperModel.ID);
             _appRoleService.Save();
             var listRole = _appRoleService.GetListRoleByGroupId(applivationGroupViewModel.ID);
             var listUserInGroup = _applicationGroupService.GetListUserByGroupId(applivationGroupViewModel.ID);
             foreach (var user in listUserInGroup)
             {
                 var listRoleName = listRole.Select(x => x.Name).ToArray();
                 foreach (var roleName in listRoleName)
                 {
                     _appUsermanager.AddToRoleAsync(user.Id, roleName);
                 }
             }
             response = request.CreateResponse(HttpStatusCode.Created, mapperModel);
         }
         return response;
     }));
 }
Esempio n. 14
0
 public static void UpdateApplicationGroup(this ApplicationGroup appGroup, ApplicationGroupViewModel appGroupViewModel)
 {
     appGroup.ID   = appGroupViewModel.ID;
     appGroup.Name = appGroupViewModel.Name;
 }
Esempio n. 15
0
        public async Task <HttpResponseMessage> Update(HttpRequestMessage request, ApplicationGroupViewModel appGroupViewModel)
        {
            if (ModelState.IsValid)
            {
                var appGroup = _appGroupService.GetDetail(appGroupViewModel.ID);
                try
                {
                    appGroup.UpdateApplicationGroup(appGroupViewModel);
                    _appGroupService.Update(appGroup);
                    //_appGroupService.Save();

                    //save group
                    var listRoleGroup = new List <ApplicationRoleGroup>();
                    foreach (var role in appGroupViewModel.Roles)
                    {
                        listRoleGroup.Add(new ApplicationRoleGroup()
                        {
                            GroupId = appGroup.ID,
                            RoleId  = role.Id
                        });
                    }
                    _appRoleService.AddRolesToGroup(listRoleGroup, appGroup.ID);

                    try
                    {
                        _appRoleService.Save();
                    }
                    catch (DbEntityValidationException e)
                    {
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                              eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                  ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                        throw;
                    }

                    //add role to user
                    var listRole        = _appRoleService.GetListRoleByGroupId(appGroup.ID);
                    var listUserInGroup = _appGroupService.GetListUserByGroupId(appGroup.ID);
                    foreach (var user in listUserInGroup)
                    {
                        var listRoleName = listRole.Select(x => x.Name).ToArray();
                        foreach (var roleName in listRoleName)
                        {
                            await _userManager.RemoveFromRoleAsync(user.Id, roleName);

                            await _userManager.AddToRoleAsync(user.Id, roleName);
                        }
                    }
                    return(request.CreateResponse(HttpStatusCode.OK, appGroupViewModel));
                }
                catch (NameDuplicatedException dex)
                {
                    return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
                }
            }
            else
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
Esempio n. 16
0
        public HttpResponseMessage Create(HttpRequestMessage request, ApplicationGroupViewModel appGroupViewModel)
        {
            if (ModelState.IsValid)
            {
                var newAppGroup = new ApplicationGroup();
                newAppGroup.Name = appGroupViewModel.Name;
                try
                {
                    var appGroup = _appGroupService.Add(newAppGroup);

                    try
                    {
                        _appGroupService.Save();
                    }
                    catch (DbEntityValidationException e)
                    {
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                              eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                  ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                        throw;
                    }

                    //save group
                    var listRoleGroup = new List <ApplicationRoleGroup>();
                    foreach (var role in appGroupViewModel.Roles)
                    {
                        listRoleGroup.Add(new ApplicationRoleGroup()
                        {
                            GroupId = appGroup.ID,
                            RoleId  = role.Id
                        });
                    }
                    _appRoleService.AddRolesToGroup(listRoleGroup, appGroup.ID);

                    try
                    {
                        _appRoleService.Save();
                    }
                    catch (DbEntityValidationException e)
                    {
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                              eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                  ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                        throw;
                    }


                    return(request.CreateResponse(HttpStatusCode.OK, appGroupViewModel));
                }
                catch (NameDuplicatedException dex)
                {
                    return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
                }
            }
            else
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
Esempio n. 17
0
        public async Task <HttpResponseMessage> Update(HttpRequestMessage request, ApplicationGroupViewModel appGroupViewModel)
        {
            if (ModelState.IsValid)
            {
                var appGroup = _appGroupService.GetDetail(appGroupViewModel.ID);
                try
                {
                    appGroup.UpdateApplicationGroup(appGroupViewModel);
                    _appGroupService.Update(appGroup);
                    var listRoleGroup = new List <ApplicationRoleGroup>();
                    foreach (var role in appGroupViewModel.Roles)
                    {
                        if (role.ApplicationRoleGroup != null)
                        {
                            listRoleGroup.Add(new ApplicationRoleGroup
                            {
                                GroupId   = appGroup.ID,
                                RoleId    = role.ID,
                                CanCreate = role.ApplicationRoleGroup.CanCreate,
                                CanRead   = role.ApplicationRoleGroup.CanRead,
                                CanUpdate = role.ApplicationRoleGroup.CanUpdate,
                                CanDelete = role.ApplicationRoleGroup.CanDelete
                            });
                        }
                        else
                        {
                            listRoleGroup.Add(new ApplicationRoleGroup
                            {
                                GroupId   = appGroup.ID,
                                RoleId    = role.ID,
                                CanCreate = false,
                                CanRead   = false,
                                CanUpdate = false,
                                CanDelete = false
                            });
                        }
                    }
                    var listOldRole     = _appRoleService.GetListRoleByGroupId(appGroup.ID);
                    var listUserInGroup = _appGroupService.GetListUserByGroupId(appGroup.ID);
                    foreach (var user in listUserInGroup)
                    {
                        foreach (var roleOld in listOldRole)
                        {
                            await _userManager.RemoveFromRoleAsync(user.Id, roleOld.Name);
                        }
                    }
                    _appRoleService.AddRolesToGroup(listRoleGroup, appGroup.ID);
                    _appRoleService.Save();

                    var listRole     = _appRoleService.GetListRoleByGroupId(appGroup.ID);
                    var listRoleName = listRole.Select(x => x.Name).ToArray();
                    foreach (var user in listUserInGroup)
                    {
                        foreach (var roleName in listRoleName)
                        {
                            //await _userManager.RemoveFromRoleAsync(user.Id, roleName);
                            await _userManager.AddToRoleAsync(user.Id, roleName);
                        }
                    }
                    return(request.CreateResponse(HttpStatusCode.OK, appGroupViewModel));
                }
                catch (NameDuplicatedException dx)
                {
                    return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dx.Message));
                }
            }
            else
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
Esempio n. 18
0
 public static void UpdateApplicationGroup(this ApplicationGroup appGroup, ApplicationGroupViewModel appGroupVM)
 {
     appGroup.ID          = appGroupVM.ID;
     appGroup.Name        = appGroupVM.Name;
     appGroup.Description = appGroupVM.Description;
 }
Esempio n. 19
0
        //     [Authorize(Roles = "EditUserGroup")]
        public async Task <IActionResult> PutAsync(int id, [FromBody] ApplicationGroupViewModel appGroupViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            IActionResult result        = new ObjectResult(false);
            GenericResult genericResult = null;

            var listRoleRemoveList = _appRoleService.GetListRoleByGroupId(appGroupViewModel.ID).ToList();
            //    List<ApplicationRoleViewModel> listRoleRemoveList2 = Mapper.Map<IEnumerable<IdentityRole>, IEnumerable<ApplicationRoleViewModel>>(listRoleRemoveList).ToList();

            var appGroup = _appGroupService.GetDetail(appGroupViewModel.ID);

            try
            {
                appGroup.UpdateApplicationGroup(appGroupViewModel);
                //    appGroup = PropertyCopy.Copy<ApplicationGroup, ApplicationGroupViewModel>(appGroupViewModel);
                _appGroupService.Update(appGroup);
                _appGroupService.Save();

                //save group
                var listRoleGroup = new List <ApplicationRoleGroup>();

                var roleByUser = appGroupViewModel.Roles.Where(x => x.Check).ToList();
                foreach (var role in roleByUser)
                {
                    listRoleGroup.Add(new ApplicationRoleGroup()
                    {
                        GroupId = appGroup.ID,
                        RoleId  = role.Id
                    });
                }

                //add role to user
                var listUserInGroup = _appGroupService.GetListUserByGroupId(appGroup.ID).ToList();

                //Xóa tất cả role thuộc group
                var listRoleRemoveName = listRoleRemoveList.Select(x => x.Name).ToArray();
                foreach (var user2 in listUserInGroup)
                {
                    foreach (var roleName in listRoleRemoveName)
                    {
                        await _userManager.RemoveFromRoleAsync(user2, roleName);
                    }
                }

                _appRoleService.AddRolesToGroup(listRoleGroup, appGroup.ID);

                _appRoleService.Save();

                var listRole = _appRoleService.GetListRoleByGroupId(appGroup.ID).ToList();

                var listRoleName = listRole.Select(x => x.Name).ToArray();
                foreach (var user in listUserInGroup)
                {
                    foreach (var roleName in listRoleName)
                    {
                        await _userManager.AddToRoleAsync(user, roleName);
                    }
                }


                genericResult = new GenericResult()
                {
                    Succeeded = true,
                    Message   = "Cập nhật nhóm người dùng thành công"
                };
            }
            catch (Exception ex)
            {
                genericResult = new GenericResult()
                {
                    Succeeded = false,
                    Message   = "Cập nhật nhóm người dùng thất bại" + ex.Message
                };
                _loggingRepository.Add(new Error()
                {
                    Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now
                });
                _loggingRepository.Commit();
            }


            result = new ObjectResult(genericResult);
            return(result);
        }