public ActionResult EditLodgeTypeSubmit([Bind(Include = "LodgeTypeId,Name,Surface,Description,MaxPersons,Picture, price, Disabled")] LodgeTypes model, HttpPostedFileBase upload, decimal?price) { if (ModelState.IsValid) { if (upload != null && upload.ContentLength > 0) { using var reader = new System.IO.BinaryReader(upload.InputStream); model.Picture = reader.ReadBytes(upload.ContentLength); } if (price != null) { LodgePrice oldlodgeprice = db.LodgePrice.Where(t => t.LodgeTypeId == model.LodgeTypeId && t.EndDate == null).First(); oldlodgeprice.EndDate = DateTime.Now; db.Entry(oldlodgeprice).State = EntityState.Modified; LodgePrice lodgePrice = new LodgePrice { StartingDate = DateTime.Now, price = (decimal)price, LodgeTypeId = model.LodgeTypeId }; db.LodgePrice.Add(lodgePrice); } db.Entry(model).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("LodgeType")); } return(RedirectToAction("EditLodgeType", model.LodgeTypeId)); }
public ActionResult AddLodgeTypeSubmit(LodgeTypes model, HttpPostedFileBase upload, decimal price) { if (ModelState.IsValid) { LodgeTypes lodgeTypes = new LodgeTypes { Name = model.Name, Surface = model.Surface, Description = model.Description, MaxPersons = model.MaxPersons }; if (upload != null && upload.ContentLength > 0) { using (var reader = new System.IO.BinaryReader(upload.InputStream)) { lodgeTypes.Picture = reader.ReadBytes(upload.ContentLength); } } db.LodgeTypes.Add(lodgeTypes); db.SaveChanges(); LodgePrice lodgePrice = new LodgePrice { StartingDate = DateTime.Now, price = Convert.ToDecimal(price), LodgeTypeId = (from n in db.LodgeTypes orderby n.LodgeTypeId descending select n.LodgeTypeId).First() }; db.LodgePrice.Add(lodgePrice); db.SaveChanges(); return(RedirectToAction("LodgeType")); } return(RedirectToAction("AddLodgeType")); }