public ActionResult ViewAllRole() { ActionResult response = null; if (Session["RoleID"] != null) { if ((int)Session["RoleID"] == 1) { List <RolePO> roleList = new List <RolePO>(); List <RoleDO> roleObjectList = RoleDataAccessLayer.ReadRole(); foreach (RoleDO objectList in roleObjectList) { RolePO mappedRole = Mapper.MapRoleDOtoPO(objectList); roleList.Add(mappedRole); } response = View(roleList); } else { response = RedirectToAction("Index", "Home"); } } else { response = RedirectToAction("Index", "Home"); } return(response); }
public ActionResult AddRole(RolePO form) { ActionResult response = null; if (ModelState.IsValid) { try { //sets user inputted role name to a variable and checks to see if the name exists in the database string name = form.Name; bool roleExists = _dataAccess.RoleExists(name); if (!roleExists) { RoleDO dataObject = RoleMapper.RolePOToDO(form); _dataAccess.AddRole(dataObject); response = RedirectToAction("Index", "Role"); } else { ModelState.AddModelError("Name", "Role name already in use, please choose another."); response = View(); } } catch (Exception ex) { Logger.Log("Fatal", ex.TargetSite.ToString(), ex.Message, ex.StackTrace); } } else { response = View(form); } return(response); }
public RolePO MapDOtoPO(RoleDO roleDO) { RolePO rolePO = new RolePO(); rolePO.RoleID = roleDO.RoleID; rolePO.RoleName = roleDO.RoleName; return(rolePO); }
public static RolePO RoleDOToPO(RoleDO from) { RolePO to = new RolePO(); to.RoleId = from.RoleId; to.Name = from.Name; return(to); }
public static RolePO MapRoleDOtoPO(RoleDO frmRoleDO) { RolePO toRolePO = new RolePO(); toRolePO.RoleID = frmRoleDO.RoleID; toRolePO.Name = frmRoleDO.Name; toRolePO.Description = frmRoleDO.Description; return(toRolePO); }
public static List <RolePO> RoleDOListToPOList(List <RoleDO> from) { List <RolePO> to = new List <RolePO>(); foreach (RoleDO role in from) { RolePO temp = new RolePO(); temp.RoleID = role.RoleID; temp.RoleName = role.Name; to.Add(temp); } return(to); }
public ActionResult UpdateRole(int Id) { ActionResult response = null; try { //views the update page for a specific role, using the role ID RoleDO dataObject = _dataAccess.ViewRoleById(Id); RolePO displayObject = RoleMapper.RoleDOToPO(dataObject); response = View(displayObject); } catch (Exception ex) { Logger.Log("Fatal", ex.TargetSite.ToString(), ex.Message, ex.StackTrace); } return(response); }
public ActionResult UpdateRole(RolePO form) { ActionResult response = null; if (ModelState.IsValid) { try { //sets the user inputted role name to a variable to be used in the code string name = form.Name; //sends the user inputted variable to RoleExists methods to see if it already exists bool roleExists = _dataAccess.RoleExists(name); if (!roleExists) { //if the role name does not exist, continue with the update procedure RoleDO dataObject = RoleMapper.RolePOToDO(form); _dataAccess.UpdateRole(dataObject); response = RedirectToAction("Index", "Role"); } else { //if the role name does exist, show error message ModelState.AddModelError("Name", "Role name already in use, please choose another."); response = View(); } } catch (Exception ex) { Logger.Log("Fatal", ex.TargetSite.ToString(), ex.Message, ex.StackTrace); } } else { response = View(form); } return(response); }