Esempio n. 1
0
        public ActionResult <string> AddMovie(ApiMovie apiMovie)
        {
            string returnString = "Add movie failed: ";

            if (string.IsNullOrEmpty(apiMovie.Name))
            {
                return(returnString + "Movie need a name");
            }
            else if (string.IsNullOrEmpty(apiMovie.Length) || !Int32.TryParse(apiMovie.Length, out int i))
            {
                return(returnString + "You need to right a number in movie length");
            }
            else if (string.IsNullOrEmpty(apiMovie.Desc))
            {
                return(returnString + "please just write something in the movie description");
            }
            else if (apiMovie.Genre == null)
            {
                return(returnString + "No genre is seleceted");
            }
            else if (apiMovie.File == null)
            {
                return(returnString + "No image file is select");
            }

            byte[] imgBytes = new byte[apiMovie.File.Length];
            using (var ms = new MemoryStream())
            {
                apiMovie.File.CopyTo(ms);
                imgBytes = ms.ToArray();
            }

            Movie movie = new Movie
            {
                Name       = apiMovie.Name,
                Length     = Convert.ToInt32(apiMovie.Length),
                Desc       = apiMovie.Desc,
                Genre      = (MovieGenre)Convert.ToInt32(apiMovie.Genre),
                ImageBytes = imgBytes
            };

            bool success = _sqlService.AddMovie(movie);

            returnString = success ? "Add movie success" : returnString;

            return(returnString);
        }