예제 #1
0
파일: demodb.cs 프로젝트: pmq20/mono_forked
    public override bool Equals(object o)
    {
        AdminUserProfile other = o as AdminUserProfile;

        if (other == null)
        {
            return(false);
        }
        return(UpEmail.Equals(other.UpEmail));
    }
예제 #2
0
        //
        // GET: /Admin/UserDetails/5

        public ActionResult UserDetails(int id = 0)
        {
            UserProfile Userprofile = UserManager.GetUserById(id);

            if (Userprofile == null)
            {
                return(HttpNotFound());
            }
            string[]         Roles            = UserManager.GetRolesByUserId(Userprofile.UserName);
            AdminUserProfile Adminuserprofile = new AdminUserProfile();

            Adminuserprofile.Roles    = Roles;
            Adminuserprofile.UserId   = id;
            Adminuserprofile.UserName = Userprofile.UserName;
            Adminuserprofile.Email    = Userprofile.Email;
            //other vars
            return(View(Adminuserprofile));
        }
예제 #3
0
        //
        // GET: /Admin/EditUser/5

        public ActionResult EditUser(int id = 0)
        {
            UserProfile Userprofile = UserManager.GetUserById(id);

            if (Userprofile == null)
            {
                return(HttpNotFound());
            }
            string[]         UserRoles        = UserManager.GetRolesByUserId(Userprofile.UserName);
            AdminUserProfile Adminuserprofile = new AdminUserProfile();

            Adminuserprofile.Roles    = UserRoles;
            Adminuserprofile.UserId   = id;
            Adminuserprofile.UserName = Userprofile.UserName;
            Adminuserprofile.Email    = Userprofile.Email;
            ViewData["RolesList"]     = Roles.GetAllRoles();
            //other vars
            return(View(Adminuserprofile));
        }
예제 #4
0
        public async Task <DatabaseResponse> UpdateAdminUser(AdminUserProfile adminuser)
        {
            try
            {
                SqlParameter[] parameters =
                {
                    new SqlParameter("@AdminID",     SqlDbType.Int),
                    new SqlParameter("@Name",        SqlDbType.NVarChar),
                    new SqlParameter("@Email",       SqlDbType.NVarChar),
                    new SqlParameter("@NewPassword", SqlDbType.NVarChar),
                    new SqlParameter("@RoleID",      SqlDbType.Int)
                };

                parameters[0].Value = adminuser.AdminUserID;
                parameters[1].Value = adminuser.Name;
                parameters[2].Value = adminuser.Email;
                parameters[3].Value = new Sha2().Hash(adminuser.NewPassword);
                parameters[4].Value = adminuser.RoleID;

                _DataHelper = new DataAccessHelper("Admin_UpdateUserProfile", parameters, _configuration);
                DataTable dt = new DataTable();

                int result = await _DataHelper.RunAsync(dt);

                return(new DatabaseResponse {
                    ResponseCode = result, Results = adminuser
                });
            }

            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                throw (ex);
            }
            finally
            {
                _DataHelper.Dispose();
            }
        }
예제 #5
0
 public ActionResult EditUser(AdminUserProfile Adminuserprofile)
 {
     if (ModelState.IsValid)
     {
         EditProfileModel EditProfileModel = new EditProfileModel();
         EditProfileModel.UserId   = Adminuserprofile.UserId;
         EditProfileModel.UserName = Adminuserprofile.UserName;
         EditProfileModel.Email    = Adminuserprofile.Email;
         if (Adminuserprofile.NewPassword != null)
         {
             EditProfileModel.NewPassword = Adminuserprofile.NewPassword;
             UserManager.EditUser(EditProfileModel);
         }
         if (Roles.GetRolesForUser(Adminuserprofile.UserName).Length != 0 && Adminuserprofile.UserName != "admin")
         {
             Roles.RemoveUserFromRoles(Adminuserprofile.UserName, Roles.GetRolesForUser(Adminuserprofile.UserName));
         }
         if (Adminuserprofile.Roles != null && Adminuserprofile.Roles.Length != 0 && Adminuserprofile.UserName != "admin")
         {
             Roles.AddUserToRoles(Adminuserprofile.UserName, Adminuserprofile.Roles);
         }
     }
     return(RedirectToAction("ManageUsers", "Admin"));
 }
예제 #6
0
        public async Task <IActionResult> UpdateAdminUser([FromHeader(Name = "Grid-Authorization-Token")] string token, [FromBody] AdminUserProfile adminuser)
        {
            try
            {
                if (string.IsNullOrEmpty(token))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = true,
                        Message = EnumExtensions.GetDescription(CommonErrors.TokenEmpty)
                    }));
                }
                AdminUsersDataAccess _adminUsersDataAccess = new AdminUsersDataAccess(_iconfiguration);

                DatabaseResponse tokenAuthResponse = await _adminUsersDataAccess.AuthenticateAdminUserToken(token);

                if (tokenAuthResponse.ResponseCode == (int)DbReturnValue.AuthSuccess)
                {
                    if (!((AuthTokenResponse)tokenAuthResponse.Results).IsExpired)
                    {
                        int _AdminUserID = ((AuthTokenResponse)tokenAuthResponse.Results).CustomerID;
                        if (!ModelState.IsValid)
                        {
                            LogInfo.Warning(StatusMessages.DomainValidationError);
                            new OperationResponse
                            {
                                HasSucceeded             = false,
                                IsDomainValidationErrors = true,
                                Message = string.Join("; ", ModelState.Values
                                                      .SelectMany(x => x.Errors)
                                                      .Select(x => x.ErrorMessage))
                            };
                        }

                        DatabaseResponse response = await _adminUsersDataAccess.UpdateAdminUser(adminuser);

                        if (response.ResponseCode == ((int)DbReturnValue.EmailNotExists))
                        {
                            return(Ok(new OperationResponse
                            {
                                HasSucceeded = false,
                                Message = EnumExtensions.GetDescription(DbReturnValue.EmailNotExists),
                                IsDomainValidationErrors = true
                            }));
                        }
                        else
                        {
                            return(Ok(new OperationResponse
                            {
                                HasSucceeded = true,
                                Message = EnumExtensions.GetDescription(DbReturnValue.CreateSuccess),
                                IsDomainValidationErrors = false,
                                ReturnedObject = response.Results
                            }));
                        }
                    }

                    else
                    {
                        //Token expired

                        LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.ExpiredToken));

                        return(Ok(new OperationResponse
                        {
                            HasSucceeded = false,
                            Message = EnumExtensions.GetDescription(DbReturnValue.TokenExpired),
                            IsDomainValidationErrors = true
                        }));
                    }
                }

                else
                {
                    // token auth failure
                    LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed));

                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = false
                    }));
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    IsDomainValidationErrors = false
                }));
            }
        }