public async Task <Guide> SaveNewGuideModel(NewGuideForm addGuide) { Guide guide = await db.Guides.FirstOrDefaultAsync(u => u.Login == addGuide.Login); if (guide == null) { // добавляем пользователя в бд db.Guides.Add(new Guide { Name = addGuide.Name, Login = addGuide.Login, Password = addGuide.Password }); await db.SaveChangesAsync(); } return(guide); }
public async Task <IActionResult> AddGuide(NewGuideForm addGuide) { if (ModelState.IsValid) { var result = await _guideService.SaveNewGuideModel(addGuide); if (result == null) { string message = "Save of new guide form"; var logger = _loggerCreator.FactoryMethod(); logger.LoggMessage(this.GetType().Name, message); return(RedirectToAction("GuideNavigation", "Guide")); } else { ModelState.AddModelError("Login", "Login is already exist"); } } return(View(addGuide)); }
public NewGuideForm CreateNewGuideForm() { NewGuideForm addGuide = new NewGuideForm(); return(addGuide); }