示例#1
0
        public async Task <IActionResult> GuaranteeFormItemEdit(int id, [FromBody] GuaranteeFormItem guaranteeFormItem)
        {
            if (id != guaranteeFormItem.Id)
            {
                Console.WriteLine("Không đúng định dạng");
                return(BadRequest());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(guaranteeFormItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GuaranteeFormItemExists(guaranteeFormItem.Id))
                    {
                        Console.WriteLine("Id không tồn tại");
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(Ok(guaranteeFormItem));
        }
示例#2
0
 public IActionResult GuaranteeFormItemCreate([FromBody] GuaranteeFormItem guaranteeFormItem)
 {
     try
     {
         GuaranteeFormItem test = new GuaranteeFormItem();
         test = guaranteeFormItem;
         if (ModelState.IsValid)
         {
             _context.Add(test);
             _context.SaveChangesAsync();
             return(Ok(test));
         }
         else
         {
             Console.WriteLine("Không đúng định dạng");
             return(BadRequest());
         }
     }
     catch (ArgumentException err)
     {
         Console.WriteLine("Không đúng định dạng", err);
         return(NotFound());
     }
 }