public Video Update(UpdateVideoCommand command)
        {
            var video = _repository.GetById(command.IdVideo);

            video.Update(command);
            _repository.Update(video);


            //if(video.Plan.IdPlan != command.IdPlan || video.)

            Commit();

            var videoEquipment = _repositoryVideoEquipment.GetAllByVideo(video.IdVideo);

            foreach (var item in videoEquipment)
            {
                decimal valueByTv = _repositoryBalance.GetValueByVideo(video.IdVideo);

                var history = new HistoryEquipment(command.IdVideo, item.IdEquipment, item.ControlLoan.IdCompany, video.Plan.Description, EAction.Atualização, valueByTv);
                history.Create();
                _repositoryHistoryEquipment.Create(history);
            }

            if (Commit())
            {
                return(video);
            }

            return(null);
        }
        public Video Create(CreateVideoCommand command)
        {
            var video = new Video(command.Url, command.TvAdditional, command.IdTypeVideo, command.IdTimeVideo, command.IdCompany, command.IdCategoryVideo, command.IdPlan, command.DateEnd, command.DateStart, command.ListVideoEquipment);

            //Marca todos itens da lista ListVideoEquipment com status Ativo
            foreach (var videoEquipment in command.ListVideoEquipment)
            {
                videoEquipment.Status       = EStatusVideoEquipment.Ativo;
                videoEquipment.DateRegister = DateTime.Now;
            }

            video.Create();
            _repository.Create(video);

            Commit();

            foreach (var videoEquipment in command.ListVideoEquipment)
            {
                var     item      = _repositoryVideoEquipment.GetById(videoEquipment.IdVideoEquipment);
                decimal valueByTv = _repositoryBalance.GetValueByVideo(item.IdVideo);
                var     history   = new HistoryEquipment(item.IdVideo, item.IdEquipment, item.ControlLoan.IdCompany, item.Video.Plan.Description, EAction.Inclusão, valueByTv);
                history.Create();
                _repositoryHistoryEquipment.Create(history);
            }



            if (Commit())
            {
                return(video);
            }

            return(null);
        }
        public VideoEquipment Create(CreateVideoEquipmentCommand command)
        {
            //Insere dados na tabela de histórico
            var     loan      = _repositoryLoan.GetById(command.IdControlLoan);
            decimal valueByTv = _repositoryBalance.GetValueByVideo(command.IdVideo);
            var     video     = _repositoryVideo.GetById(command.IdVideo);
            var     history   = new HistoryEquipment(command.IdVideo, command.IdEquipment, loan.IdCompany, video.Plan.Description, EAction.Inclusão, valueByTv);

            history.Create();
            _repositoryHistoryEquipment.Create(history);


            //Caso já exista os mesmos dados na tabela VideoEquipment, o registro é apenas atualizado com status ativo
            VideoEquipment videoEquipment = null;

            videoEquipment = _repository.GetById(command.IdEquipment, command.IdVideo, command.IdControlLoan);

            if (videoEquipment != null)
            {
                videoEquipment.Status = EStatusVideoEquipment.Ativo;
            }
            else
            {
                videoEquipment = new VideoEquipment(command.IdVideo, command.IdEquipment, command.IdControlLoan);
                videoEquipment.Create(videoEquipment);
                _repository.Create(videoEquipment);
            }

            if (Commit())
            {
                return(videoEquipment);
            }

            return(null);
        }
Esempio n. 4
0
        public HistoryEquipment Create(CreateHistoryEquipmentCommand command)
        {
            var history = new HistoryEquipment(command.IdVideo, command.IdEquipment, command.IdCompany, command.Plan, command.Action, command.Value);

            history.Create();
            _repository.Create(history);

            if (Commit())
            {
                return(history);
            }

            return(null);
        }
        public void UpdateStatusListVideo()
        {
            VideoEquipment videoEquipment     = new VideoEquipment();
            var            listVideoEquipment = _repository.GetByStatus(EStatusVideoEquipment.Ativo);
            ICollection <VideoEquipment> listVideoEquipmentUpdate = videoEquipment.UpdateStatusListVideo(listVideoEquipment);

            foreach (var video in listVideoEquipmentUpdate)
            {
                var     item      = _repositoryVideoEquipment.GetById(videoEquipment.IdVideoEquipment);
                decimal valueByTv = _repositoryBalance.GetValueByVideo(item.IdVideo);
                var     history   = new HistoryEquipment(item.IdVideo, item.IdEquipment, item.ControlLoan.IdCompany, item.Video.Plan.Description, EAction.Exclusão, valueByTv);
                history.Create();
                _repositoryHistoryEquipment.Create(history);
            }

            _repository.UpdateStatusListVideo(listVideoEquipmentUpdate);

            Commit();
        }
        public VideoEquipment Delete(int idEquipment, int idVideo, int controlLoan)
        {
            var loan = _repositoryLoan.GetById(controlLoan);

            decimal valueByTv = _repositoryBalance.GetValueByVideo(idVideo);
            var     video     = _repositoryVideo.GetById(idVideo);

            var history = new HistoryEquipment(idVideo, idEquipment, loan.IdCompany, video.Plan.Description, EAction.Exclusão, valueByTv);

            history.Create();
            _repositoryHistoryEquipment.Create(history);

            var videoEquipment = _repository.GetIdVideoEquipment(idEquipment, idVideo);

            videoEquipment.Delete(videoEquipment);
            _repository.Delete(videoEquipment);

            if (Commit())
            {
                return(videoEquipment);
            }

            return(null);
        }