Example #1
0
        public ActionResult Expired(Guid activityId)
        {
            var activityRepository = new ActivityRepository();
            var activity = activityRepository.GetById(activityId);

            return View(Mapper.Map(activity, new ActivityViewModel()));
        }
        public void GetByIdTest()
        {
            var repository = new ActivityRepository();

            var activity = new Activity { Name = "Test activiteit", OrganizerEmail = "*****@*****.**" };
            repository.Save(activity);

            var persisted = repository.GetById(activity.Id);

            Assert.AreEqual(activity.Id, persisted.Id);
        }
Example #3
0
        public ActionResult Attend(string accountId, string activityId, bool fullhouse = false)
        {
            var accountRepository = new AccountRepository();
            var account = accountRepository.GetById(accountId);

            if (account == null) return View("Error");

            var activityRepository = new ActivityRepository();
            var activity = activityRepository.GetById(activityId);

            if (activity.HasExpired())
            {
                return RedirectToAction("Expired", "Activity", new { activityId = activity.Id });
            }

            var vm = Mapper.Map(activity, new ActivityViewModel());

            // Viewmodel vullen met berekend aantal plaatsen
            foreach (var meeting in activity.Meetings)
            {
                foreach (var meetingVm in vm.Meetings.Where(meetingVm => meeting.Id == meetingVm.Id))
                {
                    meetingVm.AttendeesCount = meeting.MaxAttendeesCount - meeting.CalculateAttendeesCount();
                }
            }

            var attendee = account.FindAttendeeForActivity(activity);

            if (attendee != null)
            {
                ViewBag.SelectedMeetingId = attendee.Meeting.Id;
            }

            ViewBag.Fullhouse = fullhouse;
            ViewBag.AccountId = account.Id;

            return View(vm);
        }
Example #4
0
        public ActionResult Overview(AttendeeViewModel vm)
        {
            // Pak de activiteit
            var activityRepository = new ActivityRepository();
            var activity = activityRepository.GetById(vm.Meeting.Activity.Id.Value);

            // Pak de bijhorende meeting
            var meeting = activity.Meetings.Where(x => x.Id == vm.Meeting.Id).First();
            var availableSeats = (meeting.MaxAttendeesCount - meeting.CalculateAttendeesCount());

            // Zoek of de Attendee al bestaat
            var attendeeRepository = new AttendeeRepository();
            var attendee = vm.Id.HasValue ? attendeeRepository.GetById(vm.Id.Value) : null;

            var accountRepository = new AccountRepository();

            // Filter invalid children
            for (var i = vm.Children.Count - 1; i >= 0; i--)
            {
                var child = vm.Children[i];

                if (child.Id == null && child.Delete)
                {
                    vm.Children.Remove(child);
                }
            }

            // Pak de account
            var account = accountRepository.GetById(vm.Account.Id.Value);

            if (attendee != null && attendee.Meeting != null && attendee.Meeting.Id != meeting.Id)
            {
                if (availableSeats < vm.Children.Where(c => !c.Delete).Count())
                {
                    return RedirectToAction("Attend", "Activity", new { activityId = activity.Id, accountId = account.Id, fullhouse = true });
                }
            }
            else if (availableSeats < vm.Children.Where(c => !c.Delete && c.Id == null).Count())
            {
                return RedirectToAction("Attend", "Activity", new { activityId = activity.Id, accountId = account.Id, fullhouse = true });
            }

            if (attendee == null)
            {
                attendee = Mapper.Map(vm, new Attendee());
                attendee.Account = account;
            }
            else
            {
                foreach (var child in vm.Children)
                {
                    var existingChild = attendee.Children.Where(x => x.Id == child.Id).FirstOrDefault();

                    if (existingChild == null)
                    {
                        // Add
                        var newChild = Mapper.Map(child, new Child());
                        newChild.Attendee = attendee;

                        attendee.Children.Add(newChild);
                    }
                    else
                    {
                        if (child.Delete)
                        {
                            // Delete
                            attendee.Children.Remove(existingChild);
                        }

                        else
                        {
                            // Update
                            Mapper.Map(child, existingChild);
                        }
                    }
                }
            }

            // Assign the meeting
            attendee.Meeting = meeting;

            attendeeRepository.Save(attendee);

            // Sla ook de account op
            account.Attendees.Add(attendee);
            accountRepository.Save(account);

            // Send an initial iCal Appointment
            AppointmentService.SendAppointment(GetMailMessage(attendee.Account, activity, meeting, false),
                                                meeting.Location,
                                                activity.Name,
                                                string.Concat(attendee.Account.Id, activity.Id),
                                                meeting.DateStart,
                                                meeting.DateEnd);

            // Set the Activity Name in the ViewBag, so we can access it from the View
            ViewBag.ActivityName = activity.Name;

            return View(Mapper.Map(attendee, vm));
        }
Example #5
0
        public ActionResult PickAttendees(string activityId, string accountId, FormCollection form)
        {
            var activityRepository = new ActivityRepository();
            Activity activity = activityRepository.GetById(activityId);

            var accountRepository = new AccountRepository();
            Account account = accountRepository.GetById(accountId);

            Meeting meeting = activity.Meetings.Where(m => m.Id == Guid.Parse(form["meeting.Id"])).FirstOrDefault();
            if (meeting == null) return View("Error");

            AttendeeViewModel vm;

            var attendee = account.FindAttendeeForActivity(activity);

            if (attendee == null)
            {
                vm = new AttendeeViewModel
                {
                    Account = Mapper.Map(account, new AccountViewModel()),
                    Meeting = Mapper.Map(meeting, new MeetingViewModel())
                };

                vm.BuildDefaultChildren();
            }
            else
            {
                attendee.Meeting = meeting;

                vm = Mapper.Map(attendee, new AttendeeViewModel());
            }

            return View(vm);
        }