Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }