public ActionResult Create(DevelopmentProjectViewModel model) { var validImageTypes = new string[] { "image/gif", "image/jpeg", "image/pjpeg", "image/png" }; if (model.ProjectThumbnailUpload == null || model.ProjectThumbnailUpload.ContentLength == 0) { ModelState.AddModelError("ThumbnailUpload", "This field is required"); } else if (!validImageTypes.Contains(model.ProjectThumbnailUpload.ContentType)) { ModelState.AddModelError("ThumbnailUpload", "Please choose either a GIF, JPG or PNG image."); } if (ModelState.IsValid) { var developmentProject = new DevelopmentProject(); developmentProject.Category = model.Category; developmentProject.Date = model.Date; developmentProject.LongDescription = model.LongDescription; developmentProject.LongName = model.LongName; developmentProject.ShortDescription = model.ShortDescription; developmentProject.ShortName = model.ShortName; string skill = model.SkillList.ToString(); developmentProject.SkillsNeeded = skill; developmentProject.GitHubUrl = model.GitHubUrl; developmentProject.ProjectUrl = model.ProjectUrl; if (model.ProjectThumbnailUpload != null && model.ProjectThumbnailUpload.ContentLength > 0) { var uploadDir = "~/ImageUploads/AlbumThumbnailUploads"; var imagePath = Path.Combine(Server.MapPath(uploadDir), model.ProjectThumbnailUpload.FileName); var imageUrl = Path.Combine(uploadDir, model.ProjectThumbnailUpload.FileName); imageUrl = imageUrl.Replace(@"\", "/"); imagePath = imagePath.Replace(@"\", "/"); model.ProjectThumbnailUpload.SaveAs(imagePath); developmentProject.ProjectImageUrl = imageUrl; } db.DevelopmentProjects.Add(developmentProject); db.SaveChanges(); return(RedirectToAction("Portfolio")); } return(View(model)); }
// GET: DevelopmentProjects/Create public ActionResult Create() { var model = new DevelopmentProjectViewModel(); return(View(model)); }