public ActionResult Create(Photo photo, HttpPostedFileBase image) { photo.CreatedDate = DateTime.Today; if (!ModelState.IsValid) { return(View("Create", photo)); } else { if (image != null) { photo.ImageMimeType = image.ContentType; photo.PhotoFile = new byte[image.ContentLength]; image.InputStream.Read(photo.PhotoFile, 0, image.ContentLength); } context.Add <Photo>(photo); context.SaveChanges(); return(RedirectToAction("Index")); } }
public virtual ActionResult NewOrEdit(CategoryModel model) { if (!ModelState.IsValid) { return(View(Views.NewOrEdit, model)); } var isNew = model.CategoryId == default(int); var category = isNew ? _context.Categories.Create() : _context.FindById <CategoryModel>(model.CategoryId); category.Name = model.Name; category.Slug = model.Slug; if (isNew) { _context.Add(category); } _context.SaveChanges(); return(RedirectToAction(T4Routes.Category.Manage())); }
public ActionResult Create(Photo photo, HttpPostedFileBase image) { photo.CreationDate = DateTime.Today; if (!ModelState.IsValid) { return(View("Create", photo)); } else { //if image object is not empty update the photo attribute, using image info. if (image != null) { photo.ImageMimeType = image.ContentType; photo.PhotoFile = new byte[image.ContentLength]; //save the photo file by using image.InputStream.Read method. image.InputStream.Read(photo.PhotoFile, 0, image.ContentLength); } context.Add(photo); context.SaveChanges(); return(RedirectToAction("Index")); } }