public async Task <ActionResult> CreateChecklist([FromBody] LogChecklist checklist)
        {
            checklist.Version = 1;
            checklist.Status  = "Draft";

            var index = new LogChecklistIndex()
            {
                CreatedBy   = user,
                CreatedTime = DateTime.Now,
            };

            _repo.Add(index);
            checklist.Idchecklist = index.Idchecklist;
            _repo.Add(checklist);

            var history = LogHistory(checklist, "Create new Checklist Version", 1);

            _repo.Add(history);


            if (await _repo.SaveAll())
            {
                return(CreatedAtAction("GetbyId", new { id = checklist.Idchecklist, ver = checklist.Version }, checklist));
            }

            return(BadRequest("Failed to Create Checklist"));
        }
Example #2
0
        public async Task <ActionResult> AddStep(LogChecklistSteps step)
        {
            //get count
            var stepCount = _repo.GetStepCount(step);

            step.Step = (short)stepCount;

            _repo.Add(step);
            var history = FileHistory(step, "Draft", "Added a Step");


            _repo.Add(history);

            await _repo.SaveAll();

            return(CreatedAtRoute("GetStep", new { stepId = step.Idstep }, step));
        }
Example #3
0
        public IHttpActionResult Create([FromBody] CreateChecklistVM checklist)
        {
            if (string.IsNullOrWhiteSpace(checklist.Description))
            {
                return(BadRequest());
            }
            var newChecklist = new Checklist()
            {
                Description = checklist.Description,
                ParentId    = checklist.ParentId,
                UserId      = userId,
            };

            checklistRepository.Add(newChecklist);

            return(Created(newChecklist.Id.ToString(), checklist));
        }
        private void SaveTemplate()
        {
            if (!CanSave())
            {
                return;
            }

            Checklist.Hash    = MD5.Crypt($"Checklist {Checklist.Inspections.Count}-{Checklist.Name}");
            Checklist.Name    = Checklist.Name?.Trim();
            Checklist.Remarks = Checklist.Remarks?.Trim() ?? "";

            var questions = _checklistQuestionRepository.GetChecklistQuestions(Checklist.Parent);

            TemplateQuestions
            .ToList()
            .ForEach(q =>
            {
                var question = questions.FirstOrDefault(x => x.Question.ID == q.Question.ID);

                if (question == null)
                {
                    Checklist.ChecklistQuestions.Add(q);
                    return;
                }

                if (q.Question.Equals(question.Question))
                {
                    Checklist.ChecklistQuestions.Add(q);
                    return;
                }

                Checklist.ChecklistQuestions.Add(q.GetCleanModel());
            });

            Checklist.DateTimeCreated = DateTime.Now;

            _checklistRepository.Add(Checklist);
            MessageBox.Show($"Template met de naam {Checklist.Name} en {Checklist.ChecklistQuestions.Count} vragen is opgeslagen.");
            _router.GoBack();
        }
        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));
        }