RetreatListViewModel GetModel() { var retreats = GetRetreats().ToArray(); if (retreats.Count() != 0) { retreats.First().Active = true; } return(new RetreatListViewModel { CreateLink = _urlMapper.MapAction <RetreatController>(c => c.Create()), Retreats = retreats }); }
public ActionResult AddToRetreat(AddParticipantToRetreatViewModel postBack) { if (postBack.Cancel != null) { return(this.RedirectToAction <RetreatController>(c => c.Index(postBack.RetreatId))); } if (postBack.Search != null) { var queryResults = _participantRepository.WithNameLike(postBack.FirstName, postBack.LastName); var searchResults = queryResults.Select(x => new ParticipantSearchResultViewModel { Name = string.Format("{0} {1}", x.FirstName, x.LastName), DateReceived = x.DateReceived, SelectLink = _urlMapper.MapAction <ParticipantController>(c => c.AssignToRetreatChooseBedCode(postBack.RetreatId, x.Id)), }); TempData["searchResults"] = new AddParticipantToRetreatSearchResultsViewModel { SearchResults = searchResults.ToList(), }; return(this.RedirectToAction(c => c.AddToRetreat(postBack.RetreatId))); } var retreat = _retreatRepository.Get(postBack.RetreatDate); // TODO: what if we already have a participant with this name in the db? var newParticipant = new Participant { FirstName = postBack.FirstName, LastName = postBack.LastName, DateReceived = postBack.DateReceived, Notes = postBack.Notes, PhysicalStatus = postBack.PhysicalStatus }; var bed = _bedRepository.GetBy(postBack.BedCode); retreat.AddParticipant(newParticipant, bed); _retreatRepository.Save(retreat); return(this.RedirectToAction <RetreatController>(c => c.Index(postBack.RetreatId))); }