예제 #1
0
        public IHttpActionResult UpdateUser([FromBody] JObject data)
        {
            try
            {
                int    userID        = !string.IsNullOrEmpty(data.SelectToken("UserID").Value <string>()) ? Convert.ToInt32(data.SelectToken("UserID").Value <string>()) : 0;
                string userName      = !string.IsNullOrEmpty(data.SelectToken("UserName").Value <string>()) ? data.SelectToken("UserName").Value <string>() : string.Empty;
                string loginName     = !string.IsNullOrEmpty(data.SelectToken("LoginName").Value <string>()) ? data.SelectToken("LoginName").Value <string>() : string.Empty;
                int    designationID = !string.IsNullOrEmpty(data.SelectToken("DesignationID").Value <string>()) ? Convert.ToInt32(data.SelectToken("DesignationID").Value <string>()) : 0;
                int    loggedUserID  = !string.IsNullOrEmpty(data.SelectToken("LoggedUserID").Value <string>()) ? Convert.ToInt32(data.SelectToken("LoggedUserID").Value <string>()) : 0;

                if (!manageUser.IsLoginNameAvailable(userID, loginName))
                {
                    UserVM userVM = new UserVM();
                    userVM.UserID        = userID;
                    userVM.UserName      = userName;
                    userVM.LoginName     = loginName;
                    userVM.DesignationID = designationID;
                    userVM.ModifiedBy    = loggedUserID;

                    bool status = manageUser.UpdateUser(userVM);

                    if (status)
                    {
                        return(Json(new { status = true, message = "Successfully Updated" }));
                    }
                    else
                    {
                        return(Json(new { status = false, message = "Update Failed" }));
                    }
                }
                else
                {
                    return(Json(new { status = false, message = "Login Name already exists" }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { status = false, message = "Unknown error occurred" }));
            }
        }