public IActionResult NewsLetter([FromBody] AddRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(ModelState));
            }

            var response = new BaseResponse <Guid>();

            var item = new Newsletter
            {
                Email = request.Email,
            };

            newsletterRepo.Add(item);
            response.Message = "Kayıt başarıyla eklenmiştir.";
            response.Data    = item.Id;

            var MailBody = "HepsiSef bize ulaşın + E-Bülten" + "\n " + " " + item.Email + "\n";

            List <AdminMailMM> Admins = new List <AdminMailMM>();

            Admins = userRepo.GetBy(x => x.Role == Role.Admin).Select(x => new AdminMailMM
            {
                Email = x.Email
            }).ToList();

            foreach (var mail in Admins)
            {
                MailManager.Send(MailBody, mail.Email);
            }

            return(Ok(response));
        }
예제 #2
0
        public async Task HandleAsync(SubscribeToTheNewsletter command, CancellationToken cancellationToken = default)
        {
            var subscriber = Subscriber.Subscribe(command.Id, command.Email);
            var discount   = _discountCodeGenerator.GenerateCodeForSubscriber(_identityProvider.Next(), subscriber.Id);
            await _newsletterRepository.Add(subscriber, cancellationToken);

            await _discountRepository.Add(discount, cancellationToken);

            await _emailService.SendEmailWithDiscountCode(discount.GetCode(), cancellationToken);
        }
예제 #3
0
        bool INewsletterHelper.TrySave(Models.Home.NewsletterModel model)
        {
            string mail        = model.Email;
            int    selectedId  = model.selectedTypeOfNews;
            var    currentTime = DateTime.Now;

            var modelToSave = new Newsletter()
            {
                email        = mail,
                TypeOfNewsId = selectedId,
                InsertTime   = currentTime
            };

            _newsletterRepository.Add(modelToSave);

            return(true);
        }
예제 #4
0
        public IActionResult Register([FromBody] NewsletterCreateViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Newsletter newsletter = _newsletterRepository.FindUniqueByEmail(model.Email);

                    if (newsletter != null)
                    {
                        ModelState.AddModelError("Email", "Email já cadastrado");

                        IDictionary <string, string> error = new Dictionary <string, string>();
                        error.Add("email", "Email já cadastrado");

                        return(StatusCode(422, new {
                            StatusCode = 442,
                            Message = "Unprocessable entity",
                            Errors = error
                        }));
                    }

                    Newsletter obj = new Newsletter
                    {
                        Email     = model.Email,
                        Name      = model.Name,
                        CreatedAt = DateTime.Now,
                    };

                    _newsletterRepository.Add(obj);
                    _newsletterRepository.SaveChanges();

                    HttpContext.Response.StatusCode = 201;

                    return(StatusCode(201, new {
                        StatusCode = 201,
                        Message = "Created",
                        Data = obj
                    }));
                }

                IDictionary <string, string> errorList = new Dictionary <string, string>();

                foreach (var error in ModelState)
                {
                    if (error.Value.Errors.Any())
                    {
                        errorList.Add(error.Key, error.Value.Errors.First().ErrorMessage);
                    }
                }

                return(StatusCode(422, new {
                    StatusCode = 422,
                    Message = "Unprocessable entity",
                    Error = errorList
                }));
            }
            catch (Exception exception)
            {
                _logger.LogError("Newsletter api register error: " + exception);
                return(StatusCode(500));
            }
        }