Exemple #1
0
        public IActionResult Delete(int id)
        {
            try
            {
                Linhvuccongviec lv = db.Linhvuccongviec.Find(id);


                if (lv != null)
                {
                    if (db.Danhmuc.Where(x => x.Masolinhvuc == lv.Masolinhvuc).Count() > 0)
                    {
                        return(BadRequest());
                    }
                    else
                    {
                        db.Linhvuccongviec.Remove(lv);
                        db.SaveChanges();
                        return(Ok());
                    }
                }
                else
                {
                    return(BadRequest("Không tìm thấy id này!"));
                }
            }
            catch
            {
                throw;
            }
        }
Exemple #2
0
 public int Edit(Linhvuccongviec lv)
 {
     try
     {
         db.Entry(lv).State = EntityState.Modified;
         db.SaveChanges();
         return(1);
     }
     catch
     {
         throw;
     }
 }
Exemple #3
0
 public int Create([FromBody] Linhvuccongviec lv)
 {
     db.Linhvuccongviec.Add(lv);
     try
     {
         if (ModelState.IsValid)
         {
             db.SaveChanges();
         }
         return(1);
     }
     catch (DbUpdateException)
     {
         throw;
     }
 }