Beispiel #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 }));
        }
Beispiel #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));
        }