Esempio n. 1
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))));
        }
Esempio n. 2
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 }));
        }
Esempio n. 3
0
        public ActionResult GetParticipationTypes(UserGroup userGroup)
        {
            var peanutParticipationTypes = PeanutParticipationTypeService.Find(userGroup);
            PeanutParticipationTypeSelectionModel participationTypeSelectionModel = new PeanutParticipationTypeSelectionModel();

            participationTypeSelectionModel.SelectableParticipationTypes = peanutParticipationTypes;
            return(PartialView("EditorTemplates/ParticipationType", participationTypeSelectionModel));
        }
Esempio n. 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())));
        }
Esempio n. 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 }));
        }
Esempio n. 6
0
        public ActionResult Create(PeanutCreateCommand peanutCreateCommand, User currentUser)
        {
            Require.NotNull(peanutCreateCommand, "peanutCreateCommand");
            Require.NotNull(currentUser, "currentUser");

            if (!ModelState.IsValid)
            {
                List <UserGroupMembership> userGroupMemberships =
                    UserGroupService.FindMembershipsByUser(PageRequest.All, currentUser, _activeUsergroupMembershipTypes).ToList();
                List <UserGroup> userGroups = userGroupMemberships.Select(membership => membership.UserGroup).ToList();
                List <PeanutParticipationType> participationTypes = PeanutParticipationTypeService.GetAll(PageRequest.All).ToList();
                return(View("Create", new PeanutCreateViewModel(userGroups)));
            }

            /*Initiale Teilnehmer ermitteln.*/
            IDictionary <UserGroupMembership, PeanutParticipationDto> initialParticators = new Dictionary <UserGroupMembership, PeanutParticipationDto>();
            Peanut peanut = PeanutService.Create(peanutCreateCommand.UserGroup,
                                                 peanutCreateCommand.PeanutDto,
                                                 peanutCreateCommand.Requirements.Values.ToList(),
                                                 initialParticators,
                                                 currentUser);

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

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