public ActionResult Index() { var model = new UploadPhotoViewModel(); if (!model.UserIsAuthenticated) { return RedirectToAction("Index", "Home"); } return View(model); }
public ActionResult Upload(UploadPhotoViewModel model) { if (ModelState.IsValid) { if (!model.Photo.ContentType.ToLower().Contains("image")) { ModelState.AddModelError("Invalid_image _type", "Invalid image type"); return RedirectToAction(""); } MemoryStream target = new MemoryStream(); model.Photo.InputStream.CopyTo(target); byte[] data = target.ToArray(); var owner = Session.Load<User>(MvcApplication.SecurityManager.AuthenticatedUser.Id); var id = Guid.NewGuid(); var photo = new Photo(id, data, model.Title, model.Description, owner, DateTime.Now, model.Photo.ContentType, model.Category, !String.IsNullOrEmpty(model.EnableComments)); Session.Save(photo); MyPhoto.Web.Library.Installers.Search.AddOrUpdate(photo); return Redirect("/Preview?id=" + id); } return Redirect("/"); }