public ActionResult UpdateResources(IterationResourcesModel model) { var pc = ProjectContext; Project project; if (!Context.Projects.TryGetById(ProjectId, out project)) throw new ApplicationException("Project with id = " + ProjectId + " does not exist"); Iteration iteration; if (!pc.Iterations.TryGetById(model.IterationId, out iteration)) throw new ApplicationException("Iteration with id = " + model.IterationId + " does not exist"); if (ModelState.IsValid) { iteration.StoryPointValueInHours = model.StoryPointValue; foreach (var assignment in project.AssignmentsNonDeleted) { var resource = model.Resources.SingleOrDefault(x => x.UserId == assignment.UserId); if (resource != null) { if (!resource.Id.IsValidId()) //We create a new resource { assignment.IterationResources.Add(new IterationResource { Capacity = resource.Capacity, Velocity = resource.Velocity, IterationId = model.IterationId, ProjectAssignmentId = assignment.Id }); } else { var toBeUpdated = assignment.IterationResources.SingleOrDefault(x => x.Id == resource.Id); toBeUpdated.Capacity = resource.Capacity; toBeUpdated.Velocity = resource.Velocity; toBeUpdated.IterationId = model.IterationId; toBeUpdated.ProjectAssignmentId = assignment.Id; } } } Context.SaveChanges(); return this.RedirectToAction(x => x.Resources(iteration.ReleaseId, iteration.Id)); } ViewBag.ReleaseId = iteration.ReleaseId; ViewBag.IterationId = iteration.Id; return View("Resources", model); }
public ActionResult Resources(long? releaseId, long? iterationId) { var model = new IterationResourcesModel(); if (!releaseId.HasValue) { long rId; if (TryGetMostRecentSelectableReleaseId(out rId, true)) releaseId = rId; } if (releaseId.HasValue) ViewBag.ReleaseId = releaseId.Value; if (releaseId.HasValue && !iterationId.HasValue) { long iId; if (TryGetMostRecentSelectableIterationId(releaseId.Value, out iId)) iterationId = iId; } if (iterationId.HasValue) { ViewBag.IterationId = iterationId.Value; var pc = ProjectContext; Iteration iteration; if (!pc.Iterations.TryGetById(iterationId.Value, out iteration)) throw new ApplicationException("Itertion with id = " + iterationId + " does not exist"); model.StoryPointValue = iteration.StoryPointValueInHours; model.IterationId = iterationId.Value; var resources = pc.GetIterationResources(iteration.Id); //TODO: Implement a service for the pictures and retrieve the proper size based on the requirements. const long pictureId = Constants.InvalidId; model.Resources = resources.Select(x => new IterationResourceModel { Id = x.Item2.Id, UserId = x.Item1.Id, PictureId = pictureId, UserName = x.Item1.Name, Capacity = x.Item2.Capacity, Velocity = x.Item2.Velocity }).ToList(); } return View(model); }