Пример #1
0
        public async Task <IActionResult> PutEmployee([FromRoute] int id, [FromBody] Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employee.employeeId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PostBill([FromBody] BillPost billpost)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var bill = new Bill
            {
                customerName = billpost.customerName,
                total        = billpost.total
            };

            bill.BillItems = new List <BillItem>();

            foreach (int it in billpost.itemIds)
            {
                bill.BillItems.Add(new BillItem {
                    ItemId = it,
                    BillId = bill.billId
                });
            }


            _context.Bills.Add(bill);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBill", new { id = bill.billId }, bill));
        }