예제 #1
0
        public JsonResult ProcessProfileUpdate(EditUserObj model)
        {
            try
            {
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();

                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                if (model.UserId < 1)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, Error = "Invalid Email Address" }));
                }

                if (string.IsNullOrEmpty(model.FirstName) || model.FirstName.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, Error = "First Name must be at least 2 characters" }));
                }

                if (string.IsNullOrEmpty(model.LastName) || model.LastName.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, Error = "Last Name must be at least 2 characters" }));
                }

                if (string.IsNullOrEmpty(model.MobileNumber) || model.MobileNumber.Length != 11)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, Error = "Invalid Mobile Number" }));
                }

                model.AdminUserId = userData.UserId;
                var retVal = new PortalUserManager().ModifyUser(model, userData.Email);
                if (retVal == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, Error = "Unable to update your profile at this time" }));
                }

                if (!retVal.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, Error = string.IsNullOrEmpty(retVal.Status.Message.FriendlyMessage) ? "Unable to update your profile at this time!" : retVal.Status.Message.FriendlyMessage }));
                }

                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
예제 #2
0
        public async Task <Response> editUser(int userId, string userName, string email, string password, EModelUserType userType)
        {
            EditUserObj cmdObj = new EditUserObj(userId, userName, email, password, userType);

            return(await doModelHttpRequest(cmdObj, ECmdObjType.EdtUserObj));
        }
예제 #3
0
        public JsonResult ProcessEditUserRequest(PortalUserViewModel portalUser)
        {
            try
            {
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();

                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                //var bearerAuth = MvcApplication.GetSessionBearerData(userData.Username);
                //var authToken = MvcApplication.GetSessionAuthData(userData.Username);

                //if (string.IsNullOrEmpty(bearerAuth) || bearerAuth.Length < 5)
                //{
                //    return Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid User Session! Please Re-Login" });
                //}

                //if (string.IsNullOrEmpty(authToken) || authToken.Length < 5)
                //{
                //    return Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid User Session! Please Re-Login" });
                //}

                if (portalUser == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid User Item" }));
                }

                if (string.IsNullOrEmpty(portalUser.FirstName) || portalUser.FirstName.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "First Name is required" }));
                }

                if (string.IsNullOrEmpty(portalUser.LastName) || portalUser.LastName.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Last Name is required" }));
                }

                if (string.IsNullOrEmpty(portalUser.Email) || portalUser.Email.Length < 5)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Email is required" }));
                }


                var passObj = new EditUserObj
                {
                    UserId       = portalUser.UserId,
                    FirstName    = portalUser.FirstName,
                    LastName     = portalUser.LastName,
                    AdminUserId  = userData.UserId,
                    MobileNumber = portalUser.MobileNumber,
                };


                var response = new PortalUserManager().ModifyUser(passObj, userData.Username);
                if (response == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }


                if (!response.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.FriendlyMessage) ? "Process Failed! Unable to add role" : response.Status.Message.FriendlyMessage }));
                }

                var updateRole = new EditUserRoleObj
                {
                    AdminUserId = userData.UserId,
                    UserId      = portalUser.UserId,
                    RoleIds     = string.Join(",", portalUser.MyRoleIds)
                };

                var response2 = new PortalRoleManager().UpdateUserRoles(updateRole, userData.Username);
                if (response2 == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }


                if (!response2.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.FriendlyMessage) ? "Process Failed! Unable to add role" : response.Status.Message.FriendlyMessage }));
                }

                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }