示例#1
0
        public async Task <IActionResult> PostSaleproGoodPattn([FromBody] SaleproGoodPattn saleproGoodPattn)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var getGoodPattn = await _context.GetTransactionInv
                               .Where(w => w.GoodPattnCode == saleproGoodPattn.GoodPattnCode)
                               .GroupBy(g => new { g.GoodPattnName })
                               .Select(s => new { s.Key.GoodPattnName })
                               .ToListAsync();

            var getGoodClass = await _context.GetTransactionInv
                               .Where(w => w.GoodClassCode == saleproGoodPattn.GoodClassCode)
                               .GroupBy(g => new { g.GoodClassName })
                               .Select(s => new { s.Key.GoodClassName })
                               .ToListAsync();

            var getSubCodePro = await _context.CodePromotion
                                .Where(w => w.SubId == saleproGoodPattn.SubId)
                                .GroupBy(g => new { g.SubCodePro })
                                .Select(s => new { s.Key.SubCodePro })
                                .ToListAsync();

            saleproGoodPattn.GoodPattnName = getGoodPattn[0].GoodPattnName;
            saleproGoodPattn.GoodClassName = getGoodClass[0].GoodClassName;
            saleproGoodPattn.SubCodePro    = getSubCodePro[0].SubCodePro;

            _context.SaleproGoodPattn.Add(saleproGoodPattn);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSaleproGoodPattn", new { id = saleproGoodPattn.Id }, saleproGoodPattn));
        }
示例#2
0
        public async Task <IActionResult> PutSaleproGoodPattn([FromRoute] int id, [FromBody] SaleproGoodPattn saleproGoodPattn)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            var getGoodPattn = await _context.GetTransactionInv
                               .Where(w => w.GoodPattnCode == saleproGoodPattn.GoodPattnCode)
                               .GroupBy(g => new { g.GoodPattnName })
                               .Select(s => new { s.Key.GoodPattnName })
                               .ToListAsync();

            var getGoodClass = await _context.GetTransactionInv
                               .Where(w => w.GoodClassCode == saleproGoodPattn.GoodClassCode)
                               .GroupBy(g => new { g.GoodClassName })
                               .Select(s => new { s.Key.GoodClassName })
                               .ToListAsync();

            var getSubCodePro = await _context.CodePromotion
                                .Where(w => w.SubId == saleproGoodPattn.SubId)
                                .GroupBy(g => new { g.SubCodePro })
                                .Select(s => new { s.Key.SubCodePro })
                                .ToListAsync();

            saleproGoodPattn.GoodPattnName = getGoodPattn[0].GoodPattnName;
            saleproGoodPattn.GoodClassName = getGoodClass[0].GoodClassName;
            saleproGoodPattn.SubCodePro    = getSubCodePro[0].SubCodePro;

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

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

            return(NoContent());
        }