Example #1
0
        public int UpdatePlay(PlayWithActors playDTO)
        {
            using (var _unitOfWork = UnitOfWork.GetUnitOfWork())
            {
                var play = _unitOfWork.PlayRepository.GetById(playDTO.Id);

                play.Title            = playDTO.Title;
                play.ImagePath        = playDTO.ImagePath;
                play.ImageVirtualPath = playDTO.ImageVirtualPath;
                play.ImageType        = playDTO.ImageType;
                play.Description      = playDTO.Description;
                play.ScheduledTime    = playDTO.ScheduledTime;

                var playActorRecords = _unitOfWork.PlayActorRepository.GetPlayActorsForPlayId(play.Id);

                foreach (var playActorRecord in playActorRecords)
                {
                    _unitOfWork.PlayActorRepository.Delete(playActorRecord.Id);
                }

                foreach (var id in playDTO.ActorsIds)
                {
                    PlayActor playActor = new PlayActor
                    {
                        PlayId  = play.Id,
                        ActorId = id
                    };
                    _unitOfWork.PlayActorRepository.Insert(playActor);
                }

                _unitOfWork.Save();
                return(play.Id);
            }
        }
Example #2
0
        public int CreatePlay(PlayWithActors playDTO)
        {
            using (var _unitOfWork = UnitOfWork.GetUnitOfWork())
            {
                Play play = new Play
                {
                    Title            = playDTO.Title,
                    ImagePath        = playDTO.ImagePath,
                    ImageVirtualPath = playDTO.ImageVirtualPath,
                    ImageType        = playDTO.ImageType,
                    Description      = playDTO.Description,
                    ScheduledTime    = playDTO.ScheduledTime
                };

                _unitOfWork.PlayRepository.Insert(play);

                foreach (var id in playDTO.ActorsIds)
                {
                    PlayActor playActor = new PlayActor
                    {
                        PlayId  = play.Id,
                        ActorId = id
                    };
                    _unitOfWork.PlayActorRepository.Insert(playActor);
                }

                _unitOfWork.Save();
                return(play.Id);
            }
        }
        public ActionResult AddNewPlay(PlayViewModel model)
        {
            if (model.SelectedActorsIds.Count == 0)
            {
                ModelState.AddModelError(nameof(PlayViewModel.SelectedActorsIds), "Please select actors for this play.");
                model.Actors = _actorService.GetAllActors();
                return(View(model));
            }

            if (ModelState.IsValid)
            {
                if (model.File.ContentLength > 0 && model.File.ContentType.Contains("image"))
                {
                    var    imageFolderPath = Server.MapPath(WebConfigurationManager.AppSettings["imagePath"].ToString());
                    var    fileName        = Guid.NewGuid().ToString();
                    string virtualPath     = string.Format("{0}{1}{2}", WebConfigurationManager.AppSettings["virtualImagePath"].ToString(), fileName, Path.GetExtension(model.File.FileName).ToLower());
                    string path            = string.Format("{0}{1}{2}", imageFolderPath, Path.GetFileName(fileName), Path.GetExtension(model.File.FileName).ToLower());
                    model.File.SaveAs(path);

                    PlayWithActors playWithActors = new PlayWithActors
                    {
                        Title            = model.Title,
                        ImagePath        = path,
                        ImageVirtualPath = virtualPath,
                        ImageType        = Path.GetExtension(model.File.FileName),
                        Description      = model.Description,
                        ScheduledTime    = model.ScheduledTime,
                        ActorsIds        = model.SelectedActorsIds
                    };

                    _playService.CreatePlay(playWithActors);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError(nameof(PlayViewModel.File), "File must be image type!");
                    model.Actors = _actorService.GetAllActors();
                    return(View(model));
                }
            }
            else
            {
                model.Actors = _actorService.GetAllActors();
                return(View(model));
            }
        }
Example #4
0
        public void User_Can_Add_New_Play()
        {
            //Arrange
            var play = new PlayWithActors
            {
                Description      = "description",
                Title            = "The title",
                ScheduledTime    = DateTime.Today,
                ImageVirtualPath = "whatever",
                ImageType        = "whateverrr",
                ImagePath        = "gghjkjbj"
            };

            //Act
            var playId = _playService.CreatePlay(play);

            _playIds.Add(playId);
            var actual = _testPlayRepository.GetById(playId);

            //Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(playId, actual.Id);
            Assert.AreEqual(play.Title, actual.Title);
        }
        public ActionResult Edit(EditPlayViewModel model)
        {
            if (ModelState.IsValid)
            {
                var currentStatePlayView = _playViewService.GetPlayView(model.Id);
                if (model.ScheduledTime == null)
                {
                    model.ScheduledTime = currentStatePlayView.ScheduledTime;
                }
                if (model.SelectedActorsIds.Count == 0)
                {
                    var playActorsList = _playActorService.GetPlayActorsForPlayId(model.Id);

                    foreach (var playActorRecord in playActorsList)
                    {
                        model.SelectedActorsIds.Add(playActorRecord.ActorId);
                    }
                }

                if (model.File != null)
                {
                    if (model.File.ContentLength > 0 && !model.File.ContentType.Contains("image"))
                    {
                        ModelState.AddModelError(nameof(PlayViewModel.File), "File must be image type!");
                        model.AllActors = _actorService.GetAllActors();
                        return(View(model));
                    }

                    var imageFolderPath = Server.MapPath(WebConfigurationManager.AppSettings["imagePath"].ToString());
                    var fileName        = Guid.NewGuid().ToString();
                    model.ImageVirtualPath = string.Format("{0}{1}{2}", WebConfigurationManager.AppSettings["virtualImagePath"].ToString(), fileName, Path.GetExtension(model.File.FileName).ToLower());
                    model.ImagePath        = string.Format("{0}{1}{2}", imageFolderPath, Path.GetFileName(fileName), Path.GetExtension(model.File.FileName).ToLower());
                    model.File.SaveAs(model.ImagePath);

                    PlayWithActors playWithActors = new PlayWithActors
                    {
                        Title            = model.Title,
                        ImagePath        = model.ImagePath,
                        ImageVirtualPath = model.ImageVirtualPath,
                        ImageType        = Path.GetExtension(model.File.FileName),
                        Description      = model.Description,
                        ScheduledTime    = model.ScheduledTime,
                        ActorsIds        = model.SelectedActorsIds
                    };

                    _playService.UpdatePlay(playWithActors);

                    return(RedirectToAction("Index"));
                }
                else if (model.File == null)
                {
                    PlayWithActors playWithActors = new PlayWithActors
                    {
                        Id               = model.Id,
                        Title            = model.Title,
                        ImagePath        = currentStatePlayView.ImagePath,
                        ImageVirtualPath = currentStatePlayView.ImageVirtualPath,
                        ImageType        = currentStatePlayView.ImageType,
                        Description      = model.Description,
                        ScheduledTime    = model.ScheduledTime,
                        ActorsIds        = model.SelectedActorsIds
                    };

                    _playService.UpdatePlay(playWithActors);

                    return(RedirectToAction("Index"));
                }
            }
            model.ActorsString = _playViewService.GetPlayView(model.Id).Actors;
            model.AllActors    = _actorService.GetAllActors();
            return(View(model));
        }