public GroupRoleListViewModel UpdateGroupRole(GroupRoleListViewModel model) { var entityCollection = this._groupRolesRepository.Get(null).Where(x => x.GroupId == model.GroupId); if (entityCollection.Count() > 0) { foreach (var item in entityCollection) { this._groupRolesRepository.Delete(item); } this._unitOfWork.Commit(); } if (model.List?.Count > 0) { foreach (var item in model.List) { GroupRole newEntity = new GroupRole { GroupId = model.GroupId, RoleId = item.Value }; this._groupRolesRepository.Add(newEntity); } this._unitOfWork.Commit(); } return(model); }
public GroupRoleListViewModel GetGroupRole(long groupId) { var lang = this._languageService.CurrentLanguage; var entityCollection = this._groupRolesRepository.Get(null).Where(x => x.GroupId == groupId).ToList(); GroupRoleListViewModel result = new GroupRoleListViewModel { GroupId = groupId, List = new List <NmaeValueViewModel>() }; foreach (var item in entityCollection) { result.List.Add(new NmaeValueViewModel { Value = item.RoleId.Value, Name = item.Role.ChildTranslatedRoles.FirstOrDefault(x => x.Language == lang).Name }); } return(result); }