public ActionResult Create(ProjectRoleViewModel model) { try { // TODO: Add insert logic here if (!ModelState.IsValid) { return(View(model)); } var ProjectRole = _mapper.Map <ProjectRole>(model); var isSuccess = _repo.Create(ProjectRole); if (!isSuccess) { ModelState.AddModelError("", "Something Went Wrong!"); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError("", "Something Went Wrong!"); return(View(model)); } }
public ActionResult Delete(int id, ProjectRoleViewModel model) { try { // TODO: Add delete logic here var ProjectRole = _repo.FindById(id); if (ProjectRole == null) { return(NotFound()); } var isSuccess = _repo.Delete(ProjectRole); if (!isSuccess) { return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { return(View(model)); } }
public override void ExecuteResult(ControllerContext context) { base.ExecuteResult(context); var viewModel = new ProjectRoleViewModel(); //ProjectRoleCreatingViewModel GetViewResult(viewModel).ExecuteResult(context); }
private ProjectRole PrepareRole(ProjectRoleViewModel role, bool isNew) { var newrole = new ProjectRole { Id = isNew ? 0 : role.RoleId.Value, Name = role.Name, Description = role.ShortDescription, CreatedDate = DateTime.Now, CreatedBy = isNew ? GetUserName() : role.CreatedBy }; return(newrole); }
public async Task <IActionResult> ViewProjectRoles(int?id) { var model = new ProjectRoleViewModel { Roles = await _projectRepo.GetProjectRoleListAsync() }; if (id != null) { model.SelectedRoles = await _projectRepo.GetSelectedProjectRolesAsync(id); model.RoleGroupID = id; } return(View(model)); }
public ActionResult Create(ProjectRoleViewModel viewModel) { var role = PrepareRole(viewModel, true); if (_projectRoleRepository.SaveProjectRole(role)) { SetSucceedMessage("Project role created successfully !"); AppCach.AllProjectRoles.Add(role); //save to global cach } else { SetErrorMessage("Cannot create role"); } return(RedirectToAction("Index", "ProjectRole")); }
public ActionResult Delete(ProjectRoleViewModel model) { var isSucceed = _projectRoleRepository.DeleteProjectRole(model.RoleId.Value); if (isSucceed) { SetSucceedMessage("Project role has been removed successfully !"); //update cach : AppCach.AllRoles.Except(AppCach.AllRoles.Where(r => r.Id == roleId)); AppCach.AllProjectRoles = new ConcurrentBag <ProjectRole>(_projectRoleRepository.GetProjectRoles()); } else { SetErrorMessage("Cannot delete role"); return(View()); } return(RedirectToAction("Index", "ProjectRole")); }