public ActionResult Edit(int?id) { ProjectsEditVM model; if (id == null) { model = new ProjectsEditVM(); } else { OvmDbContext context = new OvmDbContext(); Project project = context.Projects.Find(id.Value); model = new ProjectsEditVM { Id = id.Value, Name = project.Name, Description = project.Description }; context.Dispose(); } return(View(model)); }
public ActionResult Edit(ProjectsEditVM model) { if (!ModelState.IsValid) { return(View(model)); } OvmDbContext context = new OvmDbContext(); Project project = new Project { Id = model.Id, Name = model.Name, Description = model.Description }; context.Projects.AddOrUpdate(u => u.Id, project); context.SaveChanges(); context.Dispose(); return(RedirectToAction("Index")); }
public IActionResult Post([FromForm] ProjectsEditVM model) { if (model == null) { return(NotFound()); } model.AssignedUsers = new int[0]; if (!string.IsNullOrEmpty(model.AssignedUsersAsString)) { model.AssignedUsers = model.AssignedUsersAsString.Split(",").Select(x => int.Parse(x)).ToArray(); } var projectEditDto = new ProjectEditDto(); _mapper.Map(model, projectEditDto); _projectsService.SaveProject(projectEditDto, model.AssignedUsers); var projectEditVM = _projectsService.GetDtoById(projectEditDto.ID); return(Ok(projectEditVM)); }