public ActionResult RoleActionMapping(Guid[] ActionId, Guid RoleId, Guid[] UnMap) { RoleActionMappings userRoleMappings = new RoleActionMappings(); try { var roleActionMap = roleActionMappingService.GetAll().Where(x => x.RoleMasterId == RoleId && x.IsActive == true).ToList(); if (ActionId != null) { foreach (var item in ActionId) { if (roleActionMap.Select(x => x.ActionMasterId).Contains(item) == false) { RoleActionMapping roleActionMapping = new RoleActionMapping(); roleActionMapping.RoleMasterId = RoleId; roleActionMapping.ActionMasterId = item; roleActionMapping.CreatedBy = User.Identity.Name; roleActionMapping.CreatedDate = DateTime.Now; roleActionMappingService.Add(roleActionMapping); roleActionMappingService.Save(); } } } if (UnMap != null) { foreach (var item in UnMap) { if (roleActionMap.Select(x => x.ActionMasterId).Contains(item)) { RoleActionMapping roleActionMapping = roleActionMap.Where(x => x.ActionMasterId == item && x.RoleMasterId == RoleId).FirstOrDefault(); roleActionMapping.IsActive = false; roleActionMapping.DeletedBy = User.Identity.Name; roleActionMapping.DeletedDate = DateTime.Now; roleActionMappingService.Delete(roleActionMapping); roleActionMappingService.Save(); } } } return(RedirectToAction("Index")); } catch (Exception ex) { RoleMaster roleMaster = roleMasterService.FindBy(x => x.UniqueId == RoleId).FirstOrDefault(); userRoleMappings.RoleId = roleMaster.UniqueId; userRoleMappings.RoleName = roleMaster.Name; userRoleMappings.Action = actionMasterService.GetAll().ToList(); userRoleMappings.RoleActionMapping = roleActionMappingService.GetAll().Where(x => x.RoleMasterId == RoleId).ToList(); } return(View(userRoleMappings)); }
public void Edit(RoleActionMapping entity) { entity.IsActive = false; roleActionMappingRepository.Edit(entity); RoleActionMapping am = new RoleActionMapping(); am.UniqueId = Guid.NewGuid(); am.Id = entity.UniqueId; am.ActionMasterId = entity.ActionMasterId; am.RoleMasterId = entity.RoleMasterId; am.CreatedBy = entity.CreatedBy; am.CreatedDate = DateTime.Now; this.roleActionMappingRepository.Add(am); }
public async Task Change(RoleActionMapping[] roleActionMappingsAdd, string roleId, string[] actionIdsRemove) { await WithConnection(async (connection, transaction) => { int rowDelete = 0; if (actionIdsRemove?.Length > 0) { DynamicParameters parameters = new DynamicParameters(); parameters.Add("@RoleId", roleId, DbType.String); parameters.Add("@ActionIds", string.Join(",", actionIdsRemove), DbType.String); rowDelete = await connection.ExecuteAsync(ProcName.Role_Action_Mapping_RemoveByRoleIdAndActionIds, parameters, transaction, commandType: CommandType.StoredProcedure); } if (roleActionMappingsAdd != null && roleActionMappingsAdd.Length > 0) { DataTable dataTable = RoleActionMapping.CreateDataTable(); foreach (var roleActionMapping in roleActionMappingsAdd) { roleActionMapping.AddToDataTable(dataTable); } await BulkCopy(dataTable, connection, transaction); } return(rowDelete); }); }
public void Delete(RoleActionMapping entity) { entity.IsActive = false; roleActionMappingRepository.Edit(entity); }
public void Add(RoleActionMapping entity) { roleActionMappingRepository.Add(entity); }