public async Task <IActionResult> EditSprintAsync(EditSprintViewModel editSprintViewModel) { if (ModelState.IsValid) { var sprints = await _manageSprintsService.GetAllSprintsAsync(editSprintViewModel.TeamId, new DisplayOptions()); var sprint = new Sprint { Id = editSprintViewModel.SprintId, TeamId = editSprintViewModel.TeamId, Name = editSprintViewModel.SprintName, DaysInSprint = editSprintViewModel.SprintDaysInSprint, StoryPointInHours = editSprintViewModel.SprintStorePointInHours }; var result = await EditSprintAsync(sprint); if (result) { return(RedirectToAction("AllSprints", new { teamId = editSprintViewModel.TeamId })); } else { return(RedirectToAction("NotOwnerError", new { teamId = editSprintViewModel.TeamId })); } } return(View(editSprintViewModel)); }
public IActionResult Edit(EditSprintViewModel vm) { if (!ModelState.IsValid) { return(View(vm)); } var presenter = _presenterFactory.Edit(MessageHandler, ErrorHandler); var request = vm.ToRequest(CurrentUserId); try { var uc = _useCaseFactory.Edit; var response = uc.Execute(request); return(RedirectToAction(nameof(Index), new { id = presenter.Present(response) })); } catch (InvalidRequestException ire) { presenter.PresentErrors(ire.Message, ire.Errors); return(View(presenter.Present(vm))); } catch (Exception e) { presenter.PresentMessage(MessageType.Error, e.Message); return(View(presenter.Present(vm))); } }
public EditSprintViewModel Present(EditSprintViewModel vm) { var id = Identity.FromString(vm.Id); var sprint = RepositoryProvider.Sprint.Read(id); var backlog = RepositoryProvider.Sprint.ReadSprintBacklog(id); vm.Stories = Stories(sprint.ProjectId, backlog.Stories); vm.Documents = Documents(sprint.ProjectId); return(vm); }
public async Task <IActionResult> EditSprintAsync(int sprintId, string errorMessage) { var sprint = await _manageSprintsService.GetSprintAsync(sprintId, false); var team = await _manageSprintsService.GetTeam(sprint.TeamId); var editSprintViewModel = EditSprintViewModel.Create(sprint, errorMessage, team); return(View(editSprintViewModel)); }
public static EditSprintRequest ToRequest(this EditSprintViewModel vm, string userId) { return(new EditSprintRequest(userId) { Id = Identity.FromString(vm.Id), Goal = vm.Goal, Name = vm.Name, TimeSpan = new Tuple <DateTime, DateTime>( DateTime.ParseExact(vm.StartDate, "yyyy-MM-dd", CultureInfo.InvariantCulture), DateTime.ParseExact(vm.EndDate, "yyyy-MM-dd", CultureInfo.InvariantCulture)), Stories = vm.SelectedStories.Select(Identity.FromString), Documents = vm.SelectedDocumentIds.Select(Identity.FromString), }); }
// GET: Sprint/Edit/5 public ActionResult Edit(int id) { var model = new EditSprintViewModel(); var sprintEntity = context.Sprints.Where(s => s.SprintID == id).FirstOrDefault(); model = mapper.Map <Sprint, EditSprintViewModel>(sprintEntity); var usersEntities = context.Users; var usersViewModel = mapper.Map <IEnumerable <User>, IEnumerable <UserViewModel> >(usersEntities); model.Users = usersViewModel; model.SelectedUsers = sprintEntity.Users.Select(u => u.UserID); return(View(model)); }
public async Task <IActionResult> EditSprintAsync(int teamId, int sprintId, string errorMessage) { var team = await _manageSprintsService.GetTeam(teamId); var sprint = await _manageSprintsService.GetSprintAsync(sprintId, false); EditSprintViewModel model = new EditSprintViewModel { TeamId = teamId, TeamName = team.TeamName, SprintId = sprint.Id, SprintName = sprint.Name, SprintDaysInSprint = sprint.DaysInSprint, SprintStorePointInHours = sprint.StoryPointInHours, ErrorMessage = errorMessage }; return(View(model)); }
public ActionResult Edit(EditSprintViewModel model) { try { // TODO: Add update logic here if (ModelState.IsValid) { var entitySprint = mapper.Map <EditSprintViewModel, Sprint>(model); entitySprint.Users.Where(m => !model.SelectedUsers.Contains(m.UserID)).ToList().ForEach(user => entitySprint.Users.Remove(user)); var selectedUsers = entitySprint.Users.Select(m => m.UserID); context.Users.Where(m => !model.SelectedUsers.Except(selectedUsers).Contains(m.UserID)).ToList() .ForEach(user => entitySprint.Users.Add(user)); entitySprint.StartDate = model.StartDate; entitySprint.EndDate = model.EndDate; entitySprint.ScrumGoal = model.ScrumGoal; entitySprint.ProjectID = model.ProjectID; context.SaveChanges(); return(RedirectToAction("Index")); } var entitySprintUsers = context.Users; var sprintViewModelUsers = mapper.Map <IEnumerable <User>, IEnumerable <UserViewModel> >(entitySprintUsers); model.Users = sprintViewModelUsers; return(View(model)); } catch { return(View()); } }
public async Task <IActionResult> EditSprintAsync(EditSprintViewModel editSprintViewModel) { if (ModelState.IsValid) { var sprints = await _manageSprintsService.GetAllSprintsAsync(editSprintViewModel.TeamId, new DisplayOptions()); var currentSprint = sprints.FirstOrDefault(i => i.Id == editSprintViewModel.SprintId); if (currentSprint.Name == editSprintViewModel.SprintName && currentSprint.DaysInSprint == editSprintViewModel.SprintDaysInSprint && currentSprint.StoryPointInHours == editSprintViewModel.SprintStorePointInHours && currentSprint.Status == editSprintViewModel.Status) { return(RedirectToAction("EditSprint", new { teamId = editSprintViewModel.TeamId, sprintId = editSprintViewModel.SprintId, errorMessage = _localizer["HasntAnyChange"] })); } var activeSprint = sprints.FirstOrDefault(i => i.Status == PossibleStatuses.ActiveStatus); var createdSprint = sprints.FirstOrDefault(i => i.Status == PossibleStatuses.CreatedStatus); if ((currentSprint.Status == PossibleStatuses.CreatedStatus && editSprintViewModel.Status == PossibleStatuses.ActiveStatus) || (currentSprint.Status == PossibleStatuses.ActiveStatus && editSprintViewModel.Status == PossibleStatuses.CompletedStatus) || currentSprint.Status == editSprintViewModel.Status) { if (activeSprint != null && editSprintViewModel.Status == PossibleStatuses.ActiveStatus && activeSprint.Id != currentSprint.Id) { return(RedirectToAction("EditSprint", new { teamId = editSprintViewModel.TeamId, sprintId = editSprintViewModel.SprintId, errorMessage = _localizer["ActiveFieldError"] })); } var newSprint = new Sprint { Id = editSprintViewModel.SprintId, TeamId = editSprintViewModel.TeamId, Name = editSprintViewModel.SprintName, DaysInSprint = editSprintViewModel.SprintDaysInSprint, StoryPointInHours = editSprintViewModel.SprintStorePointInHours, Status = editSprintViewModel.Status }; var result = await EditSprintAsync(newSprint); if (result) { return(RedirectToAction("AllSprints", new { teamId = editSprintViewModel.TeamId })); } else { return(RedirectToAction("NotOwnerError", new { teamId = editSprintViewModel.TeamId })); } } else { return(RedirectToAction("EditSprint", new { teamId = editSprintViewModel.TeamId, sprintId = editSprintViewModel.SprintId, errorMessage = _localizer["CantChangeStatus"] })); } } else { return(View(editSprintViewModel)); } }