public async Task <ActionResult <UserViewModel> > Create(UserViewModel loginViewModel) { if (ModelState.IsValid) { if (await db.Users.AnyAsync(x => x.Email == loginViewModel.Login)) { return(BadRequest("Такой пользователь уже существует")); } logger.LogInformation($"Create user {loginViewModel.Login}:{loginViewModel.Password}"); var role = db.Roles.FirstOrDefault(x => x.Name == loginViewModel.Role); var lang = db.Languages.First(); var newUser = new User { Id = 0, Email = loginViewModel.Login, Nickname = loginViewModel.Login, Role = role, Language = lang, LanguageId = lang.Id, RoleId = role.Id, PasswordHash = CryptService.CreateHash(loginViewModel.Password) }; db.Add(newUser); db.SaveChanges(); return(Ok()); } return(loginViewModel); }
public ActionResult <UserModel> UpdateLanguage([FromBody] ChangeLanguageModel changeLanguageModel, [FromHeader] string authorization) { var parts = authorization.Split(" "); var user = userService.GetUser(parts[1]); user.Language = authDataProvider.Languages.FirstOrDefault(x => x.Code == changeLanguageModel.Language); authDataProvider.Update(user); authDataProvider.SaveChanges(); return(mapperService.Map <UserModel>(user)); }