public async Task <ActionResult> PostApplicant(
            [FromServices] DataContext context,
            [ModelBinder(BinderType = typeof(JsonWithFilesFormDataModelBinder))] AdoptionApplicant model,
            IFormFile fileObligationDocument)
        {
            if (ModelState.IsValid)
            {
                AdoptionProcess process = new AdoptionProcess();

                DateTime date = DateTime.Now;
                process.CreatedOn  = model.ModifiedOn;
                process.ModifiedOn = model.ModifiedOn;
                process.IsPendent  = true;
                process.Protocol   = String.Format("{0:yyyyMMddHHmmss}", date);
                process.AdoptionTechnicalAnalysis = new AdoptionTechnicalAnalysis();
                process.AdoptionAdequacy          = new AdoptionAdequacy();
                process.Task      = ProcessTasks.TechnicalAnalysis;
                process.Condition = ProcessConditions.Active;
                process.CreatedBy = model.ModifiedBy;

                model.AdoptionObligation.DocumentsAttachmentPath = await AddFileAttachment(fileObligationDocument, process.Protocol);

                process.AdoptionApplicant = model;

                context.AdoptionProcesses.Add(process);
                context.AdoptionApplicants.Add(model);
                await context.SaveChangesAsync();

                EmailSenderAdoption.SendEmail(model.AdoptionInterlocutor.Email, "*****@*****.**",
                                              $"Notificação do Banco de Áreas PCJ - Adoção (Processo {process.Protocol})", model.AdoptionInterlocutor.FullName, EmailTypes.Begin);

                return(Ok());
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public async Task <bool> UpdateProcess([FromServices] DataContext context, [FromBody] AdoptionProcess model)
        {
            var process = await context.AdoptionProcesses
                          .AsNoTracking()
                          .FirstOrDefaultAsync(x => x.AdoptionProcessId == model.AdoptionProcessId);

            var applicant = await context.AdoptionApplicants
                            .AsNoTracking()
                            .Include(x => x.AdoptionInterlocutor)
                            .FirstOrDefaultAsync(x => x.AdoptionApplicantId == process.AdoptionApplicantId);

            process = model;

            if (process.Status == "Encerrar")
            {
                process.Task      = ProcessTasks.Completed;
                process.Condition = ProcessConditions.Concluded;

                if (process.AdoptionTechnicalAnalysis.Status == "Adequar" && process.AdoptionAdequacy.Status == "Expirado")
                {
                    EmailSenderAdoption.SendEmail(applicant.AdoptionInterlocutor.Email, "*****@*****.**",
                                                  $"Notificação do Banco de Áreas PCJ - Adoção (Processo {process.Protocol})", applicant.AdoptionInterlocutor.FullName, EmailTypes.CompletionAdequacyExpired);
                }

                if (process.AdoptionTechnicalAnalysis.Status == "Adequar" && process.AdoptionAdequacy.Status == "Finalizar")
                {
                    EmailSenderAdoption.SendEmail(applicant.AdoptionInterlocutor.Email, "*****@*****.**",
                                                  $"Notificação do Banco de Áreas PCJ - Adoção (Processo {process.Protocol})", applicant.AdoptionInterlocutor.FullName, EmailTypes.CompletionAdequacy);
                }

                if (process.AdoptionTechnicalAnalysis.Status == "Aguardar")
                {
                    EmailSenderAdoption.SendEmail(applicant.AdoptionInterlocutor.Email, "*****@*****.**",
                                                  $"Notificação do Banco de Áreas PCJ - Adoção (Processo {process.Protocol})", applicant.AdoptionInterlocutor.FullName, EmailTypes.CompletionAwait);
                }

                if (process.AdoptionTechnicalAnalysis.Status == "Aceita")
                {
                    EmailSenderAdoption.SendEmail(applicant.AdoptionInterlocutor.Email, "*****@*****.**",
                                                  $"Notificação do Banco de Áreas PCJ - Adoção (Processo {process.Protocol})", applicant.AdoptionInterlocutor.FullName, EmailTypes.Completion);
                }

                process.AdoptionAdequacy          = null;
                process.AdoptionApplicant         = null;
                process.AdoptionTechnicalAnalysis = null;

                context.Update(process);

                return((await context.SaveChangesAsync()) > 0);
            }
            if (process.Status == "Reanalisar" && process.Task == ProcessTasks.Completion)
            {
                EmailSenderAdoption.SendEmail(applicant.AdoptionInterlocutor.Email, "*****@*****.**",
                                              $"Notificação do Banco de Áreas PCJ - Adoção (Processo {process.Protocol})", applicant.AdoptionInterlocutor.FullName, EmailTypes.CompletionReanalyze);

                process.Status    = "";
                process.Task      = ProcessTasks.TechnicalAnalysis;
                process.IsPendent = model.IsPendent;
            }

            process.AdoptionAdequacy          = null;
            process.AdoptionApplicant         = null;
            process.AdoptionTechnicalAnalysis = null;

            context.Update(process);

            return((await context.SaveChangesAsync()) > 0);
        }