Example #1
0
        public ActionResult Edit(int id, [Bind("ID", "Name", "Gender")] User user)
        {
            try
            {
                var errorMessage = GetErrorIfInvalid(user);

                if (!string.IsNullOrWhiteSpace(errorMessage))
                {
                    return(RedirectToAction("Index", "Error", new { error = errorMessage }));
                }

                User userToEdit = _userBl.GetById(user.ID);

                if (userToEdit == null)
                {
                    return(RedirectToAction("Index", "Error", new { error = string.Format("Could not find user with id {0}", id) }));
                }

                userToEdit.Name   = user.Name;
                userToEdit.Gender = user.Gender;

                _userBl.UpdateUser(userToEdit);

                return(RedirectToAction("Details", "User"));
            }
            catch
            {
                return(RedirectToAction("Index", "Error"));
            }
        }
Example #2
0
        private void UpdateDriver(int driverId, DriverStatusEnum status)
        {
            //if (request.DriverId == null)
            //    return;

            var    operatorBL = HttpContext.Current.Application.GetContainer().Resolve <OperatorBl>();
            var    driver     = operatorBL.GetUserById(driverId);
            UserBl userBL     = HttpContext.Current.Application.GetContainer().Resolve <UserBl>();

            driver.DriverStatus = (int)status;

            userBL.UpdateUser(driver);
            driversDropDownList.DataBind();
        }
Example #3
0
        public ActionResult Edit(string username, [Bind("Gender", "UserName", "Email, IsAdmin")] User user)
        {
            if (!IsAdminConnected())
            {
                return(RedirectToAction("Index", "Error", new { error = "You must be an admin to edit." }));
            }

            try
            {
                var errorMessage = GetErrorIfInvalid(user, false);

                if (!string.IsNullOrWhiteSpace(errorMessage))
                {
                    return(RedirectToAction("Index", "Error", new { error = errorMessage }));
                }

                User userToEdit = _userBl.GetById(username);

                if (userToEdit == null)
                {
                    return(RedirectToAction("Index", "Error", new { error = string.Format("Could not find user with username {0}", username) }));
                }

                // in case of last admin make himself not admin
                if (_userBl.GetHowManyAdmins() == 1 && HttpContext.Session.GetString("ConnectedUserId") == user.UserName && user.IsAdmin == false)
                {
                    user.IsAdmin = true;
                }

                userToEdit.Gender   = user.Gender;
                userToEdit.UserName = user.UserName;
                userToEdit.Email    = user.Email;
                userToEdit.IsAdmin  = user.IsAdmin;

                _userBl.UpdateUser(userToEdit);

                return(RedirectToAction("Details", "User"));
            }
            catch
            {
                return(RedirectToAction("Index", "Error"));
            }
        }
Example #4
0
 public HttpResponseMessage Post(UserInfo user)
 {
     return(UserBl.UpdateUser(user));
 }
Example #5
0
 public bool UpdateUser(User user)
 {
     return(_userBl.UpdateUser(user));
 }