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. 2
0
        public Task <HttpResponseMessage> GetById(int id)
        {
            var loan = _service.GetById(id);

            return(CreateResponse(HttpStatusCode.OK, loan));
        }