Ejemplo n.º 1
0
        public ActionResult ChangePassword(ChangePasswordViewModel model)
        {




            if (WebHelper.VerifyCurrentPassword(model.OldPassword))
            {
                var svc = new UserAppService();
                var usr = svc.GetUserByName(HealthAuthentication.SessionInfo.UserName);
                string newsalt;
                usr.Password = WebHelper.EncryptPassword(model.NewPassword, out newsalt);
                usr.Salt = newsalt;
                svc.SaveUser(usr);



                ViewBag.Error = "0";
            }
            else
            {
                ViewBag.Error = "1";
            }




            return View(model);
        }
Ejemplo n.º 2
0
 public static void UpdateUserState(string userName, int userStateId) {
     var svc = new UserAppService();
     var user = svc.GetUserByName(userName);
     user.UserStateId = userStateId;
     svc.SaveUser(user);
 }
Ejemplo n.º 3
0
 public static void UpdateUserTryCounter(string userName, int accessTryCount) {
     var svc = new UserAppService();
     var user = svc.GetUserByName(userName);
     user.TryAccessCount = accessTryCount;
     svc.SaveUser(user);
 }
Ejemplo n.º 4
0
 public static void UpdateLastLoginDate(int userId) {
     var svc = new UserAppService();
     var usr = svc.GetUser(userId);
     usr.LastLoginDate = DateTime.Now;
     svc.SaveUser(usr);
 }
Ejemplo n.º 5
0
        public ActionResult Edit(UserViewModel model)
        {
            model.UserStates = GetUserStates(); //Reload List For Clean Model

            try
            {
                var svc = new UserAppService();

                var o = new User
                {
                    UserName = model.UserName,
                    
                    UserStateId = model.UserStateId,
                    HasChangePassword = model.HasChangePassword


                };
                if (model.UserId == -1)
                {
                    string salt;
                    var hashedPassword = WebHelper.EncryptPassword(model.Password, out salt);
                    o.Password = hashedPassword;
                    o.Salt = salt;
                }
                else
                {
                    if (String.IsNullOrEmpty(model.Password))
                    {
                        var ousr = new UserAppService().GetUser(model.UserId);

                        o.Password = ousr.Password;
                        o.Salt = ousr.Salt;

                    }
                    else
                    { //GetCurrentData
                        string salt;
                        var hashedPassword = WebHelper.EncryptPassword(model.Password, out salt);
                        o.Password = hashedPassword;
                        o.Salt = salt;
                        
                    }

                }


                if (model.UserId == -1)
                {

                    if(CommonHelper.ExistUserName(model.UserName))
                    {
                        ViewBag.Feed = 2;
                        return View(model);

                    }

                    o.LastLoginDate = DateTime.Now;
                    o.AccessCount = 0;
                    o.TryAccessCount = 0;
                   var userId= svc.AddUser(o);

                    var svcUserRole = new UserRoleAppService();

                    var roles = model.AssignedUserRole.Split(',');
                    foreach (var r in roles)
                    {
                        svcUserRole.AddUserRole(new UserRole { RoleId = Convert.ToInt32(r), UserId = userId });

                    }
                    

                    
                    ViewBag.Feed = 0;
                }
                else
                {
                    o.UserId = model.UserId;
                    o.LastLoginDate = DateTime.Now;
                    if (model.IsDeleteAction == 0)
                    {

                        svc.SaveUser(o);


                        var svcUserRole = new UserRoleAppService();
                        svcUserRole.RemoveUserRoleByUserId(o.UserId);
                        var roles = model.AssignedUserRole.Split(',');
                        foreach (var r in roles)
                        {
                            svcUserRole.AddUserRole(new UserRole { RoleId = Convert.ToInt32(r), UserId = o.UserId });

                        }

                        var eusr = new UserAppService().GetUser(model.UserId);
                        model.UserRoles = eusr.UserRoles.ToList();

                    }
                    else
                    {
                        var svcUserRole = new UserRoleAppService();
                        svcUserRole.RemoveUserRoleByUserId(o.UserId);
                        svc.RemoveUser(model.UserId);
                        model.UserRoles = new List<UserRole>();
                    }
                    ViewBag.Feed = 0;
                }
            }
            catch (Exception)
            {
                ViewBag.Feed = 1;

            }
      
            return View(model);
        }