Exemplo n.º 1
0
        public virtual async Task <T> AddAsyn(T t)
        {
            _dbSet.Add(t);
            await _context.SaveChangesAsync();

            return(t);
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Center,Address")] Circuit circuit)
        {
            if (ModelState.IsValid)
            {
                _context.Add(circuit);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(circuit));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Year,Tour, StartDate, EndDate, HeadOfCvk")] Election election)
        {
            if (ModelState.IsValid)
            {
                _context.Add(election);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(election));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Content,Type,Submitter,SubmitterEmail,Id")] Comment comment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(comment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(comment));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("For,Id")] Vote vote)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vote);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vote));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("Name,Email,Code,Id")] Voter voter)
        {
            if (ModelState.IsValid)
            {
                _context.Add(voter);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(voter));
            //System.Security.Cryptography.MD5.Create().ComputeHash(System.Text.Encoding.ASCII.GetBytes("f36145e13e32ab59ac0304cf3d2f1994"));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("Id,Name,Address,CircuitId")] District district)
        {
            if (ModelState.IsValid)
            {
                _context.Add(district);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CircuitId"] = new SelectList(_context.Circuit, "Id", "Address", district.CircuitId);
            return(View(district));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var count = db.Citizen.Count();
                int id    = (Int32)count;

                Citizen user = await db.Citizen.FirstOrDefaultAsync(u => u.Email == model.Email);

                if (user == null)
                {
                    user = new Citizen {
                        Id    = ++id, FirstName = model.FirstName, LastName = model.LastName, MiddleName = model.MiddleName,
                        Email = model.Email, BirthDate = System.DateTime.Parse(model.BirthDate), Ipn = model.Ipn, DistrictId = model.DistrictId, Password = model.Password
                    };
                    Role userRole = await db.Role.FirstOrDefaultAsync(r => r.Name == "citizen");

                    if (userRole != null)
                    {
                        user.Role = userRole;
                    }
                    db.Citizen.Add(user);
                    await db.SaveChangesAsync();

                    await Authenticate(user);

                    return(RedirectToAction("Login", "Account"));
                }
                else
                {
                    ModelState.AddModelError("", "Некоректні логін і(або) пароль");
                }
            }
            return(View(model));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> SignUp([FromForm] string email)
        {
            email = email.Trim();

            if (_context.Voters.Any(x => x.Email == email))
            {
                return(Ok("You've already signed up"));
            }

            var code  = email.MD5();
            var voter = new Voter
            {
                Email = email,
                Code  = code
            };

            _context.Add(voter);
            await _context.SaveChangesAsync();

            return(Ok(_mailer.SendConfirmationMail(email, code)));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> CommentSubmission(Comment comment, [FromRoute(Name = "id")] int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var candidate = await _context.Candidates
                            .SingleOrDefaultAsync(m => m.Id == id);

            if (candidate == null)
            {
                return(NotFound());
            }

            if (comment == null)
            {
                return(BadRequest("Problem with submitting comment. Please message us to get this resolved ASAP."));
            }
            comment.Id        = 0;
            comment.Candidate = candidate;

            _context.Add(comment);
            await _context.SaveChangesAsync();

            if (candidate.State == CandidateState.Accepted && comment.Type == Models.Comment.CommentType.Positive)
            {
                candidate.Ready = true;
            }

            await _context.SaveChangesAsync();


            return(Json(comment));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Create(Candidate candidate)
        {
            candidate.Guid = System.Guid.NewGuid();

            if (ModelState.IsValid)
            {
                _context.Add(candidate);
                await _context.SaveChangesAsync();

                _mailer.SendCandidateConfirmation(candidate);

                return(Redirect("/Candidates"));
            }

            return(RedirectToAction(nameof(Nominate)));
        }
Exemplo n.º 12
0
 public async Task SaveAsync()
 {
     await _electionContext.SaveChangesAsync();
 }