Ejemplo n.º 1
0
        public void Add_Valid_Test()
        {
            var model = new TypesCreateModel()
            {
                Description = "Tirowe"
            };

            try
            {
                _typesService.Add(model);
            }
            catch
            {
                Assert.Fail();

                return;
            }

            Assert.IsTrue(_applicationDbContext.Types.Any(t => t.Description.CompareTo(model.Description) == 0));
        }
Ejemplo n.º 2
0
        public ActionResult Create(TypesCreateModel createModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(createModel));
            }

            try
            {
                _typesService.Add(createModel);
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeResult(500, e.Message));
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
 public IActionResult OnPost()
 {
     if (ModelState.IsValid)
     {
         type.RecipeId = recipe.id;
         try
         {
             typeMain = _typesService.GetByName(typeName);
         }
         catch (InvalidOperationException)
         {
             _typesService.Add(new TypeDTO {
                 Name = typeName
             });
             typeMain = _typesService.GetByName(typeName);
         }
         type.TypeId = typeMain.id;
         _service.Add(type);
         return(Redirect(Url.Page("/Recipe_ingredient", new { id = recipe.id, login = user.Login })));
     }
     return(Page());
 }