Ejemplo n.º 1
0
        public IActionResult Avatar([FromForm] MovieUpdateListViewModel movie)
        {
            this.ViewBag.DefaultImage = defaultImage;

            if (movie.Image == null && movie.ImageString == null)
            {
                this.TempData["Error-Message"] = "Error! Please provide an image";
                return(this.PartialView("_MovieInputPartial", movie));
            }

            if (movie.Image != null)
            {//Ако сме подали нов файл
                if (!this.IsValidImage(movie.Image))
                {
                    this.TempData["Error-Message"] = "Error! Please provide a.jpg, .png ro jpeg file smaller than 1MB";
                    return(this.PartialView("_MovieInputPartial", movie));
                }

                using (var ms = new MemoryStream())
                {
                    movie.Image.CopyTo(ms);
                    var    fileBytes = ms.ToArray();
                    string base64    = Convert.ToBase64String(fileBytes);
                    movie.ImageString = string.Format("data:image/{0};base64,{1}", movie.Image.ContentType, base64);
                }

                this.TempData["Success-Message"] = "Success! Movie image updated";
            }
            else
            {
                this.TempData["Error-Message"] = "Warning! Movie image restored";
            }

            return(this.PartialView("_MovieInputPartial", movie));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Update()
        {
            var movies = await this.movieService.GetMovies();

            this.ViewBag.DefaultImage = defaultImage;

            var model = new MovieUpdateListViewModel(movies.Select(movie => new MovieUpdateViewModel(movie, defaultImage)));

            return(this.View(model));
        }
Ejemplo n.º 3
0
        public IActionResult GetMovie(MovieUpdateListViewModel movie)
        {
            this.TempData["Success-Message"] = null;

            this.TempData["Error-Message"] = null;

            this.ViewBag.MovieName = movie.Name;

            this.ViewBag.DefaultImage = defaultImage;

            return(PartialView("_MovieInputPartial", movie));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Update(MovieUpdateListViewModel viewModel)
        {
            this.ViewBag.DefaultImage = defaultImage;

            if (!this.ModelState.IsValid)
            {
                this.TempData["Error-Message"] = $"You have entered wrong Movie parameters";
                return(this.RedirectToAction("Update"));
            }

            //try
            //{
            await this.movieService.UpdateMovie(viewModel.Id, viewModel.Name, viewModel.Description, viewModel.ReleaseYear, viewModel.Duration, viewModel.ImageString);

            //}
            //catch (Exception)
            //{
            //    this.TempData["Error-Message"] = "Movie does not exist in database";
            //    return this.RedirectToAction("Update");
            //}

            this.TempData["Success-Message"] = $"You successfully updated the movie information!";
            return(this.RedirectToAction("Update"));
        }