public static void Init() { Mapper.AddMap <AdminPermission, AdminPermissionDto>(src => { var adminUserViewModel = new AdminPermissionDto(); adminUserViewModel.InjectFrom(src); if (src.ParentId > 0) { adminUserViewModel.IsParentSelected = true; } return(adminUserViewModel); }); Mapper.AddMap <AdminPermissionDto, AdminPermission>((from, to) => { var existing = to as AdminPermission ?? new AdminPermission(); existing.InjectFrom(new LoopInjection(new[] { "ParentId", "Left", "Right" }), from); if (from.IsParentSelected) { existing.ParentId = from.ParentId; } return(existing); }); }
public Result Edit(AdminPermissionDto dto) { var validator = new AdminPermissionValidator(_adminPermissionRepository); var result = validator.ValidateResult(dto); if (!result.Success) { return(result); } var entity = _adminPermissionRepository.Find(dto.Id); if (entity == null) { return(new Result().SetBlankRedirect()); } Mapper.Map <AdminPermission>(dto, entity); _adminPermissionRepository.Update(entity); _unitOfWork.Commit(); _adminPermissionRepository.MoveToParentNode("AdminPermissions", dto.Id, dto.IsParentSelected ? dto.ParentId : null); AdminRoleCacheManager.ClearCache(); return(result.SetSuccess(Messages.RecordSaved)); }
public JsonResult Create(AdminPermissionDto dto) { var result = _adminPermissionService.Create(dto); if (result.Success) { result.Redirect = Url.Action("Edit", new { id = result.Id }); } return(ToJsonResult(result)); }
public JsonResult Edit(AdminPermissionDto model) { var result = _adminPermissionService.Edit(model); if (result.IsRedirect) { result.Redirect = Url.Action("Index"); } if (!result.Success) { return(ToJsonResult(result)); } Flash.Success(result.Message); result.Redirect = Url.Action("Edit", "AdminPermissions", new { model.Id }); return(ToJsonResult(result)); }
public Result Create(AdminPermissionDto dto) { var validator = new AdminPermissionValidator(_adminPermissionRepository); var result = validator.ValidateResult(dto); if (!result.Success) { return(result); } var entity = Mapper.Map <AdminPermission>(dto); _adminPermissionRepository.Insert(entity); _unitOfWork.Commit(); AdminRoleCacheManager.ClearCache(); result.Id = entity.Id; return(result.SetSuccess(Messages.RecordSaved)); }