public ActionResult ChangePassword(int?user, int?OrgId, int?CompanyId, ChangePassword tt)
        {
            MembershipUser mu    = Membership.GetUser(Session["UserInfo"].ToString());
            string         pass  = mu.GetPassword("ok");
            string         myUrl = "/Login";

            if (tt.Newpassword.Length < 6)
            {
                return(Json(new { success = false, response = "Password must be minimum 6 characters." }));
            }

            if (pass == tt.Oldpassword)
            {
                if (mu.ChangePassword(pass, tt.Newpassword))
                {
                    var reqLogin = dbUser.GetUserById(user.Value);//db.HRMS_UserMst_ST.Include(c => c.HRMS_UserType_ST).Where(x => x.UserId == user).FirstOrDefault();
                    if (reqLogin.LoginDate == null)
                    {
                        reqLogin.LoginDate = DateTime.Now;
                        dbUser.UpdateUser(reqLogin);
                    }

                    return(Json(new { success = true, response = myUrl }));
                }
                return(Json(new { success = false, response = "Password change failed. Please contact your administrator." }));
            }

            return(Json(new { success = false, response = "Old password is incorrect." }));
        }
 public ActionResult User(SMIM_UserMst_ST User)
 {
     try
     {
         string strMessage = "";
         bool   _success   = false;
         if (User.UserId > 0)
         {
             utility.IsSpecifed <SMIM_UserMst_ST>(User);
             int maxValue = dbUser.UpdateUser(User);
             if (maxValue > 0)
             {
                 strMessage = "Record successfully updated.";
                 _success   = true;
             }
             else
             {
                 strMessage = "Application server error.";
             }
         }
         else
         {
             string password = new Utility().GetUniqueKey(8);
             //Membership.CreateUser(User.UserName, password);
             MembershipCreateStatus status;
             utility.IsSpecifed <SMIM_UserMst_ST>(User);
             int maxValue = dbUser.InsertUser(User);
             User.UserId = maxValue;
             if (maxValue > 0)
             {
                 MembershipUser newUser = Membership.CreateUser(User.UserName, password, User.UserName, "ok", "ok", true, out status);
                 strMessage = "Record successfully saved. Password for User '" + User.UserName + "' is " + password + "";
                 _success   = true;
             }
             else
             {
                 strMessage = "Application server error.";
             }
         }
         return(Json(new { success = _success, response = strMessage }));
     }
     catch (Exception ex)
     {
         Log.LogWrite(ex.Message, "User Insert/Edit", ex);
         return(Json(new { success = false, response = ex.Message.ToString() }));
     }
 }
Example #3
0
        public HttpResponseMessage Create(HttpRequestMessage request, UserViewModel user)
        {
            return(CreateHttpResponse(request, () =>
            {
                var modelService = new UserServiceModel();

                var model = new ApplicationUser();

                var nofi = string.Empty;

                modelService.UpdateUser(user);

                model.MappingServiceToDataModelOfUser(modelService);

                if (!_userService.AddNewUser(model, modelService))
                {
                    nofi = (Helper.Enum.Notification.STR_ADD_USER_SUCCESS).GetDescription();
                }

                HttpResponseMessage response = request.CreateResponse(HttpStatusCode.OK, new { mess = nofi });

                return response;
            }));
        }