Exemplo n.º 1
0
        public async Task <ShoppingListItemModel> Post([FromBody] ShoppingListItemModel value)
        {
            var shoppingList = await _context.ShoppingList.SingleOrDefaultAsync(m => m.Id == value.Id);

            if (shoppingList != null)
            {
                shoppingList.Item       = value.Item;
                shoppingList.Quantity   = value.Quantity;
                shoppingList.CategoryId = value.Category.Id;

                _context.Update(shoppingList);
                await _context.SaveChangesAsync();
            }
            else
            {
                shoppingList = new ShoppingListItem()
                {
                    Item       = value.Item,
                    Quantity   = value.Quantity,
                    CategoryId = value.Category.Id,
                    WeekId     = 1
                };

                _context.Add(shoppingList);

                await _context.SaveChangesAsync();
            }

            var category = await _context.Category.SingleAsync(u => u.Id == shoppingList.CategoryId);

            return(Map(shoppingList, category));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,ListName,CreatingDate,Price,UserId")] ShopList shopList)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shopList);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(shopList));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Quantity,Price,AmountProduct")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("iD,name")] Items items)
        {
            if (ModelState.IsValid)
            {
                _context.Add(items);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(items));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,Name,Price,ShelfId,Warranty")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ShelfId"] = new SelectList(_context.Shelfs, "Id", "Id", product.ShelfId);
            return(View(product));
        }