public async Task <IActionResult> Create([FromBody] CreateEmailModelRequest request) { // TODO - fix issue, when trying to imput an email that already exists in the database, it throws an exception var emailModel = new EmailTempModel { Id = Guid.NewGuid(), Email = request.Email, CreatedDate = request.CreatedDate, VerificationKey = Guid.NewGuid().ToString() //Convert.ToBase64String(Guid.NewGuid().ToByteArray()) }; var created = await _emailTempDataService.CreateTempEmailModel(emailModel); if (created == false) { return(BadRequest()); } // TODO - here the server should send a confirmation email var verificationMessage = _emailSendingService.GenerateVerificationEmail(emailModel.Email, emailModel.VerificationKey); /* * var recipients = new List<EmailModel> * { * new EmailModel * { * Id = emailModel.Id, * Email = emailModel.Email, * CreatedDate = emailModel.CreatedDate * } * }; */ _emailSendingService.SendMail(verificationMessage, "E-pasta verifikācija", true, emailModel.Email); //recipients // end of send var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}"; var locationUri = baseUrl + "/" + ApiRoutes.VerificationEmailClientData.Get.Replace("{modelId}", emailModel.Id.ToString()); var response = new EmailModelResponse { Id = emailModel.Id }; return(Created(locationUri, response)); }
public async Task <IActionResult> PublishTransfer() { var emails = await _emailDataService.GetEmailModels(); if (emails == null) { return(NotFound()); } var records = await _recordTempService.GetTempRecords(); if (records == null) { return(NotFound()); } /* * var htmlEmailMessage = _emailSendingService.GenerateHTMLEmail(records); * _emailSendingService.SendMail(htmlEmailMessage, "Jaunas stundu izmaiņas", true, emails); */ foreach (var e in emails) { var em = new DeleteEmailModel { Email = e.Email, CreatedDate = e.CreatedDate }; var htmlEmailMessage = _emailSendingService.GenerateHTMLEmail(records, em); _emailSendingService.SendMail(htmlEmailMessage, "Jaunas stundu izmaiņas", true, em.Email); } var transfered = await _recordTempService.TransferChanges(); if (transfered == false) { return(BadRequest()); } return(Ok()); }