Пример #1
0
        public async Task <ActionResult> Edit(Guid id, FilmEditModel model)
        {
            var film = await this.db.Films.SingleOrDefaultAsync(m => m.Id == id);

            var fileExt = "";

            if (model.File != null)
            {
                var fileName = System.IO.Path.GetFileName(model.File.FileName);
                fileExt = Path.GetExtension(fileName).ToLower();
                if (!FilmsController.AllowedExtensions.Contains(fileExt))
                {
                    this.ModelState.AddModelError(nameof(model.File), "This file type is prohibited");
                }
            }
            if (ModelState.IsValid)
            {
                film.Name        = model.Name;
                film.Regisseur   = model.Regisseur;
                film.Description = model.Description;
                film.Created     = model.Created;
                if (model.File != null)
                {
                    Guid file_name = Guid.NewGuid();
                    model.File.SaveAs(HostingEnvironment.MapPath("~/attachments/" + file_name + fileExt));
                    film.Path = "/attachments/" + file_name + fileExt;
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Пример #2
0
        public async Task <FilmEditModel> EditFilm(FilmEditModel model)
        {
            var film = await _dbContext.Films.FindAsync(model.Id);

            film.Name        = model.Name;
            film.Description = model.Description;
            film.Producer    = model.Producer;
            film.Year        = model.Year;

            try
            {
                film.Name        = model.Name;
                film.Description = model.Description;
                film.Producer    = model.Producer;
                film.Year        = model.Year;

                await _dbContext.SaveChangesAsync();

                return(model);
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Failed to edit item. Error stack: {e}");
                throw;
            }
        }
Пример #3
0
        public async Task <IActionResult> Edit(FilmEditModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.ImageNew != null)
                {
                    string uniqueFileName = UploadedFile(model.ImageNew);
                    model.Image = uniqueFileName;
                }
                Film film = new Film
                {
                    Id        = model.Id,
                    Title     = model.Title,
                    Desc      = model.Desc,
                    Year      = model.Year,
                    Director  = model.Director,
                    UserEmail = model.UserEmail,
                    Image     = model.Image,
                };
                dbContext.Films.Update(film);
                await dbContext.SaveChangesAsync();

                return(Redirect("~/Film/Info/?filmId=" + @model.Id));
            }
            return(View(model));
        }
Пример #4
0
        public List <int> AgregateSelectedFilmCrewIds(FilmEditModel model)
        {
            List <int> selectedfilmCrewIds = new List <int>();

            foreach (var item in model.ProducerIds)
            {
                selectedfilmCrewIds.Add(item);
            }
            foreach (var item in model.ActorIds)
            {
                selectedfilmCrewIds.Add(item);
            }

            return(selectedfilmCrewIds);
        }
Пример #5
0
        public async Task <IActionResult> Edit(int id, FilmEditModel film)
        {
            if (id != film.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                await _filmService.EditFilm(film);

                return(RedirectToAction(nameof(Index)));
            }

            return(View(film));
        }
Пример #6
0
        public FilmEntity Edit(FilmEditModel model)
        {
            FilmEntity entry = null;

            using (context = new CinemaStoreContext())
            {
                if (model.Id > 0)
                {
                    entry =
                        context.FilmEntity
                        .Include(x => x.FilmCrew)
                        .Include(x => x.Categories)
                        .FirstOrDefault(x => x.Id == model.Id);
                }
                else
                {
                    entry = new FilmEntity();
                    context.FilmEntity.Add(entry);
                }

                entry.Description = model.Description;
                entry.Name        = model.Name;
                entry.Year        = model.Year;
                entry.UserId      = model.UserId;

                List <int> selectedFilmCrewIds = AgregateSelectedFilmCrewIds(model);
                var        selectedFilmCrew    = GetFilmCrew(selectedFilmCrewIds.ToArray(), context);
                var        selectedCategories  = GetCategories(model.CategoryIds, context);

                try
                {
                    UpdateFilmCrew(selectedFilmCrew, entry, context);
                    UpdateFilmCategories(selectedCategories, entry, context);

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(entry);
        }
Пример #7
0
        public async Task <FilmEditModel> GetEditFilm(int id)
        {
            var userId = _httpContextAccessor.HttpContext.User.GetLoggedInUserId <string>();
            var dbFilm = await _dbContext.Films.FindAsync(id);

            if (userId != dbFilm.UserId)
            {
                return(null);
            }

            var film = new FilmEditModel
            {
                Id          = dbFilm.Id,
                Name        = dbFilm.Name,
                Description = dbFilm.Description,
                Producer    = dbFilm.Producer,
                Year        = dbFilm.Year,
            };

            return(film);
        }
Пример #8
0
        public ActionResult Create(FilmEditModel model)
        {
            Guid file_name = Guid.NewGuid();
            var  fileName  = "";
            var  fileExt   = "";

            if (model.File != null)
            {
                fileName = System.IO.Path.GetFileName(model.File.FileName);
                fileExt  = Path.GetExtension(fileName).ToLower();
                if (!FilmsController.AllowedExtensions.Contains(fileExt))
                {
                    this.ModelState.AddModelError(nameof(model.File), "This file type is prohibited");
                }
                model.File.SaveAs(HostingEnvironment.MapPath("~/attachments/" + file_name + fileExt));
            }

            if (ModelState.IsValid)
            {
                var Film = new Film
                {
                    Name         = model.Name,
                    Description  = model.Description,
                    Created      = model.Created,
                    Regisseur    = model.Regisseur,
                    CreatorName  = User.Identity.Name,
                    Created_post = DateTime.Now
                };
                if (model.File != null)
                {
                    Film.Path = "/attachments/" + file_name + fileExt;
                }

                db.Films.Add(Film);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
Пример #9
0
        // GET: Films/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Film film     = db.Films.Find(id);
            var  editFilm = new FilmEditModel
            {
                Name        = film.Name,
                Description = film.Description,
                Created     = film.Created,
                Regisseur   = film.Regisseur,
                CreatorName = User.Identity.Name,
            };

            if (film == null)
            {
                return(HttpNotFound());
            }
            this.ViewBag.Guid = film.Id;
            return(View(editFilm));
        }
Пример #10
0
        public async Task <IActionResult> Edit(int?filmId)
        {
            if (filmId != null)
            {
                Film film = await dbContext.Films.AsNoTracking().FirstOrDefaultAsync(u => u.Id == filmId);

                if (film != null && film.UserEmail == User.Identity.Name)
                {
                    FilmEditModel filmEditModel = new FilmEditModel
                    {
                        Id        = film.Id,
                        Title     = film.Title,
                        Desc      = film.Desc,
                        Year      = film.Year,
                        Director  = film.Director,
                        UserEmail = film.UserEmail,
                        Image     = film.Image,
                        ImageNew  = null,
                    };
                    return(View(filmEditModel));;
                }
            }
            return(NotFound());
        }