Example #1
0
 public HttpResponseMessage Put([FromBody] MovieReview review)
 {
     //review.Id = Id;
     _uOW.MovieReviews.Update(review);
     _uOW.Commit();
     return(new HttpResponseMessage(HttpStatusCode.NoContent));
 }
        public IActionResult Upload(int Id, IFormFile file)
        {
            var movie = _uow.Movies.GetById(Id);

            if (movie == null)
            {
                return(NotFound());
            }

            if (file == null)
            {
                return(BadRequest("File not valid"));
            }
            if (file.Length == 0)
            {
                return(BadRequest("Empty File"));
            }
            if (file.Length > _options.MaxBytes)
            {
                return(BadRequest("File exceeded 10 MB size!"));
            }

            if (!_options.IsSupported(file.FileName))
            {
                return(BadRequest("Invalid File Type"));
            }
            var uploadsFolder = Path.Combine(_host.WebRootPath, "uploads");

            if (!Directory.Exists(uploadsFolder))
            {
                Directory.CreateDirectory(uploadsFolder);
            }

            var fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
            var filepath = Path.Combine(uploadsFolder, fileName);

            using (var stream = new FileStream(filepath, FileMode.Create))
            {
                file.CopyTo(stream);
            }

            var image = new Image {
                FileName = fileName
            };

            movie.Images.Add(image);
            _uow.Commit();
            return(Ok(image));
        }
 public IActionResult Post([FromBody] Movie movie)
 {
     movie = _uow.Movies.Add(movie);
     _uow.Commit();
     return(Ok(movie));
 }