public ActionResult Create(RoleCM m) { BindData(); var entity = iRoleService.Get(m.ID) ?? new Role(); try { if (ModelState.IsValid) { entity.Name = m.Name; entity.MenuActions = m.ActionIDList.Count > 0 ? string.Join(",", m.ActionIDList) : ""; entity.Menus = m.MenuIDList.Count > 0 ? string.Join(",", m.MenuIDList) : ""; iRoleService.Save(entity); iRoleService.Commit(); this.ShowTip(); } else { AddError(); } } catch (Exception ex) { this.AddError(ErrorCode.Exception, ex.Message); } return(RedirectToAction("Create", new { ID = entity.ID })); }
public ActionResult <Role> PostRole(RoleCM model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Role role = new Role(); role = _mapper.Map <Role>(model); _roleService.Create(role); _roleService.Save(); return(StatusCode(201, "Role Type Created!")); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <Role> PostRole(RoleCM model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var nameExist = _roleService.GetByName(model.Name); if (nameExist != null) { return(BadRequest("Role Name is existed!")); } Role role = new Role(); role = _mapper.Map <Role>(model); _roleService.Create(role); return(StatusCode(201, role.ID)); } catch (Exception e) { return(BadRequest(e.Message)); } }