public void FindAllTest()
        {
            var repository = new ActivityRepository();
            var activities = repository.FindAll();

            Assert.AreNotEqual(0, activities.Count);
        }
        public ActionResult Expired(Guid activityId)
        {
            var activityRepository = new ActivityRepository();
            var activity = activityRepository.GetById(activityId);

            return View(Mapper.Map(activity, new ActivityViewModel()));
        }
        public static void Seed()
        {
            var activityRespository = new ActivityRepository();
            var activity = activityRespository.GetActive();

            if (activity != null) return;

            var seed = new Activity
            {
                Name = "Sinterklaasfeest bij Achmea op 28 november 2015",
                OrganizerEmail = "*****@*****.**",
                OrganizerName = "Sinterklaas",
                Active = true,
                EndDate = DateTime.Parse("2015-11-05 16:00:00.000"),
                Meetings = new List<Meeting>()
                {
                    new Meeting
                    {
                        Location = "Midi, Heuvelring 108, Tilburg",
                        DateStart = DateTime.Parse("2015-11-28 10:00:00.000"),
                        DateEnd = DateTime.Parse("2015-11-28 13:00:00.000"),
                        MaxAttendeesCount = 100,
                        Description = "Sessie 1 voor leden: inloop 9.30, start musical 10.00"
                    },
                    new Meeting
                    {
                        Location = "Midi, Heuvelring 108, Tilburg",
                        DateStart = DateTime.Parse("2015-11-28 10:00:00.000"),
                        DateEnd = DateTime.Parse("2015-11-28 13:00:00.000"),
                        MaxAttendeesCount = 275,
                        Description = "Sessie 1 voor niet-leden: inloop 9.30, start musical 10.00"
                    },
                    new Meeting
                    {
                        Location = "Midi, Heuvelring 108, Tilburg",
                        DateStart = DateTime.Parse("2015-11-28 12:30:00.000"),
                        DateEnd = DateTime.Parse("2015-11-28 15:30:00.000"),
                        MaxAttendeesCount = 100,
                        Description = "Sessie 2 voor leden: inloop 12.00, start musical 12.30"
                    },
                    new Meeting
                    {
                        Location = "Midi, Heuvelring 108, Tilburg",
                        DateStart = DateTime.Parse("2015-11-28 12:30:00.000"),
                        DateEnd = DateTime.Parse("2015-11-28 15:30:00.000"),
                        MaxAttendeesCount = 275,
                        Description = "Sessie 2 voor niet-leden: inloop 12.00, start musical 12.30"
                    }
                }
            };

            using (var transaction = Session.BeginTransaction())
            {
                Session.Save(seed);

                transaction.Commit();
            }
        }
        public void UpdateTest()
        {
            var repository = new ActivityRepository();

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

            repository.Save(activity);
        }
        public void DeleteTest()
        {
            var repository = new ActivityRepository();

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

            // no exception = ok
        }
        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);
        }
Exemple #7
0
        public CsvActionResult Export(string secret)
        {
            if (IsInvalidSecret(secret)) return new CsvActionResult(new DataTable());

            var activityRepository = new ActivityRepository();
            var activity = activityRepository.GetActive();

            var dataTable = new DataTable();
            dataTable.Columns.Add(new DataColumn("Activteit"));
            dataTable.Columns.Add(new DataColumn("Sessie naam"));
            dataTable.Columns.Add(new DataColumn("Medewerker e-mail"));
            dataTable.Columns.Add(new DataColumn("Medewerker voornaam"));
            dataTable.Columns.Add(new DataColumn("Medewerker achternaam"));
            dataTable.Columns.Add(new DataColumn("Kind geslacht"));
            dataTable.Columns.Add(new DataColumn("Kind voornaam"));
            dataTable.Columns.Add(new DataColumn("Kind achternaam"));
            dataTable.Columns.Add(new DataColumn("Kind leeftijd"));

            foreach (var meeting in activity.Meetings)
            {
                foreach (var attendee in meeting.Attendees)
                {
                    foreach (var child in attendee.Children)
                    {
                        var row = dataTable.NewRow();

                        row["Activteit"] = activity.Name;
                        row["Sessie naam"] = meeting.Description;
                        row["Medewerker e-mail"] = (attendee.Account != null) ? attendee.Account.Email : string.Empty;
                        row["Medewerker voornaam"] = attendee.Firstname;
                        row["Medewerker achternaam"] = attendee.Lastname;
                        row["Kind geslacht"] = child.Gender == Gender.Male ? "Jongen" : "Meisje";
                        row["Kind voornaam"] = child.Firstname;
                        row["Kind achternaam"] = child.Lastname;
                        row["Kind leeftijd"] = child.Age;

                        dataTable.Rows.Add(row);
                    }
                }
            }

            return new CsvActionResult(dataTable);
        }
        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);
        }
        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));
        }
        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);
        }
        private MailMessage GetMailMessage(Account account)
        {
            var activityRepository = new ActivityRepository();

            var activity = activityRepository.GetActive();

            var body = new StringBuilder();
            var request = System.Web.HttpContext.Current.Request;

            body.Append("<html><body>");
            body.AppendFormat("<p><strong>Via deze link kun je je aanmelden voor {0}</strong></p>", activity.Name);
            body.AppendFormat("<p><a href=\"{0}://{1}/Account/Verify/{2}/{3}\">Klik hier om verder te gaan met je aanmelding</a>.</p>",
                request.Url.Scheme, // http or https
                request.Headers["host"], // Server / domain name
                account.Id,
                GenerateToken(string.Concat(account.Id.ToString(), account.Email), hmacSymetricKey));
            body.AppendFormat("</body></html>");

            #if DEBUG
            body.Append("<br /> <br />");
            body.AppendFormat("{0}://{1}/Account/Verify/{2}/{3}",
                request.Url.Scheme, // http or https
                request.Headers["host"], // Server / domain name
                account.Id,
                GenerateToken(string.Concat(account.Id.ToString(), account.Email), hmacSymetricKey));
            #endif
            return new MailMessage(new MailAddress(activity.OrganizerEmail, activity.OrganizerName), new MailAddress(account.Email))
            {
                IsBodyHtml = true,
                Body = body.ToString(),
                Subject = "Uw inschrijving voor het Achmea Sinterklaasfeest"
            };
        }
        public ActionResult Verify(string id, string token)
        {
            var accountRepository = new AccountRepository();
            var account = accountRepository.GetById(id);

            if (account != null)
            {
                if (ValidateToken(string.Concat(account.Id, account.Email), hmacSymetricKey, token))
                {
                    // Get the current activity
                    var activityRepository = new ActivityRepository();
                    var activity = activityRepository.GetActive();

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

                    // Set auth cookie
                    FormsAuthentication.SetAuthCookie(account.Email, false);

                    // Set the account as verified
                    account.Verified = true;

                    // Store the account again in the database
                    accountRepository.Save(account);

                    // Now redirect to the Attend page on the Activity controller, passing the account variable
                    return RedirectToAction("Attend", "Activity", new { activityId = activity.Id, accountId = account.Id });
                }
                else
                {
                    return View("Expired", Mapper.Map(account, new AccountViewModel()) );
                }
            }

            throw new InvalidOperationException(string.Format("Account niet gevonden. {0}, token {1}", id, token));
        }