public async Task <CreateEditFilmViewModel> GetEdit(int?Id)
        {
            var post = _context.Film
                       .Include(p => p.Image)
                       .Include(p => p.Serie)
                       .SingleOrDefault(p => p.ID == Id);

            if (post != null)
            {
                var tags = await _context.FilmTag.
                           Include(p => p.Tag).
                           Where(p => p.FilmID == post.ID).
                           ToListAsync();

                string tempTag = "";
                foreach (var item in tags)
                {
                    tempTag = tempTag + item.Tag.Title + ", ";
                }
                CreateEditFilmViewModel model = new CreateEditFilmViewModel
                {
                    Actor            = post.Actor,
                    AuthorID         = post.AuthorID,
                    DateofRease      = post.DateofRease,
                    Description      = post.Description,
                    DescriptionShort = post.DescriptionShort,
                    Director         = post.Director,
                    ImageID          = post.ImageID,
                    Info             = post.Info,
                    IsProposed       = post.IsProposed,
                    Watch            = post.Watch,
                    Vote             = post.Vote,
                    VideoTrailer     = post.VideoTrailer,
                    VideoBackUp2     = post.VideoBackUp2,
                    VideoBackUp1     = post.VideoBackUp1,
                    Video            = post.Video,
                    Length           = post.Length,
                    Title            = post.Title,
                    StarRating       = post.StarRating,
                    Slug             = post.Slug,
                    SerieID          = post.SerieID,
                    OrtherTitle      = post.OrtherTitle,
                    Genres           = post.Genres,
                    TempTag          = tempTag,
                    Image            = post.Image,
                    Serie            = post.Serie
                };
                return(model);
            }
            return(null);
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("ID,Title,OrtherTitle,Description, DescriptionShort,TempTag,DateofRease,Info,Length,Watch,StarRating,Video, VideoBackUp1, VideoBackUp2,VideoTrailer,Slug,ImageID,SerieID,Genres,IsProposed,Actor,Director,TempTag")] CreateEditFilmViewModel film)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(HttpContext.User);

                film.AuthorID = user.Id;
                await _repository.Create(film);

                return(RedirectToAction("Index"));
            }
            ViewData["ImageID"]  = new SelectList(_repository.GetImages(), "ID", "Name", film.ImageID);
            ViewData["AuthorID"] = new SelectList(_repository.GetMembers(), "Id", "FullName", film.AuthorID);
            ViewData["SerieID"]  = new SelectList(_repository.GetSeries(), "ID", "ID", film.SerieID);
            return(View(film));
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Title,OrtherTitle,Description, DescriptionShort,TempTag,DateofRease,Info,Length,Watch,StarRating,Video, VideoBackUp1, VideoBackUp2,VideoTrailer,Slug,ImageID,SerieID,Genres,IsProposed,Actor,Director,TempTag")] CreateEditFilmViewModel film)
        {
            if (id != film.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _repository.SaveEdit(film);
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                return(RedirectToAction("Index"));
            }
            ViewData["ImageID"]  = new SelectList(_repository.GetImages(), "ID", "ID", film.ImageID);
            ViewData["AuthorID"] = new SelectList(_repository.GetMembers(), "Id", "Id", film.AuthorID);
            ViewData["SerieID"]  = new SelectList(_repository.GetSeries(), "ID", "ID", film.SerieID);
            return(View(film));
        }
        public async Task Create(CreateEditFilmViewModel model)
        {
            var post = _context.Film.SingleOrDefault(p => p.ID == model.ID);

            if (post != null)
            {
                throw new ArgumentException("A post with the id of " + model.ID + " already exists.");
            }

            Film film = new Film
            {
                Active           = "A",
                Actor            = model.Actor,
                Approved         = "A",
                AuthorID         = model.AuthorID,
                CreateDT         = DateTime.Now,
                IsDeleted        = false,
                UpdateDT         = DateTime.Now,
                DateofRease      = model.DateofRease,
                Description      = model.Description,
                DescriptionShort = model.DescriptionShort,
                Director         = model.Director,
                ImageID          = model.ImageID,
                Info             = model.Info,
                IsProposed       = model.IsProposed,
                Watch            = model.Watch,
                Vote             = model.Vote,
                VideoTrailer     = model.VideoTrailer,
                VideoBackUp2     = model.VideoBackUp2,
                VideoBackUp1     = model.VideoBackUp1,
                Video            = model.Video,
                Length           = model.Length,
                Title            = model.Title,
                StarRating       = model.StarRating,
                Slug             = model.Slug,
                SerieID          = model.SerieID,
                OrtherTitle      = model.OrtherTitle,
                Genres           = model.Genres
            };

            _context.Film.Add(film);

            // Get and convert string to create tag
            List <string> listString = StringExtensions.ConvertStringToListString(model.TempTag);
            List <Tag>    listTag    = new List <Tag>(listString.Capacity - 1);

            // Save all tag
            foreach (var item in listString)
            {
                Tag tag = new Tag
                {
                    Title = item,
                    Slug  = StringExtensions.ConvertToUnSign3(item)
                };
                _context.Add(tag);
                _context.Add(new FilmTag {
                    TagID = tag.ID, FilmID = film.ID
                });
            }
            await _context.SaveChangesAsync();
        }