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 static UserSerializable ToUserSerializable(this ProjectCureData.Models.User u) { return(u != null ? new UserSerializable { UserId = u.UserId, UserName = u.UserEmail, LastName = u.UserLastName, FirstName = u.UserFirstName, Roles = u.Role != null ? new[] { u.Role.RoleName } : new string[] { } } : null); }
public static string FirstEventText(this ProjectCureData.Models.User u) { if (u != null) { var firstEvent = u.Events.FirstOrDefault(); if (firstEvent != null) { return(string.Format("{0} - {1:M} {1:t}", firstEvent.EventTitle, firstEvent.EventStartDateTime)); } } return(""); return(u != null ? string.Format("", u.Events.FirstOrDefault()) : ""); }