public static string AddOrEdit(Proizvod proiz)
 {
     using (ZadatakDBEntities db = new ZadatakDBEntities())
     {
         try
         {
             if (proiz.id == 0)
             {
                 db.Proizvods.Add(proiz);
                 db.SaveChanges();
                 return("Saved Successfully");
             }
             else
             {
                 db.Entry(proiz).State = EntityState.Modified;
                 db.SaveChanges();
                 return("Updated Successfully");
             }
         }
         catch (Exception ex)
         {
             return(ex.Message);
         }
     }
 }
Example #2
0
 public ActionResult AddOrEdit(Proizvod proiz)
 {
     using (ZadatakDBEntities db = new ZadatakDBEntities())
     {
         if (proiz.id == 0)
         {
             db.Proizvods.Add(proiz);
             db.SaveChanges();
             return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             db.Entry(proiz).State = EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
Example #3
0
 public ActionResult Delete(int id)
 {
     using (ZadatakDBEntities db = new ZadatakDBEntities())
     {
         Proizvod proiz = db.Proizvods.Where(x => x.id == id).FirstOrDefault();
         db.Proizvods.Remove(proiz);
         db.SaveChanges();
         return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
     }
 }
 public static string Delete(int id)
 {
     using (ZadatakDBEntities db = new ZadatakDBEntities())
     {
         try
         {
             Proizvod proiz = db.Proizvods.Where(x => x.id == id).FirstOrDefault();
             db.Proizvods.Remove(proiz);
             db.SaveChanges();
             return("Deleted Successfully");
         }
         catch (Exception ex)
         {
             return(ex.Message);
         }
     }
 }