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

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(guaranteeForm);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GuaranteeFormExists(guaranteeForm.Id))
                    {
                        Console.WriteLine("Id không tồn tại");
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(Ok(guaranteeForm));
        }
Example #2
0
 public IActionResult GuaranteeFormCreate([FromBody] GuaranteeForm guaranteeForm)
 {
     try
     {
         GuaranteeForm test = new GuaranteeForm();
         test = guaranteeForm;
         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());
     }
 }