public ActionResult MembershipStatistics(UserGroup userGroup, UserGroupMembership userGroupMembership, User currentUser) { Require.NotNull(userGroup, "userGroup"); Require.NotNull(userGroupMembership, "userGroupMembership"); Require.IsTrue(() => userGroupMembership.UserGroup.Equals(userGroup), "userGroupMembership"); Require.IsFalse(() => userGroupMembership.MembershipType == UserGroupMembershipType.Quit, "userGroupMembership"); UserGroupMembership currentUsersMembershipInGroup = UserGroupService.FindMembershipsByUserAndGroup(currentUser, userGroup); IList <UserGroupMembership> members = UserGroupService.FindMembershipsByGroups(PageRequest.All, new List <UserGroup> { userGroup }, new List <UserGroupMembershipType> { UserGroupMembershipType.Administrator, UserGroupMembershipType.Member }).ToList(); IDictionary <UserGroupMembership, int> userGroupMembersKarma = PeanutService.GetUserGroupMembersKarma(userGroup); return(View("UserGroupMembershipStatistics", new UserGroupMembershipStatisticsViewModel(userGroupMembership, members, new UserGroupMembershipOptions(userGroupMembership, currentUsersMembershipInGroup), PeanutService.GetPeanutsUserGroupMembershipStatistics(userGroupMembership), userGroupMembersKarma ))); }
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 MembershipDetails(UserGroup userGroup, UserGroupMembership userGroupMembership, User currentUser) { Require.NotNull(userGroup, "userGroup"); Require.NotNull(userGroupMembership, "userGroupMembership"); Require.IsTrue(() => userGroupMembership.UserGroup.Equals(userGroup), "userGroupMembership"); Require.IsFalse(() => userGroupMembership.MembershipType == UserGroupMembershipType.Quit, "userGroupMembership"); IList <UserGroupMembership> members = UserGroupService.FindMembershipsByGroups(PageRequest.All, new List <UserGroup> { userGroup }, new List <UserGroupMembershipType> { UserGroupMembershipType.Administrator, UserGroupMembershipType.Member }).ToList(); UserGroupMembership currentUsersMembershipInGroup = UserGroupService.FindMembershipsByUserAndGroup(currentUser, userGroup); IPage <Peanut> peanuts = new Page <Peanut>(new List <Peanut>(), 0); if (userGroupMembership.MembershipType == UserGroupMembershipType.Administrator) { peanuts = PeanutService.FindAllPeanutsInGroup(userGroup); } return(View("UserGroupMembershipDetails", new UserGroupMembershipDetailsViewModel(userGroupMembership, members, new UserGroupMembershipOptions(userGroupMembership, currentUsersMembershipInGroup), peanuts))); }
public ActionResult Index(User currentUser, int year, int month) { Require.NotNull(currentUser, "currentUser"); Require.Ge(year, 2000, "year"); Require.Ge(month, 1, "month"); Require.Le(month, 12, "month"); DateTime firstDayOfMonth = new DateTime(year, month, 1); /*Ab Montag der Woche des ersten Tages des Monats.*/ DateTime from = firstDayOfMonth.GetFirstDayOfWeek(); /*Bis Sonntag der Woche des letzten Tages Monats*/ DateTime to = firstDayOfMonth .AddMonths(1) // 1. des nächsten Monats .AddDays(-1) // letzter des aktuellen Monats .GetFirstDayOfWeek() // Montag der letzten Woche .AddDays(6); // Sonntag der letzten Woche IPage <PeanutParticipation> peanutParticipations = PeanutService.FindParticipationsOfUser(PageRequest.All, currentUser, from, to); IPage <Peanut> attendablePeanuts = PeanutService.FindAttendablePeanutsForUser(PageRequest.All, currentUser, from, to); IDictionary <DateTime, IList <PeanutParticipation> > peanutParticipationsByDate = peanutParticipations.GroupBy(participation => participation.Peanut.Day) .ToDictionary(g => g.Key, g => (IList <PeanutParticipation>)g.ToList()); IDictionary <DateTime, IList <Peanut> > attendablePeanutsByDate = attendablePeanuts.GroupBy(peanut => peanut.Day) .ToDictionary(g => g.Key, g => (IList <Peanut>)g.ToList()); return(View("Index", new PeanutsIndexViewModel(year, month, peanutParticipationsByDate, attendablePeanutsByDate))); }
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 })); }
public ActionResult InviteUser(Peanut peanut, PeanutInvitationCreateCommand peanutInvitationCreateCommand, User currentUser) { Require.NotNull(peanut, "peanut"); Require.NotNull(peanutInvitationCreateCommand, "peanutInvitationCreateCommand"); Require.NotNull(currentUser, "currentUser"); if (peanut.IsFixed) { return(View("CanNotInvite", new PeanutParticipationRejectedViewModel(peanut))); } string peanutUrl = Url.Action("Show", "Peanut", new { peanut = peanut.BusinessId }, Request.Url.Scheme); string attendPeanutUrl = Url.Action("AttendForm", "Peanut", new { peanut = peanut.BusinessId }, Request.Url.Scheme); if (peanutInvitationCreateCommand.UserGroupMembership != null) { PeanutService.InviteUser(peanut, peanutInvitationCreateCommand.UserGroupMembership, new PeanutParticipationDto(peanutInvitationCreateCommand.PeanutParticipationType, PeanutParticipationState.Pending), new PeanutInvitationNotificationOptions(peanutUrl, attendPeanutUrl), currentUser); } else { PeanutService.InviteAllGroupMembers(peanut, peanut.UserGroup, peanutInvitationCreateCommand.PeanutParticipationType, new PeanutInvitationNotificationOptions(peanutUrl, attendPeanutUrl), currentUser); } return(RedirectToAction("Show", new { peanut = peanut.BusinessId })); }
public ActionResult Show(Bill bill, User currentUser) { Require.NotNull(bill, "bill"); Require.NotNull(currentUser, "currentUser"); Peanut createdFromPeanut = PeanutService.FindFromBill(bill); return(View("Show", new BillShowViewModel(bill, new BillOptions(bill, currentUser), createdFromPeanut))); }
public ActionResult UpdateState(Peanut peanut, PeanutState peanutState, User currentUser) { Require.NotNull(peanut, "peanut"); Require.NotNull(currentUser, "currentUser"); string peanutUrl = Url.Action("Show", "Peanut", new { peanut = peanut.BusinessId }, Request.Url.Scheme); PeanutUpdateNotificationOptions peanutUpdateNotificationOptions = new PeanutUpdateNotificationOptions(true, peanutUrl); PeanutService.UpdateState(peanut, peanutState, peanutUpdateNotificationOptions, currentUser); return(RedirectToAction("Show", new { peanut = peanut.BusinessId })); }
public ActionResult DeclineParticipation(Peanut peanut, PeanutParticipation peanutParticipation, User currentUser) { Require.NotNull(peanut, "peanut"); Require.NotNull(peanutParticipation, "peanutParticipation"); Require.IsTrue(() => peanutParticipation.Peanut.Equals(peanut), "peanutParticipation"); PeanutService.RemoveParticipations(peanut, new List <UserGroupMembership> { peanutParticipation.UserGroupMembership }, currentUser); return(RedirectToAction("Day", new { year = peanut.Day.Year, month = peanut.Day.Month, day = peanut.Day.Day })); }
public ActionResult AddComment(Peanut peanut, PeanutCommentCreateCommand peanutCommentCreateCommand, User currentUser) { if (!ModelState.IsValid) { return(RedirectToAction("Show", new { peanut = peanut.BusinessId })); } PeanutService.AddComment(peanut, peanutCommentCreateCommand.Comment, new PeanutUpdateNotificationOptions(peanutCommentCreateCommand.SendUpdateNotification, Url.Action("Show", "Peanut", new { peanut = peanut.BusinessId }, Request.Url.Scheme)), currentUser); return(RedirectToAction("Show", new { peanut = peanut.BusinessId })); }
public async Task <ActionResult> Index(User currentUser) { IPage <UserGroupMembership> memberships = UserGroupService.FindMembershipsByUser(PageRequest.All, currentUser, new List <UserGroupMembershipType> { UserGroupMembershipType.Administrator, UserGroupMembershipType.Member }); IPage <Payment> pendingPayments = PaymentService.FindPendingPaymentsByUser(PageRequest.First, currentUser); IPage <Payment> declinedPayments = PaymentService.FindDeclinedPaymentsByUser(PageRequest.First, currentUser); IPage <PeanutParticipation> peanutParticipations = PeanutService.FindParticipationsOfUser(PageRequest.All, currentUser, DateTime.Today, DateTime.Today); IPage <Bill> declinedBills = BillService.FindDeclinedCreditorBillsByUser(PageRequest.All, currentUser); List <Bill> unsettledBills = BillService.FindCreditorBillsForUser(PageRequest.All, currentUser, false).ToList(); unsettledBills.AddRange(BillService.FindDebitorBillsForUser(PageRequest.All, currentUser, false).ToList()); return(View("Index", new IndexViewModel(peanutParticipations, memberships, unsettledBills, declinedBills, pendingPayments, declinedPayments, currentUser.DisplayName))); }
public ActionResult Day(int year, int month, int day, User currentUser) { DateTime date = new DateTime(year, month, day); IPage <PeanutParticipation> peanutParticipations = PeanutService.FindParticipationsOfUser(PageRequest.All, currentUser, date, date, new [] { PeanutParticipationState.Confirmed }); IPage <Peanut> attendablePeanuts = PeanutService.FindAttendablePeanutsForUser(PageRequest.All, currentUser, date, date); if (peanutParticipations.TotalElements == 1 && attendablePeanuts.TotalElements == 0) { /*Wenn es an diesem Tag nur diesen einen Peanut gibt, dann diesen anzeigen*/ return(RedirectToAction("Show", "Peanut", new { peanut = peanutParticipations.Single().Peanut.BusinessId })); } else { return(View("List", new PeanutsListViewModel(date, date, peanutParticipations.ToList(), attendablePeanuts.ToList()))); } }
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 })); }
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 })); }