public IActionResult UserNew([FromServices] IProxyServiceCallingWebApi proxyServiceCallingWeb, UserEdit user)
        {
            if (ModelState.IsValid)
            {
                User userToSave = new User
                {
                    Id         = user.Id,
                    Login      = user.Login,
                    Password   = user.Password,
                    FirstName  = user.FirstName,
                    MiddleName = user.MiddleName,
                    LastName   = user.LastName,
                    IsAdmin    = user.IsAdmin,
                    Telephone  = user.Telephone
                };
                var result = proxyServiceCallingWeb.NewUser(userToSave);

                if (result == HttpStatusCode.OK)
                {
                    return(RedirectToAction("ShowUsers", "UserGrid"));
                }

                ModelState.AddModelError("Ошибка", "Ошибка сохранения атрибутов пользователя.");
            }
            return(View(user));
        }
예제 #2
0
        public IActionResult OnPost([FromServices] IProxyServiceCallingWebApi proxyServiceCallingWeb)
        {
            if (ModelState.IsValid)
            {
                var strError = proxyServiceCallingWeb.ExistLogin(Person.Login, 0);
                if (!string.IsNullOrEmpty(strError))
                {
                    ModelState.AddModelError("Person.Login", strError);
                }
                else
                {
                    User userToSave = new User
                    {
                        Id         = Person.Id,
                        Login      = Person.Login,
                        Password   = Person.Password,
                        FirstName  = Person.FirstName,
                        MiddleName = Person.MiddleName,
                        LastName   = Person.LastName,
                        IsAdmin    = Person.IsAdmin,
                        Telephone  = Person.Telephone
                    };

                    if (userToSave.Password == null)
                    {
                        userToSave.Password = string.Empty;
                    }

                    var result = proxyServiceCallingWeb.NewUser(userToSave);

                    if (result == HttpStatusCode.OK)
                    {
                        var url = Url.Page("AllUsers");
                        return(Redirect(url));
                    }
                }
            }
            return(Page());
        }