Ejemplo n.º 1
0
        public async Task <IActionResult> PostSaleproFrpcostRf([FromBody] SaleproFrpcostRf saleproFrpcostRf)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var getProduct = await _context.GetTransactionInv
                             .Where(w => w.ProductCode == saleproFrpcostRf.GoodCateCode)
                             .GroupBy(g => new { g.Product })
                             .Select(s => new { s.Key.Product })
                             .ToListAsync();

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

            saleproFrpcostRf.GoodCateName = getProduct[0].Product;
            saleproFrpcostRf.SubCodePro   = getSubCodePro[0].SubCodePro;

            _context.SaleproFrpcostRf.Add(saleproFrpcostRf);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSaleproFrpcostRf", new { id = saleproFrpcostRf.Id }, saleproFrpcostRf));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutSaleproFrpcostRf([FromRoute] int id, [FromBody] SaleproFrpcostRf saleproFrpcostRf)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            var getProduct = await _context.GetTransactionInv
                             .Where(w => w.ProductCode == saleproFrpcostRf.GoodCateCode)
                             .GroupBy(g => new { g.Product })
                             .Select(s => new { s.Key.Product })
                             .ToListAsync();

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

            saleproFrpcostRf.GoodCateName = getProduct[0].Product;
            saleproFrpcostRf.SubCodePro   = getSubCodePro[0].SubCodePro;

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

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

            return(NoContent());
        }