public async Task <ActionResult> deleteDepartament(CountryDepartametsModel departamentModel) { try { var departament = _context.CountryDepartaments.FirstOrDefault(x => x.id == departamentModel.id); _context.CountryDepartaments.Remove(departament); await _context.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { Console.WriteLine("an error ocurred" + ex.ToString()); return(BadRequest()); } }
public async Task <ActionResult <CountryDepartametsModel> > newDepartament(CountryDepartametsModel departamentModel) { try { departamentModel.date_created = DateTime.Now; _context.CountryDepartaments.Add(departamentModel); await _context.SaveChangesAsync(); return(CreatedAtAction("GetModelDepartament", new { id = departamentModel.id }, departamentModel)); } catch (Exception ex) { Console.WriteLine("an error ocurred" + ex.ToString()); return(BadRequest(ex)); } }
public async Task <ActionResult <CountryModel> > updateDepartament(CountryDepartametsModel departamentModel) { try { var departament = _context.CountryDepartaments.FirstOrDefault(x => x.id == departamentModel.id); departament.name = departamentModel.name; departament.code = departamentModel.code; await _context.SaveChangesAsync(); return(CreatedAtAction("GetModelDepartament", new { id = departamentModel.id }, departamentModel)); } catch (Exception ex) { Console.WriteLine("an error ocurred" + ex.ToString()); return(BadRequest()); } }