Exemple #1
0
        public async Task <IActionResult> PostGoodsSet([FromBody] Set set)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            var goodsSet = new GoodsSet();

            goodsSet.Name = set.Name;

            _context.GoodsSets.Add(goodsSet);
            _context.SaveChanges();


            foreach (var g in set.Goods)
            {
                _context.GoodsInSets.Add(new GoodsInSet()
                {
                    IdGoods = g.Id, IdSet = goodsSet.Id, Quantity = g.Quantity
                });
            }

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGoodsSet", new { id = goodsSet.Id }, goodsSet));
        }
Exemple #2
0
        public async Task <IActionResult> PutGoodsSet([FromRoute] int id, [FromBody] GoodsSet goodsSet)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != goodsSet.Id)
            {
                return(BadRequest());
            }

            _context.Entry(goodsSet).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GoodsSetExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public GoodsSetViewModel(GoodsSet goodsSet)
 {
     Goods = goodsSet.Goods;
     Count = goodsSet.Count;
 }
Exemple #4
0
 public OrderItem(GoodsSet set)
 {
     GoodsCount = set.Count;
     GoodsId    = set.Goods.Id;
 }