public async Task <IActionResult> UpdateEvent(EventViewModel model) { var currentUser = await _userManager.GetUserAsync(User); var eventDbModel = EventModelMapper.MapFrom(currentUser, model); var updatedEvent = _eventRepo.Update(eventDbModel); var newInvitees = _inviteeHelper.GetInviteeEmailsFromView(model).OrderBy(x => x).ToList(); var currentInvitees = await _inviteeHelper.GetInviteeEmails(updatedEvent.Id); var sortedCurrentInvitees = currentInvitees.OrderBy(x => x).ToList(); var inviteesToAdd = newInvitees.Except(sortedCurrentInvitees).ToList(); foreach (var inviteeToAdd in inviteesToAdd) { var result = await _inviteeHelper.AddInviteeFromEmail(inviteeToAdd, currentUser, updatedEvent); } var inviteesToRemove = sortedCurrentInvitees.Except(newInvitees).ToList(); foreach (var inviteeToRemove in inviteesToRemove) { var result = await _inviteeHelper.RemoveInviteeFromEmail(inviteeToRemove, updatedEvent); } return(RedirectToAction("ViewCalendar", "Scheduler")); }
public async Task <IActionResult> CreateEvent(EventViewModel model) { var currentUser = await _userManager.GetUserAsync(User); var eventDbModel = EventModelMapper.MapFrom(currentUser, model); var newEvent = _eventRepo.Create(eventDbModel); var emails = _inviteeHelper.GetInviteeEmailsFromView(model); foreach (var email in emails) { var result = await _inviteeHelper.AddInviteeFromEmail(email, currentUser, newEvent); } return(RedirectToAction("ViewCalendar", "Scheduler")); }