public async Task <ActionResult> PostApplicant( [FromServices] DataContext context, [ModelBinder(BinderType = typeof(JsonWithFilesFormDataModelBinder))] DisponibilizationApplicant model, IFormFile fileGeometry, IFormFile fileImage) { if (ModelState.IsValid) { DisponibilizationProcess process = new DisponibilizationProcess(); DateTime date = DateTime.Now; process.CreatedOn = model.ModifiedOn; process.ModifiedOn = model.ModifiedOn; process.IsPendent = true; process.Protocol = String.Format("{0:yyyyMMddHHmmss}", date); process.TechnicalAnalysis = new DisponibilizationTechnicalAnalysis(); process.Task = ProcessTasks.GeometryPreparation; process.Condition = ProcessConditions.Active; process.CreatedBy = model.ModifiedBy; model.GeometryAttachmentPath = await AddFileAttachment(fileGeometry, process.Protocol); model.ImageAttachmentPath = await AddFileAttachment(fileImage, process.Protocol); process.Applicant = model; context.DisponibilizationProcesses.Add(process); context.DisponibilizationApplicants.Add(model); await context.SaveChangesAsync(); EmailSenderDisponibilization.SendEmail(model.Email, "*****@*****.**", $"Notificação do Banco de Áreas PCJ - Disponibilização (Processo {process.Protocol})", model.FullName, EmailTypes.Begin); return(Ok()); } else { return(BadRequest(ModelState)); } }
public async Task <bool> UpdateProcessCompletion([FromServices] DataContext context, [FromBody] DisponibilizationProcess model) { var process = await context.DisponibilizationProcesses .AsNoTracking() .FirstOrDefaultAsync(x => x.DisponibilizationProcessId == model.DisponibilizationProcessId); if (model.Status == "Encerrar") { model.Task = ProcessTasks.Completed; model.Condition = ProcessConditions.Concluded; } if (model.Status == "Reanalisar") { model.Task = ProcessTasks.GeometryPreparation; model.Condition = ProcessConditions.Active; } process = model; context.Update(process); return((await context.SaveChangesAsync()) > 0); }
public async Task <bool> UpdateProcess([FromServices] DataContext context, [FromBody] DisponibilizationProcess model) { var process = await context.DisponibilizationProcesses .AsNoTracking() .FirstOrDefaultAsync(x => x.DisponibilizationProcessId == model.DisponibilizationProcessId); var applicant = await context.DisponibilizationApplicants .AsNoTracking() .FirstOrDefaultAsync(x => x.ApplicantId == process.ApplicantId); process = model; if (process.Status == "Encerrar") { process.Task = ProcessTasks.Completed; if (process.TechnicalAnalysis.Status == "Aceitar") { EmailSenderDisponibilization.SendEmail(applicant.Email, "*****@*****.**", $"Notificação do Banco de Áreas PCJ - Disponibilização (Processo {process.Protocol})", applicant.FullName, EmailTypes.Completion); } if (process.TechnicalAnalysis.Status == "Arquivar") { EmailSenderDisponibilization.SendEmail(applicant.Email, "*****@*****.**", $"Notificação do Banco de Áreas PCJ - Disponibilização (Processo {process.Protocol})", applicant.FullName, EmailTypes.TechnicalAnalysisArquiveConcluded); } if (process.TechnicalAnalysis.Status == "Adequar") { EmailSenderDisponibilization.SendEmail(applicant.Email, "*****@*****.**", $"Notificação do Banco de Áreas PCJ - Disponibilização (Processo {process.Protocol})", applicant.FullName, EmailTypes.AdequacyExpiredConcluded); } process.Condition = ProcessConditions.Concluded; process.ModifiedOn = model.ModifiedOn; process.Geometries = null; process.Adequacies = null; process.TechnicalAnalysis = null; process.Applicant = null; context.Update(process); return((await context.SaveChangesAsync()) > 0); } if (process.Status == "Reanalisar" && process.Task == ProcessTasks.Completion) { process.Status = ""; process.Task = ProcessTasks.GeometryPreparation; process.Condition = ProcessConditions.Active; process.IsPendent = model.IsPendent; } process.ModifiedOn = model.ModifiedOn; process.Geometries = null; process.Adequacies = null; process.TechnicalAnalysis = null; process.Applicant = null; context.Update(process); return((await context.SaveChangesAsync()) > 0); }