Exemple #1
0
        public async Task <IActionResult> PutThanhPhanMonAn(int id, ThanhPhanMonAn thanhPhanMonAn)
        {
            if (id != thanhPhanMonAn.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemple #2
0
        public async Task <ActionResult <ThanhPhanMonAn> > PostThanhPhanMonAn(ThanhPhanMonAn thanhPhanMonAn)
        {
            var tp = await _context.ThanhPhanMonAns.Where(x => x.MonAn_ID == thanhPhanMonAn.MonAn_ID && x.NguyenLieu_ID == thanhPhanMonAn.NguyenLieu_ID).FirstOrDefaultAsync();

            if (tp == null)
            {
                _context.ThanhPhanMonAns.Add(thanhPhanMonAn);
            }
            else
            {
                tp.soluong = thanhPhanMonAn.soluong;
                _context.ThanhPhanMonAns.Update(tp);
            }
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetThanhPhanMonAn", new { id = thanhPhanMonAn.Id }, thanhPhanMonAn));
        }