public IActionResult Delete(int Id) { Response <object> oResponse = new Response <object>(); try { using (blazorcrudContext db = new blazorcrudContext()) { Cattle oCattle = db.Cattle.Find(Id); db.Remove(oCattle); db.SaveChanges(); oResponse.Success = 1; } } catch (Exception ex) { oResponse.Message = ex.Message; throw; } return(Ok(oResponse)); }
public IActionResult Edit(CattleRequest model) { Response <object> oResponse = new Response <object>(); try { using (blazorcrudContext db = new blazorcrudContext()) { Cattle oCattle = db.Cattle.Find(model.Id); oCattle.Breed = model.Breed; oCattle.Name = model.Name; db.Entry(oCattle).State = Microsoft.EntityFrameworkCore.EntityState.Modified; db.SaveChanges(); oResponse.Success = 1; } } catch (Exception ex) { oResponse.Message = ex.Message; throw; } return(Ok(oResponse)); }
public IActionResult Add(CattleRequest model) { Response <object> oResponse = new Response <object>(); try { using (blazorcrudContext db = new blazorcrudContext()) { Cattle oCattle = new Cattle(); oCattle.Breed = model.Breed; oCattle.Name = model.Name; db.Cattle.Add(oCattle); db.SaveChanges(); oResponse.Success = 1; } } catch (Exception ex) { oResponse.Message = ex.Message; throw; } return(Ok(oResponse)); }