Exemplo n.º 1
0
        public ActionResult ResetPassword(int id)
        {
            var success = false;

            try
            {
                var user = Repository.GetUserById(id);
                if (user != null)
                {
                    var newPassword = GetNewPassword();
                    user.UserPassword = newPassword;
                    Repository.UpdatePassword(user);

                    success = true;

                    var notifier = new EmailNotifier();
                    notifier.GiveTemporaryPasswordNotification(Repository, user.UserEmail, newPassword);

                    return(Json(new
                    {
                        UserId = user.UserId,
                        UserName = user.UserFirstName + " " + user.UserLastName,
                        UserEmail = user.UserEmail,
                        success,
                    }));
                }
            }
            catch (Exception ex)
            {
                var log = ex.GetBaseException().Message;
            }


            return(Json(new { success }));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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;
            }
        }
Exemplo n.º 4
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid && Repository.IsValidUser(model.UserName, model.OldPassword))
            {
                Repository.UpdatePassword(new ProjectCureData.Models.User
                {
                    UserEmail    = model.UserName,
                    UserPassword = model.NewPassword
                });

                model.PasswordChanged = true;

                var notifier = new EmailNotifier();
                notifier.PasswordChangeConfirmationNotification(Repository, model.UserName);

                return(View("ChangePasswordSuccess"));
            }

            return(View(model));
        }
Exemplo n.º 5
0
        public ActionResult UnfilledEventsNotification()
        {
            try
            {
                var events = Repository.GetEventsBetweenDates(DateTime.Today, DateTime.Today.AddDays(UserController.UnfilledNotificationEmailDays))
                             .Where(c => c.EventManagerId == null)
                             .OrderBy(c => c.EventStartDateTime)
                             .ToList();

                if (events != null && events.Count() > 0)
                {
                    var notifier = new EmailNotifier();
                    notifier.UnfilledEventsNotification(Repository, events);

                    return(Json(new
                    {
                        success = true,
                        message = string.Format("{0} unfilled event(s) were found.\rA notification email was sent out to active sort leaders.", events.Count)
                    }));
                }
                else
                {
                    return(Json(new
                    {
                        success = true,
                        message = "No unfilled events were found."
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    success = false,
                    message = ex.GetBaseException().Message
                }));
            }
        }