public async Task <IActionResult> Login(LoginViewModel model) { ImageUser avatar; if (ModelState.IsValid) { var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false); if (result.Succeeded) { var currentUser = await _userManager.FindByNameAsync(model.Email); // проверяем, принадлежит ли URL приложению if (!string.IsNullOrEmpty(model.ReturnUrl) && Url.IsLocalUrl(model.ReturnUrl)) { return(Redirect(model.ReturnUrl)); } else { if (currentUser.UserStatus == "admin") { avatar = new ImageUser { ImageAddress = "admin" }; _context.Add(avatar); _context.SaveChanges(); return(RedirectToAction("Index", "Users")); } else if (currentUser.UserStatus == "user") { avatar = new ImageUser { ImageAddress = "user" }; _context.Add(avatar); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Неправильный логин и (или) пароль"); } } return(View(model)); }
public async Task <IServiceResult> PostImageUser([FromBody] ImageUser imageUser) { try { _context.ImageUsers.Add(imageUser); if (!await _unitOfWork.CompleteAsync()) { throw new SaveFailedException(nameof(imageUser)); } _logger.LogInformation($"Image {imageUser.Id} created."); return(new ServiceResult(payload: imageUser.UrlOnline)); } catch (Exception e) { _logger.LogError($"Can't create a image of game {imageUser.Id}. {e.Message}"); return(new ServiceResult(false, message: e.Message)); } }