public ResultVM CreateCandidate(CandidateVM model) { Result.Success = false; // generate userId string newVoterId = GenerateUserId(); var candidate = new VoteUserDTO { UserId = model.UserId, VoterId = newVoterId, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, Phone = model.Phone, PositionId = model.PositionId, ImageString = model.ImageString, DateAddedUtc = DateTime.UtcNow }; _db.VoteUsers.Add(candidate); _db.SaveChanges(); // add user to role AddToRole(candidate.UserId, "Candidate"); //this.AddToRole(candidate.UserId, "Candidate"); Result.Success = true; return(Result); }
public VoterVM(VoteUserDTO row) { UserId = row.UserId; VoterId = row.VoterId; FirstName = row.FirstName; LastName = row.LastName; Email = row.Email; Phone = row.Phone; }
public CandidateVM(VoteUserDTO row) { UserId = row.UserId; VoterId = row.VoterId; FirstName = row.FirstName; LastName = row.LastName; Phone = row.Phone; Email = row.Email; PositionId = row.PositionId; ImageString = row.ImageString; }
public ActionResult Edit(string voterId) { VoteUserDTO user = db.VoteUsers.Where(x => x.VoterId == voterId).FirstOrDefault(); if (user == null) { return(RedirectToAction("Index")); } VoterVM model = new VoterVM(user); return(View(model)); }
public async Task <ResultVM> CreateUserAsync(VoterVM model) { var existingUser = _db.VoteUsers.Where(x => x.Email == model.Email).FirstOrDefault(); if (existingUser != null) { if (await IsInRole(existingUser.UserId, "Voter")) { Result.Success = false; Result.ErrorMessage = "Voter with email: " + existingUser.Email + " already exist"; return(Result); } } // generate userId string newVoterId = GenerateUserId(); VoteUserDTO user = new VoteUserDTO { UserId = model.UserId, VoterId = newVoterId, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, Phone = model.Phone, DateAddedUtc = DateTime.UtcNow }; _db.VoteUsers.Add(user); _db.SaveChanges(); // add user to role //this.AddToRole(user.UserId, "Voter"); // notify user NotifyNewVoter(user); Result.Success = true; return(Result); }
private void NotifyNewVoter(VoteUserDTO voter) { // Send an email with this link var mailModel = new EmailMessageVM(); mailModel.ToAddress = voter.Email; mailModel.Subject = "Account Created on LAGSOBA '94"; var callbackUrl = GetBaseUrl(); string message = "Hello," + "<br>An account has been created for you on the LAGSOBA '94 voting platform." + "<br> Use this as your password to log in: " + voter.VoterId + "<br> <html><body><a href='" + callbackUrl + "' style=\"padding: 8px 12px; border: 1px solid #5ed863;border-radius: 2px;font-family: Helvetica, Arial, sans-serif;font-size: 14px; color: #ffffff;background-color:#5ed863;text-decoration: none;font-weight:bold;display: inline-block;\">Log in now</a></body></html>" + "<br><br><br>" + "<html><body><p><em>If you you got this email as an error, kindly ignore.</em></p></body></html>"; mailModel.Message = message; // send email MailClient.SendEmail(mailModel); }