public IngredientServiceTests()
 {
     this.service = new IngredientService();
     service.Add(new Ingredient { Name = "Sugar" }
         );
     service.Add(new Ingredient { Name = "Milk" }
         );
 }
 public IngredientServiceTests()
 {
     this.service = new IngredientService();
     service.Add(new Ingredient {
         Name = "Sugar"
     }
                 );
     service.Add(new Ingredient {
         Name = "Milk"
     }
                 );
 }
        public void Create(IngredientViewModel model)
        {
            var ingredient = _mapper
                             .Map <IngredientDto>(model);

            _service.Add(ingredient);
        }
Exemplo n.º 4
0
        public IActionResult Add(Ingredients ingredient)
        {
            var result = _ingredientService.Add(ingredient);

            if (!result.IsSuccess)
            {
                return(BadRequest(result));
            }
            return(Ok(result));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Post([FromBody] Ingredient ingredient)
        {
            if (string.IsNullOrWhiteSpace(ingredient.Name))
            {
                return(BadRequest());
            }

            await _service.Add(ingredient);

            return(Ok(ingredient));
        }
        public void AddTest()
        {
            var name          = Guid.NewGuid().ToString();
            var newIngredient = new Ingredient
            {
                Name = name
            };
            var AddedIngredient = service.Add(newIngredient);

            Assert.IsNotNull(AddedIngredient);
            Assert.IsTrue(AddedIngredient.Id > 0);
            Assert.AreEqual(AddedIngredient.Name, name);
        }
Exemplo n.º 7
0
        public virtual HttpResponseMessage Post(CreateIngredient createIngredient)
        {
            Ingredient ingredient = AutoMapper.Map <CreateIngredient, Ingredient>(createIngredient);

            ingredientService.Add(ingredient);

            Ingredient    createdIngredient    = ingredientService.Get(ingredient.Id);
            IngredientDto createdIngredientDto = AutoMapper.Map <Ingredient, IngredientDto>(createdIngredient);

            createdIngredientDto.Unit = unitService.Get(ingredient.UnitId);

            return(Request.CreateResponse(HttpStatusCode.Created, createdIngredientDto));
        }
Exemplo n.º 8
0
 public IActionResult Post([FromBody] IngredientModel ingredientModel)
 {
     try
     {
         var savedIngredient = _ingredientService.Add(ingredientModel.ToDomainModel());
         return(CreatedAtAction("Get", new { Id = savedIngredient.Id }, savedIngredient.ToApiModel()));
     }
     catch (System.Exception ex)
     {
         ModelState.AddModelError("AddIngredient", ex.Message);
         return(BadRequest(ModelState));
     }
 }
        public IActionResult Post([FromBody] IngredientModel ingredientModel)
        {
            try
            {
                // add the new book
                _ingredientService.Add(ingredientModel.ToDomainModel());
            }
            catch (System.Exception ex)
            {
                ModelState.AddModelError("AddIngredient", ex.GetBaseException().Message);
                return(BadRequest(ModelState));
            }

            return(CreatedAtAction("Get", new { Id = ingredientModel.Id }, ingredientModel));
        }
Exemplo n.º 10
0
        public IHttpActionResult PostIngredientToMaster(IngredientModel ingredientModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var ingredient = new Ingredient();

            ObjectFactory.Parse(ingredientModel, ingredient);

            _ingredientService.Add(ingredient);

            db.SaveChanges();

            var newIngredientModel = ModelFactory.Create(ingredient);

            return(Ok(newIngredientModel));
        }
        public async Task <IActionResult> Create(IngredientDto ingredientIngredientDto)
        {
            if (await _ingredientService.CheckExists(ingredientIngredientDto.ID))
            {
                return(BadRequest("Ingredient ID already exists!"));
            }
            if (await _ingredientService.CheckBarCodeExists(ingredientIngredientDto.Code))
            {
                return(BadRequest("Ingredient Barcode already exists!"));
            }
            ////var username = User.FindFirst(ClaimTypes.Name).Value;
            // //ingredientIngredientDto.Updated_By = username;
            ingredientIngredientDto.CreatedDate = DateTime.Now.ToString("MMMM dd, yyyy HH:mm:ss tt");
            if (await _ingredientService.Add(ingredientIngredientDto))
            {
                return(NoContent());
            }

            throw new Exception("Creating the brand failed on save");
        }
Exemplo n.º 12
0
 public async Task <IActionResult> Create(IngredientDto ingredientIngredientDto)
 {
     if (await _ingredientService.CheckExists(ingredientIngredientDto.ID))
     {
         return(BadRequest("Ingredient ID already exists!"));
     }
     if (await _ingredientService.CheckBarCodeExists(ingredientIngredientDto.MaterialNO))
     {
         return(BadRequest("Ingredient Material# already exists!"));
     }
     if (await _ingredientService.CheckExistsName(ingredientIngredientDto.Name))
     {
         return(BadRequest("Ingredient Name already exists!"));
     }
     ingredientIngredientDto.CreatedDate = DateTime.Now.ToString("MMMM dd, yyyy HH:mm:ss tt");
     if (await _ingredientService.Add(ingredientIngredientDto))
     {
         return(NoContent());
     }
     throw new Exception("Creating the brand failed on save");
 }
Exemplo n.º 13
0
 public IActionResult OnPost()
 {
     if (ModelState.IsValid)
     {
         ingredient.RecipeId = recipe.id;
         try
         {
             ingredientMain = _ingredientService.GetByName(ingredientName);
         }
         catch (InvalidOperationException)
         {
             _ingredientService.Add(new IngredientDTO {
                 id = Guid.NewGuid(), Name = ingredientName
             });
             ingredientMain = _ingredientService.GetByName(ingredientName);
         }
         ingredient.IngredientId = ingredientMain.id;
         _service.Add(ingredient);
         return(Redirect(Url.Page("/Recipe_ingredient", new { id = recipe.id, login = user.Login })));
     }
     return(Page());
 }
Exemplo n.º 14
0
 public async Task <(string, bool, IngredientModel model)> Add(IngredientModel model)
 {
     return(await _ingredientService.Add(model));
 }
Exemplo n.º 15
0
 private void Validate()
 {
     _IngredientService.Add(new Ingredient(IngredientName, Type));
     NavigationService.NavigateAsync("NavigationPage/RestaurantMenu");
 }
Exemplo n.º 16
0
        public async Task <IActionResult> Add([FromBody] CreateIngredientModel model)
        {
            var result = await _ingredientService.Add(model);

            return(Created(result.Id.ToString(), null));
        }