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));
        }
Esempio n. 2
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));
        }