Exemplo n.º 1
0
        public async Task <ActionResult <Voucher> > Excute()
        {
            AssigndataUtils AssigndataUtils = new AssigndataUtils();

            Voucher newVoucher = AssigndataUtils.AssignVoucher(voucherDTO, 0);

            var _context = new TGDDContext();

            _context.Vouchers.Add(newVoucher);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                bool voucherExist = _context.Vouchers.Any(voucher => voucher.Id == newVoucher.Id);

                if (voucherExist)
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }
            return(CreatedAtAction("GetVoucher", new { id = newVoucher.Id }, newVoucher));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Excute()
        {
            AssigndataUtils AssigndataUtils = new AssigndataUtils();
            var             _context        = new TGDDContext();

            Voucher voucherUpdate = AssigndataUtils.AssignVoucher(voucherDTO, voucherDTO.Id);

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                bool voucherExist = _context.Vouchers.Any(voucher => voucher.Id == voucherUpdate.Id);
                if (!voucherExist)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok("Update Voucher thành công !"));
        }