public ActionResult DeleteConfirmed(int id) { BikeMakeID bikeMakeID = db.BikeMakeIDs.Find(id); db.BikeMakeIDs.Remove(bikeMakeID); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "BikeMakeID1,Manufacturer,City,State")] BikeMakeID bikeMakeID) { if (ModelState.IsValid) { db.Entry(bikeMakeID).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bikeMakeID)); }
public ActionResult Create([Bind(Include = "BikeMakeID1,Manufacturer,City,State")] BikeMakeID bikeMakeID) { if (ModelState.IsValid) { db.BikeMakeIDs.Add(bikeMakeID); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bikeMakeID)); }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BikeMakeID bikeMakeID = db.BikeMakeIDs.Find(id); if (bikeMakeID == null) { return(HttpNotFound()); } return(View(bikeMakeID)); }
public ActionResult Create([Bind(Include = "BikeID,BikeModel,BikeTypeID,Price,UnitsSold,Year,BikeImage,Description,TireID,BikeStatusID,BikeMakeID,IsSiteFeature")] Bike bike, HttpPostedFileBase bikeImage, string BikeMake) { bike.BikeMakeID = 0; // we are defaulting it to a value to check validity if (ModelState.IsValid) { #region Bike Make or Manufacturer Info //query bikemakeid table to see if that make already exists on the table BikeMakeID record = db.BikeMakeIDs.Where(x => x.Manufacturer == BikeMake).FirstOrDefault(); //if this query gets nothing back then we need to add something if (record != null) { bike.BikeMakeID = record.BikeMakeID1; } else { BikeMakeID newRecord = new BikeMakeID(); newRecord.Manufacturer = BikeMake; db.BikeMakeIDs.Add(newRecord); db.SaveChanges(); bike.BikeMakeID = newRecord.BikeMakeID1; } #endregion #region file upload string file = "NoImage.png"; if (bikeImage != null) { file = bikeImage.FileName; string ext = file.Substring(file.LastIndexOf('.')); string[] goodExts = { ".jpeg", ".jpg", ".png", ".gif" }; if (goodExts.Contains(ext)) { if (bikeImage.ContentLength <= 4194304) { file = Guid.NewGuid() + ext; #region resize image string savePath = Server.MapPath("~/Content/imgstore/bikes/"); Image convertedImage = Image.FromStream(bikeImage.InputStream); int maxImageSize = 500; int maxThumbSize = 100; ImageService.ResizeImage(savePath, file, convertedImage, maxImageSize, maxThumbSize); #endregion } } } bike.BikeImage = file; #endregion db.Bikes.Add(bike); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BikeMakeID = new SelectList(db.BikeMakeIDs, "BikeMakeID1", "Manufacturer", bike.BikeMakeID); ViewBag.BikeStatusID = new SelectList(db.BikeStatuses, "BikeStatusID", "BikeStatusName", bike.BikeStatusID); ViewBag.BikeTypeID = new SelectList(db.BikeTypes, "BikeTypeID", "BikeType1", bike.BikeTypeID); ViewBag.TireID = new SelectList(db.TireTypes, "TireID", "Tubeless", bike.TireID); return(View(bike)); }