public async Task <bool> PutInscriptionProcess( [FromServices] DataContext context, [ModelBinder(BinderType = typeof(JsonWithFilesFormDataModelBinder))] InscriptionProcess model, IFormFile enterpriseSummaryFile, IFormFile budgetWorksheetFile, IFormFile financialScheduleFile, IFormFile technicalDocumentsFile, IFormFile otherDocumentsFile) { if (ModelState.IsValid) { var process = await context.InscriptionProcesses .AsNoTracking() .FirstOrDefaultAsync(x => x.InscriptionProcessId == model.InscriptionProcessId); model.ModifiedOn = DateTime.Now; model.EnterpriseSummaryPath = enterpriseSummaryFile != null ? await AddFileAttachment(enterpriseSummaryFile, model.Type, "ResumoEmpreendimento", model.InscriptionProcessId) : process.EnterpriseSummaryPath; model.BudgetWorksheetPath = budgetWorksheetFile != null ? await AddFileAttachment(budgetWorksheetFile, model.Type, "PlanilhaOrcamento", model.InscriptionProcessId) : process.BudgetWorksheetPath; model.FinancialSchedulePath = financialScheduleFile != null ? await AddFileAttachment(financialScheduleFile, model.Type, "CronogramaFinanceiro", model.InscriptionProcessId) : process.FinancialSchedulePath; model.TechnicalDocumentsPath = technicalDocumentsFile != null ? await AddFileAttachment(technicalDocumentsFile, model.Type, "DocumentosTecnicos", model.InscriptionProcessId, "Documentos Técnicos.zip") : process.TechnicalDocumentsPath; model.OtherDocumentsPath = otherDocumentsFile != null ? await AddFileAttachment(otherDocumentsFile, model.Type, "OutrosDocumentos", model.InscriptionProcessId, "Outros Documentos.zip") : process.OtherDocumentsPath; model.Status = process.Status; model.NupProtocol = process.NupProtocol; model.Task = process.Task; model.IsPendent = process.IsPendent; model.ModifiedBy = process.ModifiedBy; model.Type = process.Type; model.CreatedOn = process.CreatedOn; context.Update(model); } return((await context.SaveChangesAsync()) > 0); }
public async Task <bool> PutDefinitiveInscriptionProcessNup( [FromServices] DataContext context, [FromBody] InscriptionProcess model) { if (ModelState.IsValid) { var process = await context.InscriptionProcesses .Include(x => x.InscriptionFinancedEnterprise) .Include(y => y.InscriptionResourceTaker) .FirstOrDefaultAsync(x => x.InscriptionProcessId == model.InscriptionProcessId); if (model.NupProtocol != process.NupProtocol) { process.NupProtocol = model.NupProtocol; process.ModifiedOn = DateTime.Now; process.ModifiedBy = ""; AdjustTask(process); context.InscriptionProcessTaskLogs.Add(new InscriptionProcessTaskLog { InscriptionProcessId = process.InscriptionProcessId, ModifiedAt = DateTime.Now, ModifiedBy = model.ModifiedBy, Task = "insercaoNup", Value = process.NupProtocol }); EmailSenderInscription.SendEmail(model.InscriptionResourceTaker.AgentEmail, "*****@*****.**", $"Ficha de inscrição (definitiva) recebida. Protocolo efetuado.", model.InscriptionResourceTaker.AgentName, EmailTypes.DefinitiveInscriptionNupInsert, process.InscriptionResourceTaker.CompanyName, process.InscriptionFinancedEnterprise.Title, process.NupProtocol); context.Update(process); } } return((await context.SaveChangesAsync()) > 0); }
public async Task <ActionResult> PostInscriptionProcess( [FromServices] DataContext context, [ModelBinder(BinderType = typeof(JsonWithFilesFormDataModelBinder))] InscriptionProcess model, IFormFile enterpriseSummaryFile, IFormFile budgetWorksheetFile, IFormFile financialScheduleFile, IFormFile technicalDocumentsFile, IFormFile otherDocumentsFile) { if (ModelState.IsValid) { try { model.CreatedOn = DateTime.Now; model.ModifiedOn = DateTime.Now; model.ModifiedBy = ""; AdjustTask(model); context.InscriptionProcesses.Add(model); await context.SaveChangesAsync(); model.EnterpriseSummaryPath = await AddFileAttachment(enterpriseSummaryFile, model.Type, "ResumoEmpreendimento", model.InscriptionProcessId); model.BudgetWorksheetPath = await AddFileAttachment(budgetWorksheetFile, model.Type, "PlanilhaOrcamento", model.InscriptionProcessId); model.FinancialSchedulePath = await AddFileAttachment(financialScheduleFile, model.Type, "CronogramaFinanceiro", model.InscriptionProcessId); model.TechnicalDocumentsPath = await AddFileAttachment(technicalDocumentsFile, model.Type, "DocumentosTecnicos", model.InscriptionProcessId, "Documentos Técnicos.zip"); model.OtherDocumentsPath = await AddFileAttachment(otherDocumentsFile, model.Type, "OutrosDocumentos", model.InscriptionProcessId, "Outros Documentos.zip"); context.InscriptionProcesses.Update(model); if (model.Type == "preinscricao") { EmailSenderInscription.SendEmail(model.InscriptionResourceTaker.AgentEmail, "*****@*****.**", "Ficha de inscrição enviada com sucesso (pré qualificação).", model.InscriptionResourceTaker.AgentName, EmailTypes.PreInscriptionCompletion, model.InscriptionResourceTaker.CompanyName, model.InscriptionFinancedEnterprise.Title); } if (model.Type == "inscricaodefinitiva") { EmailSenderInscription.SendEmail(model.InscriptionResourceTaker.AgentEmail, "*****@*****.**", $"Ficha de inscrição (definitiva) enviada com sucesso.", model.InscriptionResourceTaker.AgentName, EmailTypes.DefinitiveInscriptionCompletion, model.InscriptionResourceTaker.CompanyName, model.InscriptionFinancedEnterprise.Title); } await context.SaveChangesAsync(); return(Ok()); } catch (Exception e) { throw new Exception("Erro: " + e.Message); } } else { return(BadRequest(ModelState)); } }
public async Task <bool> PutPreInscriptionProcessStatus( [FromServices] DataContext context, [FromBody] InscriptionProcess model) { if (ModelState.IsValid) { var process = await context.InscriptionProcesses .Include(x => x.InscriptionFinancedEnterprise) .Include(y => y.InscriptionResourceTaker) .FirstOrDefaultAsync(x => x.InscriptionProcessId == model.InscriptionProcessId); if (model.Status != process.Status) { process.Status = model.Status; process.ModifiedOn = DateTime.Now; process.ModifiedBy = ""; AdjustTask(process); if (process.Status == "Pendente") { EmailSenderInscription.SendEmail(model.InscriptionResourceTaker.AgentEmail, "*****@*****.**", $"O empreendimento possui pendências.", model.InscriptionResourceTaker.AgentName, EmailTypes.PreInscriptionAnalyzis, process.InscriptionResourceTaker.CompanyName, process.InscriptionFinancedEnterprise.Title, process.NupProtocol); } else if (process.Status == "Qualificado") { process.DefinitiveInscriptionProcessGuidLink = Guid.NewGuid().ToString(); EmailSenderInscription.SendEmail(model.InscriptionResourceTaker.AgentEmail, "*****@*****.**", $"O empreendimento foi pré qualificado.", model.InscriptionResourceTaker.AgentName, EmailTypes.PreInscriptionDeferred, process.InscriptionResourceTaker.CompanyName, process.InscriptionFinancedEnterprise.Title, process.NupProtocol, process.DefinitiveInscriptionProcessGuidLink); } else if (process.Status == "Indeferido") { EmailSenderInscription.SendEmail(model.InscriptionResourceTaker.AgentEmail, "*****@*****.**", $"O empreendimento foi indeferido.", model.InscriptionResourceTaker.AgentName, EmailTypes.PreInscriptionRejected, process.InscriptionResourceTaker.CompanyName, process.InscriptionFinancedEnterprise.Title, process.NupProtocol); } context.InscriptionProcessTaskLogs.Add(new InscriptionProcessTaskLog { InscriptionProcessId = process.InscriptionProcessId, ModifiedAt = DateTime.Now, ModifiedBy = model.ModifiedBy, Task = "insercaoStatus", Value = process.Status }); context.Update(process); } } return((await context.SaveChangesAsync()) > 0); }
private void AdjustTask(InscriptionProcess process) { if (String.IsNullOrEmpty(process.NupProtocol)) { process.Task = ProcessTasks.InscriptionNup; } else if (process.Status == "Pendente" || String.IsNullOrEmpty(process.Status)) { process.Task = ProcessTasks.InscriptionStatus; } else { process.Task = ""; } process.IsPendent = String.IsNullOrEmpty(process.Task) ? false : true; }
public async Task <bool> DettachUser([FromServices] DataContext context, [FromBody] InscriptionProcess model) { try { var process = await context.InscriptionProcesses .Include(x => x.InscriptionFinancedEnterprise) .Include(y => y.InscriptionResourceTaker) .FirstOrDefaultAsync(x => x.InscriptionProcessId == model.InscriptionProcessId); process.ModifiedBy = ""; context.Update(process); return((await context.SaveChangesAsync()) > 0); } catch (Exception e) { return(false); } }
//CRUD METHODS //Create--------- public async Task <InscriptionProcessResponse> SaveAsync(int userId, InscriptionProcess inscriptionProcess) { //find user if (await FindUserById(userId) == null) { return(new InscriptionProcessResponse($"User with id: {userId} not found")); } //now add try { await _inscriptionProcessRepository.AddAsync(userId, inscriptionProcess); await _unitOfWork.CompleteAsync(); return(new InscriptionProcessResponse(inscriptionProcess)); } catch (Exception ex) { return(new InscriptionProcessResponse($"An error ocurred while saving the inscriptionProcess: {ex.Message}")); } }
public void Remove(InscriptionProcess inscriptionProcess) { _context.InscriptionProcesses.Remove(inscriptionProcess); }
public async Task AddAsync(int userId, InscriptionProcess inscriptionProcess) { inscriptionProcess.UserId = userId; await _context.InscriptionProcesses.AddAsync(inscriptionProcess); }