예제 #1
0
 public ActionResult DeleteConfirmed(int id)
 {
     Models.Oil oil = db.Oils.Find(id);
     db.Oils.Remove(oil);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
예제 #2
0
        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));
        }
예제 #3
0
 public Models.Oil Post(Models.Oil oil)
 {
     if (!ModelState.IsValid)
     {
         throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request");
     }
     return(_oilService.Save(oil.CreateFrom()).CreateFrom());
 }
예제 #4
0
 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);
 }
예제 #5
0
 // 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);
 }
예제 #6
0
 /// <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
     });
 }
예제 #7
0
 // 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);
 }