public ActionResult Create([Bind(Include = "ID,FirstName,Surname,VotingId")] Candidate candidate)
        {
            if (ModelState.IsValid)
            {
                db.Candidates.Add(candidate);
                db.SaveChanges();
                return(RedirectToAction("Details/" + candidate.VotingId, "Votings"));
            }

            ViewBag.VotingId = candidate.VotingId;
            return(View(candidate));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // Aby uzyskać więcej informacji o sposobie włączania potwierdzania konta i resetowaniu hasła, odwiedź stronę https://go.microsoft.com/fwlink/?LinkID=320771
                    // Wyślij wiadomość e-mail z tym łączem
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Potwierdź konto", "Potwierdź konto, klikając <a href=\"" + callbackUrl + "\">tutaj</a>");
                    Profile profile = new Profile {
                        Login = model.Email
                    };
                    VotingContext db = new VotingContext();
                    db.Profiles.Add(profile);
                    db.SaveChanges();

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // Dotarcie do tego miejsca wskazuje, że wystąpił błąd, wyświetl ponownie formularz
            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult DetailsP(int code, List <string> candidates)
        {
            Vote vote = db.Votes.
                        Include(v => v.Voting).
                        Include(v => v.Voting.Candidates)
                        .Where(v => v.ID == code).FirstOrDefault();
            List <int> candidateID = new List <int>();

            foreach (var item in candidates)
            {
                if (!item.Equals("false"))
                {
                    candidateID.Add(int.Parse(item));
                }
            }
            vote.Voted = true;
            if (candidateID.Count <= vote.Voting.NumberOfWinners)
            {
                List <Candidate> candidates1 = vote.Voting.Candidates;
                foreach (var item in candidates1)
                {
                    if (candidateID.Any(c => c == item.ID))
                    {
                        item.VotesCount++;
                    }
                }
                ViewBag.Text = "Oddano głos";
            }
            else
            {
                ViewBag.Text = "Oddano głos nieważny";
            }
            db.SaveChanges();
            return(View());
        }
Exemplo n.º 4
0
        public ActionResult Create([Bind(Include = "ID,Name,NumberOfWinners,NumberOfVoters")] Voting voting)
        {
            if (ModelState.IsValid)
            {
                db.Votings.Add(voting);
                for (int i = 0; i < voting.NumberOfVoters; i++)
                {
                    string code;
                    do
                    {
                        code = "";
                        for (int j = 0; j < 6; j++)
                        {
                            int choice = random.Next(3);
                            switch (choice)
                            {
                            case 0:
                                code += (char)random.Next(48, 58);
                                break;

                            case 1:
                                code += (char)random.Next(65, 91);
                                break;

                            case 2:
                                code += (char)random.Next(97, 123);
                                break;

                            default:
                                break;
                            }
                        }
                    } while (db.Votes.FirstOrDefault(v => v.Code == code) != null);

                    Vote vote = new Vote()
                    {
                        Voting = voting, Code = code
                    };
                    db.Votes.Add(vote);
                }
                db.SaveChanges();
                return(RedirectToAction("Details/" + voting.ID));
            }

            return(View(voting));
        }
Exemplo n.º 5
0
        // GET: Voting
        public async Task <IActionResult> Count(int?id)
        {
            Person person = _context.People.Find(id);

            person.Count++;
            _context.Update(person);
            _context.SaveChanges();

            return(Redirect("/Voting"));
        }
Exemplo n.º 6
0
        public IActionResult AddLikes(string wname, string loc, string typ)
        {
            if (!_context.WeatherSuppliers.Any(x => x.Name == wname))
            {
                var w = new WeatherSupplier {
                    Name = wname
                };
                _context.WeatherSuppliers.Add(w);
                _context.Votes.Add(new Vote {
                    Likes = typ == "like" ? 1 : -1, Supplier = w, Location = loc
                });
            }
            else if (!_context.Votes.Any(x => x.Supplier.Name == wname))
            {
                var w = _context.WeatherSuppliers.First(x => x.Name == wname);
                _context.Votes.Add(new Vote {
                    Supplier = w, Likes = typ == "like" ? 1 : -1, Location = loc
                });
            }
            else
            {
                var vote = _context.Votes.First(x => x.Supplier.Name == wname);
                if (typ == "like")
                {
                    vote.Likes++;
                }
                else
                {
                    vote.Likes--;
                }
            }

            _context.SaveChanges();
            var sortedWeather = SortWeathers(allWeathers.Weathers);

            allWeathers.Weathers = sortedWeather;
            return(View("Like", allWeathers));
        }
Exemplo n.º 7
0
        private static void SeedOptions(this VotingContext context)
        {
            if (context.Options.Any())
            {
                return;
            }
            context.Options.AddRange(
                new Option {
                Id = 1, Text = "Da",
            },
                new Option {
                Id = 2, Text = "Nu",
            },
                new Option {
                Id = 3, Text = "Nu stiu",
            },
                new Option {
                Id = 4, Text = "Dark Island",
            },
                new Option {
                Id = 5, Text = "London Pride",
            },
                new Option {
                Id = 6, Text = "Zaganu",
            },
                new Option {
                Id = 7, Text = "Transmisia manualã",
            },
                new Option {
                Id = 8, Text = "Transmisia automatã",
            },
                new Option {
                Id = 9, Text = "Altele (specificaţi)", IsFreeText = true
            },
                new Option {
                Id = 10, Text = "Metrou"
            },
                new Option {
                Id = 11, Text = "Tramvai"
            },
                new Option {
                Id = 12, Text = "Autobuz"
            }
                );

            context.SaveChanges();
        }
Exemplo n.º 8
0
        private static void SeedSectiune(this VotingContext context)
        {
            if (context.Sectiune.Any())
            {
                return;
            }

            context.Sectiune.AddRange(
                new Sectiune {
                IdSectiune = 1, CodSectiune = "B", Descriere = "Despre Bere"
            },
                new Sectiune {
                IdSectiune = 2, CodSectiune = "C", Descriere = "Descriere masini"
            }
                );

            context.SaveChanges();
        }
Exemplo n.º 9
0
        private static void SeedFormSections(this VotingContext context)
        {
            if (context.FormSections.Any())
            {
                return;
            }

            context.FormSections.AddRange(
                new FormSection {
                Id = 1, Code = "B", Description = "Despre Bere"
            },
                new FormSection {
                Id = 2, Code = "C", Description = "Description masini"
            }
                );

            context.SaveChanges();
        }
        private static void SeedNGOs(this VotingContext context)
        {
            if (context.Ngos.Any())
            {
                return;
            }

            context.Ngos.Add(new Ngo
            {
                Id = 1, Name = "Code4Romania", Organizer = true, ShortName = "C4R"
            });
            context.Ngos.Add(new Ngo
            {
                Id        = 2,
                Name      = "Guest NGO",
                Organizer = false,
                ShortName = "GUE"
            });
            context.SaveChanges();
        }
Exemplo n.º 11
0
        private static void SeedVersions(this VotingContext context)
        {
            if (context.VersiuneFormular.Any())
            {
                return;
            }

            context.VersiuneFormular.AddRange(
                new VersiuneFormular {
                CodFormular = "A", VersiuneaCurenta = 1
            },
                new VersiuneFormular {
                CodFormular = "B", VersiuneaCurenta = 1
            },
                new VersiuneFormular {
                CodFormular = "C", VersiuneaCurenta = 1
            }
                );

            context.SaveChanges();
        }
Exemplo n.º 12
0
        private static void SeedVersions(this VotingContext context)
        {
            if (context.FormVersions.Any())
            {
                return;
            }

            context.FormVersions.AddRange(
                new FormVersion {
                Code = "A", CurrentVersion = 1
            },
                new FormVersion {
                Code = "B", CurrentVersion = 1
            },
                new FormVersion {
                Code = "C", CurrentVersion = 1
            }
                );

            context.SaveChanges();
        }
Exemplo n.º 13
0
        public ActionResult Index(VotingResults[] votingResults)
        {
            List <MatchResults> matchesList = new List <MatchResults>();

            foreach (var item in db.MatchResults)
            {
                VotingResults vr = votingResults.Where(x => x.Id == item.Id).First();
                if (vr.Value == 1)
                {
                    item.HomeWon++;
                }
                if (vr.Value == 2)
                {
                    item.GuestWon++;
                }
                if (vr.Value == 3)
                {
                    item.Draw++;
                }
            }
            db.SaveChanges();
            return(RedirectToAction("Stats"));
        }
 public Candidate AddCandidate(Candidate candidate)
 {
     _votingContext.Candidates.Add(candidate);
     _votingContext.SaveChanges();
     return(candidate);
 }
Exemplo n.º 15
0
        private static void SeedQuestions(this VotingContext context, char idFormular)
        {
            if (context.Questions.Any(a => a.FormCode == idFormular.ToString()))
            {
                return;
            }

            context.Questions.AddRange(
                // primul formular
                new Question
            {
                Id                 = idFormular * 20 + 1,
                FormCode           = idFormular.ToString(),
                IdSection          = 1, //B
                QuestionType       = QuestionType.SingleOption,
                Text               = $"{idFormular}: Iti place berea? (se alege o singura optiune selectabila)",
                OptionsToQuestions = new List <OptionToQuestion>
                {
                    new OptionToQuestion {
                        Id = idFormular * 20 + 1, IdOption = 1
                    },
                    new OptionToQuestion {
                        Id = idFormular * 20 + 2, IdOption = 2, Flagged = true
                    },
                    new OptionToQuestion {
                        Id = idFormular * 20 + 3, IdOption = 3
                    }
                }
            },
                new Question
            {
                Id                 = idFormular * 20 + 2,
                FormCode           = idFormular.ToString(),
                IdSection          = 1,            //B
                QuestionType       = QuestionType.MultipleOption,
                Text               = $"{idFormular}: Ce tipuri de bere iti plac? (se pot alege optiuni multiple)",
                OptionsToQuestions = new List <OptionToQuestion>
                {
                    new OptionToQuestion {
                        Id = idFormular * 20 + 4, IdOption = 4, Flagged = true
                    },
                    new OptionToQuestion {
                        Id = idFormular * 20 + 5, IdOption = 5
                    },
                    new OptionToQuestion {
                        Id = idFormular * 20 + 6, IdOption = 6
                    }
                }
            },
                new Question
            {
                Id                 = idFormular * 20 + 3,
                FormCode           = idFormular.ToString(),
                IdSection          = 2, //C
                QuestionType       = QuestionType.SingleOptionWithText,
                Text               = $"{idFormular}: Ce tip de transmisie are masina ta? (se poate alege O singura optiune selectabila + text pe O singura optiune)",
                OptionsToQuestions = new List <OptionToQuestion>
                {
                    new OptionToQuestion {
                        Id = idFormular * 20 + 7, IdOption = 7, Flagged = true
                    },
                    new OptionToQuestion {
                        Id = idFormular * 20 + 8, IdOption = 8
                    },
                    new OptionToQuestion {
                        Id = idFormular * 20 + 9, IdOption = 9
                    }
                }
            },
                new Question
            {
                Id                 = idFormular * 20 + 4,
                FormCode           = idFormular.ToString(),
                IdSection          = 2, //C
                QuestionType       = QuestionType.MultipleOptionWithText,
                Text               = $"{idFormular}: Ce mijloace de transport folosesti sa ajungi la birou? (se pot alege mai multe optiuni + text pe O singura optiune)",
                OptionsToQuestions = new List <OptionToQuestion>
                {
                    new OptionToQuestion {
                        Id = idFormular * 20 + 10, IdOption = 10, Flagged = true
                    },
                    new OptionToQuestion {
                        Id = idFormular * 20 + 11, IdOption = 11
                    },
                    new OptionToQuestion {
                        Id = idFormular * 20 + 12, IdOption = 12
                    },
                    new OptionToQuestion {
                        Id = idFormular * 20 + 13, IdOption = 9
                    }
                }
            }
                );

            context.SaveChanges();
        }
Exemplo n.º 16
0
        private static void SeedQuestions(this VotingContext context, char idFormular)
        {
            if (context.Intrebare.Any(a => a.CodFormular == idFormular.ToString()))
            {
                return;
            }

            context.Intrebare.AddRange(
                // primul formular
                new Intrebare
            {
                IdIntrebare       = idFormular * 20 + 1,
                CodFormular       = idFormular.ToString(),
                IdSectiune        = 1, //B
                IdTipIntrebare    = TipIntrebareEnum.OSinguraOptiune,
                TextIntrebare     = $"{idFormular}: Iti place berea? (se alege o singura optiune selectabila)",
                RaspunsDisponibil = new List <RaspunsDisponibil>
                {
                    new RaspunsDisponibil {
                        IdRaspunsDisponibil = idFormular * 20 + 1, IdOptiune = 1
                    },
                    new RaspunsDisponibil {
                        IdRaspunsDisponibil = idFormular * 20 + 2, IdOptiune = 2, RaspunsCuFlag = true
                    },
                    new RaspunsDisponibil {
                        IdRaspunsDisponibil = idFormular * 20 + 3, IdOptiune = 3
                    }
                }
            },
                new Intrebare
            {
                IdIntrebare       = idFormular * 20 + 2,
                CodFormular       = idFormular.ToString(),
                IdSectiune        = 1,              //B
                IdTipIntrebare    = TipIntrebareEnum.OptiuniMultiple,
                TextIntrebare     = $"{idFormular}: Ce tipuri de bere iti plac? (se pot alege optiuni multiple)",
                RaspunsDisponibil = new List <RaspunsDisponibil>
                {
                    new RaspunsDisponibil {
                        IdRaspunsDisponibil = idFormular * 20 + 4, IdOptiune = 4, RaspunsCuFlag = true
                    },
                    new RaspunsDisponibil {
                        IdRaspunsDisponibil = idFormular * 20 + 5, IdOptiune = 5
                    },
                    new RaspunsDisponibil {
                        IdRaspunsDisponibil = idFormular * 20 + 6, IdOptiune = 6
                    }
                }
            },
                new Intrebare
            {
                IdIntrebare       = idFormular * 20 + 3,
                CodFormular       = idFormular.ToString(),
                IdSectiune        = 2, //C
                IdTipIntrebare    = TipIntrebareEnum.OSinguraOptiuneCuText,
                TextIntrebare     = $"{idFormular}: Ce tip de transmisie are masina ta? (se poate alege O singura optiune selectabila + text pe O singura optiune)",
                RaspunsDisponibil = new List <RaspunsDisponibil>
                {
                    new RaspunsDisponibil {
                        IdRaspunsDisponibil = idFormular * 20 + 7, IdOptiune = 7, RaspunsCuFlag = true
                    },
                    new RaspunsDisponibil {
                        IdRaspunsDisponibil = idFormular * 20 + 8, IdOptiune = 8
                    },
                    new RaspunsDisponibil {
                        IdRaspunsDisponibil = idFormular * 20 + 9, IdOptiune = 9
                    }
                }
            },
                new Intrebare
            {
                IdIntrebare       = idFormular * 20 + 4,
                CodFormular       = idFormular.ToString(),
                IdSectiune        = 2, //C
                IdTipIntrebare    = TipIntrebareEnum.OptiuniMultipleCuText,
                TextIntrebare     = $"{idFormular}: Ce mijloace de transport folosesti sa ajungi la birou? (se pot alege mai multe optiuni + text pe O singura optiune)",
                RaspunsDisponibil = new List <RaspunsDisponibil>
                {
                    new RaspunsDisponibil {
                        IdRaspunsDisponibil = idFormular * 20 + 10, IdOptiune = 10, RaspunsCuFlag = true
                    },
                    new RaspunsDisponibil {
                        IdRaspunsDisponibil = idFormular * 20 + 11, IdOptiune = 11
                    },
                    new RaspunsDisponibil {
                        IdRaspunsDisponibil = idFormular * 20 + 12, IdOptiune = 12
                    },
                    new RaspunsDisponibil {
                        IdRaspunsDisponibil = idFormular * 20 + 13, IdOptiune = 9
                    }
                }
            }
                );

            context.SaveChanges();
        }
 public Poll AddPoll(Poll poll)
 {
     _votingContext.Polls.Add(poll);
     _votingContext.SaveChanges();
     return(poll);
 }
 public Voter AddVoter(Voter voter)
 {
     _votingContext.Voters.Add(voter);
     _votingContext.SaveChanges();
     return(voter);
 }
 public Admin AddAdmin(Admin admin)
 {
     _votingContext.Admins.Add(admin);
     _votingContext.SaveChanges();
     return(admin);
 }