public void TestNewAccount() { var account = new Account(); account.Email = "*****@*****.**"; account.Verified = true; var repository = new AccountRepository(); repository.Save(account); }
public ActionResult Signup(string email) { if (String.IsNullOrWhiteSpace(email)) return RedirectToAction("Signup"); email = email.Trim().ToLower(); var accountRepository = new AccountRepository(); var account = accountRepository.GetByEmailAddress(email); if (account == null) { // Create a new Account account = AccountFactory.Build(email); // Save it accountRepository.Save(account); using (var message = GetMailMessage(account)) { using (var smtpClient = new SmtpClient()) { smtpClient.Send(message); } } } #if DEBUG //else if (account.Verified) //{ // // Set auth cookie // FormsAuthentication.SetAuthCookie(account.Email, false); // // Get the current activity // var activityRepository = new ActivityRepository(); // var activity = activityRepository.GetActive(); // // 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 }); //} #endif // Log the user in return RedirectToAction("Thanks", "Account", new { id = account.Id }); }
public ActionResult Resend(string id) { var accountRepository = new AccountRepository(); var account = accountRepository.GetById(id); if (account != null) { //Multiview message? http://www.search-this.com/2009/02/05/aspnet-sending-email-both-in-html-and-plain-text/ using (var message = GetMailMessage(account)) { using (var smtpClient = new SmtpClient()) { smtpClient.Send(message); } } return RedirectToAction("Thanks", "Account", new { id = account.Id }); } return View("Error"); }
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); }
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)); }
public ActionResult Thanks(string id) { var accountRepository = new AccountRepository(); var account = accountRepository.GetById(id); var vm = Mapper.Map(account, new AccountViewModel()); if (account.Verified) { return View("ThanksAgain", vm); } return View(vm); }