public ActionResult Create(PlateCreateViewModel model) { if (ModelState.IsValid) { foreach (var file in model.files) { var dateTaken = Utils.GetDateTaken(file.InputStream); var plateId = Guid.NewGuid(); var fileName = fileUploadService.UploadFile(file, plateId.ToString() + Path.GetExtension(file.FileName)); var plate = new Plate() { HasPicture = model.files.Count() > 0, Extension = Path.GetExtension(fileName), Id = plateId, TimeEaten = dateTaken, Title = model.Title, UserId = Guid.Parse(User.Identity.GetUserId()) }; db.Plates.Add(plate); db.SaveChanges(); } return(RedirectToAction("Index")); } return(View(model)); }
public IHttpActionResult PostPlate(PlateCreateViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Plates.Add(plate); try { db.SaveChanges(); } catch (DbUpdateException) { if (PlateExists(plate.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = plate.Id }, plate)); }