Exemple #1
0
        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));
        }