Exemplo n.º 1
0
        public ActionResult Create(PhotoCreateViewModel photo, HttpPostedFileBase image)
        {
            photo.CreatedDate = DateTime.Today;
            if (!ModelState.IsValid)
            {
                var types = photoAPI.GetAllPhotoTypes();
                photo.PhotoTypes = new SelectList(types, "PhotoTypeID", "Description");
                return(View(photo));
            }
            else
            {
                photo.CreatedDate = DateTime.Today;
                if (image != null)
                {
                    var photoFile = new byte[image.ContentLength];
                    image.InputStream.Read(photoFile, 0, image.ContentLength);
                    photoAPI.AddPhoto(photo.ToDataModel(), photoFile, image.ContentType);
                }
                else
                {
                    photoAPI.AddPhoto(photo.ToDataModel());
                }

                return(RedirectToAction("Index"));
            }
        }