Beispiel #1
0
        public JsonResult AddToNewsletter(string email)
        {
            if (email == null)
            {
                return(Json(new { success = false, responseText = _localizer["Please enter a valid email address."].ToString() }));
            }

            var emailDbcount = _emailNewsletterRepo.GetAllEntities().Count(x => x.EmailAddress.Equals(email));

            if (emailDbcount > 0)
            {
                return(Json(new { success = false, responseText = _localizer["You are already registered to our email newsletter."].ToString() }));
            }

            else
            {
                #region IP Kontrolü
                string remoteIpAddress = HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();

                if (Request.Headers.ContainsKey("X-Forwarded-For"))
                {
                    remoteIpAddress = Request.Headers["X-Forwarded-For"];
                }
                #endregion

                EmailNewsletter newsLetter = new EmailNewsletter
                {
                    EmailAddress = email,
                    UserIp       = remoteIpAddress
                };

                _emailNewsletterRepo.CreateEntity(newsLetter);
                EmailToAdminForNewsletterRecord(email);
                return(Json(new { success = true, responseText = _localizer["Your subscription to the e-mail newsletter is successful. Thank you."].ToString() }));
            }
        }
        //[NonAction]
        public JsonResult AddToNewsletter(string email)
        {
            if (email == null)
            {
                return(Json(new { success = false, responseText = _localizer["Lütfen geçerli bir eposta adresi giriniz."].ToString() }));
            }

            var emailDbcount = _emailNewsletterRepo.AnyEntity(x => x.EmailAddress.Equals(email));

            if (emailDbcount)
            {
                return(Json(new { success = false, responseText = _localizer["Eposta aboneliğiniz mevcuttur."].ToString() }));
            }

            else
            {
                #region IP Kontrolü
                string remoteIpAddress = HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();

                if (Request.Headers.ContainsKey("X-Forwarded-For"))
                {
                    remoteIpAddress = Request.Headers["X-Forwarded-For"];
                }
                #endregion

                EmailNewsletter newsLetter = new EmailNewsletter
                {
                    EmailAddress = email,
                    UserIp       = remoteIpAddress
                };

                _emailNewsletterRepo.CreateEntity(newsLetter);

                return(Json(new { success = true, responseText = _localizer["E-posta adresiniz bültenimize kaydedilmiştir. Teşekkür ederiz."].ToString() }));
            }
        }