예제 #1
0
        public async Task <IActionResult> Create([FromBody] CreateEmailModelRequest request)
        {
            var emailModel = new EmailModel
            {
                Id          = Guid.NewGuid(),
                Email       = request.Email,
                CreatedDate = request.CreatedDate
            };

            var created = await _emailDataService.CreateEmailModel(emailModel);

            if (created == false)
            {
                return(BadRequest());
            }

            var baseUrl     = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
            var locationUri = baseUrl + "/" + ApiRoutes.EmailClientData.Get.Replace("{modelId}", emailModel.Id.ToString());

            var response = new EmailModelResponse {
                Id = emailModel.Id
            };

            return(Created(locationUri, response));
        }
        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 EmailModel
            {
                Id          = Guid.NewGuid(),
                Email       = request.Email,
                CreatedDate = request.CreatedDate
            };

            var created = await _emailDataService.CreateEmailModel(emailModel);

            if (created == false)
            {
                return(BadRequest());
            }

            var baseUrl     = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
            var locationUri = baseUrl + "/" + ApiRoutes.EmailAdminData.Get.Replace("{modelId}", emailModel.Id.ToString());

            var response = new EmailModelResponse {
                Id = emailModel.Id
            };

            return(Created(locationUri, response));
        }
예제 #3
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));
        }