public ActionResult AddOrEdit(VT_GetTruckInFo_Result con) { if (con.ID == 0) { Truck truck = new Truck(); truck.DriverID = con.DriverID; truck.TruckNo = con.TruckNo; truck.Status = con.Status; truck.TrailerID = con.TrailerID; truck.Expire = con.Expire; truck.Transit = con.Transit; truck.OwnRent = con.OwnRent; db.Trucks.Add(truck); db.SaveChanges(); return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet)); } else { Truck truck = db.Trucks.Where(c => c.ID == con.ID).FirstOrDefault(); truck.DriverID = con.DriverID; truck.TruckNo = con.TruckNo; truck.Status = con.Status; truck.TrailerID = con.TrailerID; truck.Expire = con.Expire; truck.Transit = con.Transit; truck.OwnRent = con.OwnRent; db.Entry(truck).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult AddOrEdit(int id = 0) { if (id == 0) { return(View(new VT_GetTruckInFo_Result())); } else { VT_GetTruckInFo_Result result = db.VT_GetTruckInFo(id).FirstOrDefault(); return(View(result)); } }