Ejemplo n.º 1
0
        public ActionResult SendMail(vm_SendMail sendmail)
        {
            if (!string.IsNullOrEmpty(sendmail.Subscriber.Name) && !string.IsNullOrEmpty(sendmail.Subscriber.Email))
            {
                var newsub = new Subscriber();

                newsub.ID = Guid.NewGuid();
                newsub.Name = sendmail.Subscriber.Name;
                newsub.Email = sendmail.Subscriber.Email;
                newsub.City = sendmail.Subscriber.City;
                newsub.SubscriberType = sendmail.Subscriber.SubscriberType;

                _subscriberRepo.Save(newsub);
                ViewBag.StatusMessage = "Success";
                return View();
             }

            if (!string.IsNullOrEmpty(sendmail.Newsletter.Subject) && !string.IsNullOrEmpty(sendmail.Newsletter.Message))
            {
                sendmail.Newsletter.ID = Guid.NewGuid();
                sendmail.Newsletter.Date = DateTime.Now;

                _newsletterRepo.Save(sendmail.Newsletter);

                List<Subscriber> emails = _subscriberRepo.FindAll(e => e.SubscriberType == sendmail.Subscriber.SubscriberType).ToList();

                foreach (var email in emails)
                {
                    try
                    {
                        MailMessage mail = new MailMessage();
                        SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                        mail.From = new MailAddress("*****@*****.**");
                        mail.To.Add(email.Email);
                        mail.Subject = sendmail.Newsletter.Subject;
                        mail.Body = sendmail.Newsletter.Message;

                        SmtpServer.Port = 587;
                        SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "jctest123456");
                        SmtpServer.EnableSsl = true;

                        SmtpServer.Send(mail);
                        ViewBag.StatusMessage = "Mail skickat";
                    }
                    catch (Exception ex)
                    {
                        ViewBag.StatusMessage = ex;
                    }
                }
                return View();

            }
            return View();
        }
Ejemplo n.º 2
0
 public ActionResult Index(Subscriber subscriber)
 {
     if (ModelState.IsValid)
     {
         var existing = _subscriberRepo.FindAll(s => s.Email == subscriber.Email);
             subscriber.ID = Guid.NewGuid();
             _subscriberRepo.Save(subscriber);
             ViewBag.SaveMessage = "Prenumeration påbörjad!";
             var vm = new vm_PostSubscriber();
             vm.Post = _postRepo.FindAll().Take(3).ToList();
             return View(vm);
     }
     else
     {
         ViewBag.SaveMessage = "Subscription unsuccessful";
         return View();
     }
 }
Ejemplo n.º 3
0
        public ActionResult Unsubscribe(Subscriber subscriber)
        {
            if (ModelState.IsValid)
            {
                Subscriber unsubscriber = _subscriberRepo.FindAll(e => e.Email == subscriber.Email && e.Name == subscriber.Name).FirstOrDefault();

                if (unsubscriber == null)
                {
                    TempData["error"] = "Namn eller Email hittades inte";
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    _subscriberRepo.Delete(unsubscriber);
                    TempData["error"] = "Du är nu inte längre registrerad och kommer inte få nyhetsbrev längre!";
                    return RedirectToAction("Index", "Home");
                }
            }
            else
            {
                TempData["error"] = "Hoppsan, där var det nåt som gick fel";
                return RedirectToAction("Index", "Home");
            }
        }
Ejemplo n.º 4
0
        public ActionResult CreateAnswer(vm_AnswerEventQuestion Answer)
        {
            List<string> words = Answer.Words.Split(',').ToList();
            foreach (var singleword in words)
            {
                var lowerword = singleword.ToLower().Trim();
                var word = _wordRepository.FindAll(w => w.Word == lowerword).FirstOrDefault();
                if (word != null)
                {
                    word.WordCount = word.WordCount + 1;
                    _wordRepository.Save(word);
                }
                else
                {
                    var newword = new Words();
                    newword.WordCount = 1;
                    newword.ID = Guid.NewGuid();
                    newword.Word = lowerword;
                    _wordRepository.Save(newword);
                }
            }
            var eventQuestionIDs = Answer.EventQuestionIDs.Split(';').Select(e => new Guid(e)).ToList();
            List<int> ar = new List<int>();
            for(int n =0; n < Answer.StringAnswers.Length; n++)
            {
                ar.Add(int.Parse(Answer.StringAnswers[n].ToString()));
            }
            int i = 0;
            foreach (var id in eventQuestionIDs)
            {
                var qAnswer = new Answer
                {
                    Age = Answer.Age,
                    Username = Answer.Username,
                    Email = Answer.Email,
                    ID = Guid.NewGuid(),
                    Gender = Answer.Gender,
                    EventQuestionID = id,
                    Score = ar[i]
                };
                i++;
                try
                    {
                        _answerRepository.Save(qAnswer);
                    }
                    catch (DbEntityValidationException ex)
                    {
                    StringBuilder sb = new StringBuilder();

                    foreach (var failure in ex.EntityValidationErrors)
                    {
                        sb.AppendFormat("{0} failed validation\n",
                        failure.Entry.Entity.GetType());

                        foreach (var error in failure.ValidationErrors)
                        {
                        sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                        sb.AppendLine();
                        }
                    }
                        throw new DbEntityValidationException("Entity Validation Failed - errors follow:\n" + sb.ToString(), ex);
                }
            }
            if (!string.IsNullOrEmpty(Answer.Email))
            {
                Subscriber subscriber = _subScriberRepository.FindAll(s => s.Email == Answer.Email).FirstOrDefault();
                if(subscriber == null){
                    subscriber = new Subscriber();
                    subscriber.Email = Answer.Email;
                    subscriber.City = Answer.City;
                    subscriber.Name = Answer.Username;
                    subscriber.ID = Guid.NewGuid();
                    _subScriberRepository.Save(subscriber);
                }
            }
            return RedirectToAction("CreateAnswer", "Event");
        }