Esempio n. 1
0
        public static Boolean SavePoll(PollResult poll, SafeAdmission admission, HttpRequestBase request)
        {
            var voterId = GetVoterState(admission, request);

            try
            {
                using (var Db = new Repository())
                {
                    poll.PollResultQuestions.ForEach(el =>
                    {
                        el.Answers.ForEach(an =>
                        {
                            Db.Context.Results.Add(new EFModel.Result()
                            {
                                AnswerId = Int32.Parse(an), QuestionId = Int32.Parse(el.Id), VoterId = (Int32)voterId, ProjectId = Db.Context.Projects.Where(x => x.UrlCode == admission.projectUrl).Select(x => x.Id).FirstOrDefault()
                            });
                        });
                    });
                    Db.Save();
                }
                return(true);
            }
            catch (Exception ex)
            {
                using (var Db = new Repository())
                {
                    var v = Db.Context.ProjectAccessVoters.Where(x => x.Id == voterId).FirstOrDefault();
                    v.IsUsed  = false;
                    v.VotedOn = null;
                    Db.Save();
                }
                return(false);
            }
        }
Esempio n. 2
0
        private static Int32?GetVoterState(SafeAdmission admission, HttpRequestBase request)
        {
            if (admission.UserIdentity != null)
            {
                using (var Db = new Repository())
                {
                    var v = Db.Context.ProjectAccessVoters.Where(x => x.Id == admission.UserIdentity).FirstOrDefault();
                    v.IsUsed  = true;
                    v.VotedOn = DateTime.Now;
                    Db.Save();
                }
                return(admission.UserIdentity);
            }
            HttpCookie cookie = request.Cookies[MemberWorker.GetAnonymousCookieName()];

            if (cookie != null)
            {
                var val   = cookie["Data"];
                var voter = new ProjectAccessVoter();
                using (var Db = new Repository())
                {
                    UserSet user = new UserSet()
                    {
                        CookieValue = val
                    };
                    voter = new ProjectAccessVoter()
                    {
                        ProjectId = Db.Context.Projects.Where(x => x.UrlCode == admission.projectUrl).Select(x => x.Id).FirstOrDefault(), UserSet = user, IsUsed = true, ModifiedOn = DateTime.Now
                    };
                    voter.VotedOn = DateTime.Now;
                    Db.Context.ProjectAccessVoters.Add(voter);
                    Db.Save();
                }
                return(voter.Id);
            }
            else
            {
                return(null);
            }
        }