public ActionResult DeleteConfirmed(int id) { Models.Oil oil = db.Oils.Find(id); db.Oils.Remove(oil); db.SaveChanges(); return(RedirectToAction("Index")); }
public Models.Oil Post(Models.Oil oil) { if (!ModelState.IsValid) { throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request"); } if (oil.OilId > 0) { #region Update Record Models.Oil oilDbVersion = GetOilById(oil.OilId); oilDbVersion.OilName = oil.OilName; oilDbVersion.OilMakerId = oil.OilMakerId; oilDbVersion.OilAverageMilage = oil.OilAverageMilage; oilDbVersion.OilPower = oil.OilPower; oilDbVersion.OilPrice = oil.OilPrice; oilDbVersion.OilDescription = oil.OilDescription; oilDbVersion.OilNetWeightId = oil.OilNetWeightId; DbSet.AddOrUpdate(oilDbVersion); db.SaveChanges(); #endregion } else { #region Add New Record DbSet.Add(oil); db.SaveChanges(); #endregion } return(GetOilById(oil.OilId)); }
public Models.Oil Post(Models.Oil oil) { if (!ModelState.IsValid) { throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request"); } return(_oilService.Save(oil.CreateFrom()).CreateFrom()); }
public ActionResult Edit([Bind(Include = "OilId,OilName,OilMakerId,OilAverageMilage,OilPower,OilPrice,OilDescription,OilNetWeightId")] Models.Oil oil) { if (ModelState.IsValid) { db.Entry(oil).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.OilMakerId = new SelectList(db.OilMakerCompanies, "OilMakerId", "OilMakerName", oil.OilMakerId); //return View(oil); return(null); }
// GET: /Api/test/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.Oil oil = db.Oils.Find(id); if (oil == null) { return(HttpNotFound()); } //return View(oil); return(null); }
/// <summary> /// Create entity from web model /// </summary> public static MainDomain.Oil CreateFrom(this Models.Oil source) { return(new MainDomain.Oil { OilId = source.OilId, OilAverageMilage = source.OilAverageMilage, OilDescription = source.OilDescription, OilMakerId = source.OilMakerId, OilName = source.OilName, OilNetWeightId = source.OilNetWeightId, OilPower = source.OilPower, OilPrice = source.OilPrice }); }
// GET: /Api/test/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.Oil oil = db.Oils.Find(id); if (oil == null) { return(HttpNotFound()); } ViewBag.OilMakerId = new SelectList(db.OilMakerCompanies, "OilMakerId", "OilMakerName", oil.OilMakerId); //return View(oil); return(null); }