Beispiel #1
0
        public IHttpActionResult Put(int id, [FromBody] Checklist value)
        {
            if (id == 0)
            {
                return(BadRequest());
            }
            var checklist = checklistRepository.Get(id);

            if (checklist == null)
            {
                return(NotFound());
            }
            checklist.IsCompleted = value.IsCompleted;
            checklist.Description = value.Description;
            checklistRepository.Update(checklist);

            return(Ok());
        }
        public async Task <string> Execute(CheckList checklist, int idAppointment, DateTime dateTimeDelivery, string path)
        {
            if (idAppointment == 0)
            {
                throw new NotFoundRegisterException("Appointment não Encontrado. Verifique");
            }
            var appointment = await _repository.FindById(idAppointment);

            if (appointment == null)
            {
                throw new NotFoundRegisterException("Appointment não Encontrado. Verifique");
            }
            if (appointment.DateTimeCollected == null)
            {
                throw new NotFoundRegisterException("Carro não foi alocado. Verifique para realizar vistória.");
            }
            if (appointment.DateTimeCollected > dateTimeDelivery)
            {
                throw new DateTimeColectedInvalidException("A data de devolução é menor que a data coletada. Verifique para realizar vistória.");
            }

            appointment.DateTimeDelivery = dateTimeDelivery;
            appointment.Inspected        = true;

            if (!checklist.CleanCar)
            {
                appointment.AdditionalCosts = appointment.Amount * 0.30;
            }
            if (!checklist.FullTank)
            {
                appointment.AdditionalCosts = appointment.Amount * 0.30;
            }
            if (checklist.Crumpled)
            {
                appointment.AdditionalCosts = appointment.Amount * 0.30;
            }
            if (checklist.Scratches)
            {
                appointment.AdditionalCosts = appointment.Amount * 0.30;
            }

            string pdf;

            if (appointment.IdCheckList != null)
            {
                checklist.Id = (int)appointment.IdCheckList;
                await _repository.Update(appointment);

                await _repositoryCheckList.Update(checklist);

                pdf = CheckListPaymentPDF.Writer(appointment);
                return(_servicePDF.Build(path, pdf));
            }

            await _repository.Update(appointment);

            await _repositoryCheckList.Add(checklist);

            pdf = CheckListPaymentPDF.Writer(appointment);
            return(_servicePDF.Build(path, pdf));
        }