public ActionResult Create([Bind(Include = "DestinationId,Name,Location,Description,Photo,RegionId")] Destination destination) { if (ModelState.IsValid) { if (Request != null) { // upload album cover if there is one if (Request.Files.Count > 0) { var file = Request.Files[0]; if (file.FileName != null && file.ContentLength > 0) { // get file path dynamically string path = Server.MapPath("~/Content/Images/") + file.FileName; file.SaveAs(path); destination.Photo = file.FileName; } } } db.Destinations.Add(destination); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(destination)); }
public IHttpActionResult PutRegion(int id, Region region) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != region.RegionId) { return(BadRequest()); } db.Entry(region).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RegionExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }