public ActionResult Edit(EditUserModel model) { if (ModelState.IsValid) { var user = new ProjectCureData.Models.User { UserId = model.UserId, UserEmail = model.UserName, UserFirstName = model.FirstName, UserLastName = model.LastName, UserRoleId = model.RoleId, UserActiveIn = model.IsActive, UserNotifyFiveDays = model.Notify5Days, UserNotifyTenDays = model.Notify10Days, }; var existingUser = Repository.GetUserById(user.UserId); Repository.SaveUser(user); var notifier = new EmailNotifier(); if (model.IsNew) { //set password for new user and notify via email var newPassword = GetNewPassword(); user.UserPassword = newPassword; Repository.UpdatePassword(user); notifier.GiveTemporaryPasswordNotification(Repository, user.UserEmail, newPassword); } else if (!model.IsNew && !user.UserActiveIn) { if (existingUser != null && existingUser.UserActiveIn) { //unassign from events, and send notifications //remove manager from future events if being inactivated var unassociatedEvents = Repository.RemoveManagerFromEvents(user.UserId); foreach (var evt in unassociatedEvents) { notifier.EventCancellationNotification(Repository, evt, user.UserEmail); } } } } model.Roles = Repository.GetRoleList(); return(PartialView("Edit", model)); }
public void Item(int id, EditEventModel input) { var notifier = new EmailNotifier(); switch (input.Action) { case EventEditAction.Assign: Repository.AssignManager(id, HttpContext.User.Identity.Name); break; case EventEditAction.Unassign: Repository.AssignManager(id, null); notifier.LeadCancellationNotification(Repository, Repository.GetEventById(id)); break; case EventEditAction.Edit: if (HttpContext.User.IsInRole("Admin")) { User manager = null; if (input.ManagerId != null) { manager = Repository.GetUserById(input.ManagerId.Value); } Event e = Repository.GetEventById(id); e.EventDescription = input.Description; e.EventStartDateTime = DateTime.ParseExact(input.Date + " " + input.StartTime, "M/d/yyyy HH:mm", CultureInfo.InvariantCulture); e.EventEndDateTime = DateTime.ParseExact(input.Date + " " + input.EndTime, "M/d/yyyy HH:mm", CultureInfo.InvariantCulture); e.EventTitle = input.Title; e.User = manager; e.EventManagerId = input.ManagerId; Repository.SaveEvent(e); } break; case EventEditAction.Delete: if (HttpContext.User.IsInRole("Admin")) { Event @event = Repository.GetEventById(id); string email = (@event != null && @event.User != null) ? @event.User.UserEmail : string.Empty; Repository.DeleteEventById(id); if (!string.IsNullOrWhiteSpace(email)) { notifier.EventCancellationNotification(Repository, @event, @event.User.UserEmail); } } break; } }