public ActionResult Attend(Peanut peanut, User currentUser, PeanutParticipationCreateCommand peanutParticipationCreateCommand) { Require.NotNull(peanut, "peanut"); Require.NotNull(currentUser, "currentUser"); Require.IsFalse(() => peanut.IsFixed, "peanut"); UserGroupMembership userGroupMembership = UserGroupService.FindMembershipsByUserAndGroup(currentUser, peanut.UserGroup); Require.NotNull(userGroupMembership, "userGroupMembership"); if (!UserGroupService.IsUserSolvent(userGroupMembership)) { return(View("CanNotParticipate", new PeanutParticipationRejectedViewModel(peanut))); } if (!ModelState.IsValid) { IList <PeanutParticipationType> peanutParticipationTypes = PeanutParticipationTypeService.Find(peanut.UserGroup); return(View("CreateParticipation", new PeanutParticipationCreateFormViewModel(peanut, peanutParticipationTypes.ToList(), peanutParticipationCreateCommand))); } PeanutService.AddOrUpdateParticipations(peanut, new Dictionary <UserGroupMembership, PeanutParticipationDto> { { userGroupMembership, new PeanutParticipationDto(peanutParticipationCreateCommand.PeanutParticipationType, PeanutParticipationState.Confirmed) } }, currentUser); return(RedirectToAction("Show", new { peanut = peanut.BusinessId })); }
public ActionResult UpdateParticipation(Peanut peanut, PeanutParticipation peanutParticipation, PeanutParticipationUpdateCommand peanutParticipationUpdateCommand, User currentUser) { Require.NotNull(peanut, "peanut"); Require.NotNull(peanutParticipation, "peanutParticipation"); Require.NotNull(peanutParticipationUpdateCommand, "peanutParticipationUpdateCommand"); Require.IsTrue(() => peanut.Equals(peanutParticipation.Peanut), "peanutParticipation"); if (!ModelState.IsValid) { return(RedirectToAction("Show", new { peanut = peanut.BusinessId })); } Dictionary <UserGroupMembership, PeanutParticipationDto> participationUpdates = new Dictionary <UserGroupMembership, PeanutParticipationDto> { { peanutParticipation.UserGroupMembership, new PeanutParticipationDto(peanutParticipationUpdateCommand.PeanutParticipationType, peanutParticipation.ParticipationState) } }; PeanutService.AddOrUpdateParticipations(peanut, participationUpdates, currentUser); return(RedirectToAction("Show", new { peanut = peanut.BusinessId })); }