Example #1
0
        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 }));
        }
Example #2
0
        public ActionResult Show(Peanut peanut, User currentUser)
        {
            Require.NotNull(peanut, "peanut");
            Require.NotNull(currentUser, "currentUser");

            IList <PeanutParticipationType> peanutParticipationTypes = PeanutParticipationTypeService.Find(peanut.UserGroup);
            List <UserGroupMembership>      userGroupMemberships     =
                UserGroupService.FindMembershipsByGroups(PageRequest.All,
                                                         new List <UserGroup> {
                peanut.UserGroup
            },
                                                         UserGroupMembership.ActiveTypes).ToList();
            /*Es können alle Nutzer eingeladen werden, die in der Gruppe aktives Mitglied sind und noch nicht am Peanut teilnehmen oder ihre Teilnahme abgesagt haben*/
            List <UserGroupMembership> invitableUsers =
                userGroupMemberships.Except(
                    peanut.Participations.Where(part => part.ParticipationState != PeanutParticipationState.Refused)
                    .Select(part => part.UserGroupMembership)).ToList();

            return(View("Show",
                        new PeanutShowViewModel(peanut,
                                                peanut.Participations.SingleOrDefault(part => part.UserGroupMembership.User.Equals(currentUser)),
                                                invitableUsers,
                                                peanutParticipationTypes,
                                                new PeanutEditOptions(peanut, currentUser))));
        }
Example #3
0
        public ActionResult GetParticipationTypes(UserGroup userGroup)
        {
            var peanutParticipationTypes = PeanutParticipationTypeService.Find(userGroup);
            PeanutParticipationTypeSelectionModel participationTypeSelectionModel = new PeanutParticipationTypeSelectionModel();

            participationTypeSelectionModel.SelectableParticipationTypes = peanutParticipationTypes;
            return(PartialView("EditorTemplates/ParticipationType", participationTypeSelectionModel));
        }
Example #4
0
        public ActionResult AttendForm(Peanut peanut, User currentUser)
        {
            Require.NotNull(peanut, "peanut");
            Require.NotNull(currentUser, "currentUser");
            Require.IsFalse(() => peanut.IsFixed, "peanut");

            IList <PeanutParticipationType> peanutParticipationTypes = PeanutParticipationTypeService.Find(peanut.UserGroup);

            return(View("CreateParticipation", new PeanutParticipationCreateFormViewModel(peanut, peanutParticipationTypes.ToList())));
        }
Example #5
0
        public ActionResult Update(Peanut peanut, PeanutUpdateCommand peanutUpdateCommand, User currentUser)
        {
            if (!ModelState.IsValid)
            {
                IList <PeanutParticipationType> peanutParticipationTypes = PeanutParticipationTypeService.Find(peanut.UserGroup);
                return(View("Update", new PeanutUpdateViewModel(peanut, peanutUpdateCommand, peanutParticipationTypes)));
            }

            PeanutService.Update(peanut,
                                 peanutUpdateCommand.PeanutDto,
                                 peanutUpdateCommand.Requirements.Values.ToList(),
                                 peanutUpdateCommand.PeanutCommentCreateCommand.Comment,
                                 new PeanutUpdateNotificationOptions(peanutUpdateCommand.PeanutCommentCreateCommand.SendUpdateNotification,
                                                                     Url.Action("Show", "Peanut", new { peanut = peanut.BusinessId }, Request.Url.Scheme)),
                                 currentUser);

            return(RedirectToAction("Show", new { peanut = peanut.BusinessId }));
        }
Example #6
0
        public ActionResult UpdateForm(Peanut peanut, User currentUser)
        {
            IList <PeanutParticipationType> peanutParticipationTypes = PeanutParticipationTypeService.Find(peanut.UserGroup);

            return(View("Update", new PeanutUpdateViewModel(peanut, peanutParticipationTypes)));
        }