public PollEntity AddNewPollAndReturnPoll(PollModelView pollModelView, ApplicationUser applicationUser, ApplicationDbContext db)
        {
            var pollEntity = new PollEntity(pollModelView, applicationUser);

            db.Polls.Add(pollEntity);
            db.SaveChanges();
            return(pollEntity);
        }
        public ActionResult CreatePoll(PollModelView pollModelView)
        {
            if (!ModelState.IsValid)
            {
                return(View(pollModelView));
            }
            var user = appUserManager.FindById(User.Identity.GetUserId());

            if (user.CreatedPoll.Count > 10)
            {
                ModelState.AddModelError("LimitPollUser", "You can't have more than 10 poll on your account. You must delete some old one.");
                return(View(pollModelView));
            }
            var poll = pollManager.AddNewPollAndReturnPoll(pollModelView, user, db);

            return(RedirectToAction("PollVote", new { id = poll.Id }));
        }
 public PollEntity(PollModelView pollModelView, ApplicationUser user)
 {
     Question     = pollModelView.Question;
     DateTime     = DateTime.Now;
     UserChecking = pollModelView.UserChecking;
     View         = 0;
     UserCreator  = user;
     Answers      = new List <PollAnswersEntity>();
     foreach (var item in pollModelView.Answers)
     {
         Answers.Add(new PollAnswersEntity()
         {
             Answers = item, Votes = 0, Poll = this
         });
     }
     if (!string.IsNullOrEmpty(pollModelView.Password))
     {
         var privPollManager = new PrivatePollManager();
         Password = privPollManager.HashPassword(pollModelView.Password);
     }
 }