public HttpResponseMessage PostItem(ShoppingListItem item) { item = repository.Add(item); var response = Request.CreateResponse <ShoppingListItem>(HttpStatusCode.Created, item); string uri = Url.Link("PostItem", new { name = item.Name }); response.Headers.Location = new Uri(uri); return(response); }
public void Add(ShoppingItemDto item) { ValidateModel(item); if (IsDrinkAlreadyAdded(item.Drink.Name)) { throw new BusinessException("The selected drink was already added to the shopping list."); } _shoppingListRepository.Add(item.Drink.Name, item.Quantity); }
public async Task <IActionResult> AddShoppingListItem([FromBody] ShoppingListItemToAddDto shoppingLitItemToAddDto) { if (shoppingLitItemToAddDto != null) { IngredientDto newIngredientDto = await _ingredientRepo.GetIngredientsFromAPI(shoppingLitItemToAddDto.SpoonacularId); string image = newIngredientDto.image; ShoppingListItem shoppingListItem = _mapper.Map <ShoppingListItem>(shoppingLitItemToAddDto); shoppingListItem.IsOnShoppingList = true; var userId = User.FindFirst(claim => claim.Type == ClaimTypes.NameIdentifier).Value; shoppingListItem.CreatedBy = int.Parse(userId); shoppingListItem.Image = image; _repo.Add <ShoppingListItem>(shoppingListItem); _repo.SaveAll(); return(StatusCode(201)); } Response.StatusCode = 400; return(Content("Naughty")); }
public ActionResult Create(ShopItemModel model) { _repository.Add(model); return(RedirectToAction(nameof(Index))); }