Exemple #1
0
        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));
        }
Exemple #3
0
        public NewGuideForm CreateNewGuideForm()
        {
            NewGuideForm addGuide = new NewGuideForm();

            return(addGuide);
        }