public async Task <IActionResult> Index(RegistrationVModel model) { if (ModelState.IsValid) { if (model.Password == model.ConfirmPassword) { Users entityUser = new Users(); entityUser.FName = model.FName; entityUser.SName = model.SNAme; entityUser.LName = model.LName; entityUser.Phone = ""; entityUser.Address = ""; entityUser.City = ""; entityUser.Country = model.Country; role roles = await _context.Roles.FirstOrDefaultAsync(x => x.Id == 2); LoginModel login = new LoginModel(); login.Email = model.Email; login.Password = model.Password; login.Role = roles; login.User = entityUser; _context.Add(entityUser); _context.Add(login); await _context.SaveChangesAsync(); } else { ModelState.AddModelError(string.Empty, "Passeords is not match"); return(View(model)); } } return(View()); }
public ActionResult UserDetails() { var Email = Request.Cookies["usId"].Value.ToString(); var Details = context.Registrations.FirstOrDefault(x => x.Email == Email); var Role = ""; if (Details.LoginIdentity == 0) { Role = "Member"; } else if (Details.LoginIdentity == 1) { Role = "Councilor"; } else if (Details.LoginIdentity == 2) { Role = "Mayor"; } else if (Details.LoginIdentity == 3) { Role = "Admin"; } RegistrationVModel UserDetails = new RegistrationVModel { Email = Details.Email, Location = Details.Location, LoginIdentity = Role, VoterId = Details.VoterId }; return(View(UserDetails)); }
public IActionResult Index() { RegistrationVModel model = new RegistrationVModel(); return(View(model)); }
public ActionResult Registration(RegistrationVModel registrationVModel) { //ViewBag.Status = ""; var Register = new Registration(); if (registrationVModel.LoginIdentity == "Mayor") { Register.LoginIdentity = 2; var Avalibility = context.Registrations.FirstOrDefault(x => x.LoginIdentity == 2); if (Avalibility != null) { return(Json(new { Message = "Already Assigned Mayor" }, JsonRequestBehavior.AllowGet)); } var Avalibility2 = context.Registrations.FirstOrDefault(x => x.Email == registrationVModel.Email || x.VoterId == registrationVModel.VoterId && x.LoginIdentity == 2 || x.VoterId == registrationVModel.VoterId && x.LoginIdentity == 1); if (Avalibility2 != null) { return(Json(new { Message = "Already Assigned Email or VoterID" }, JsonRequestBehavior.AllowGet)); } } else if (registrationVModel.LoginIdentity == "Member") { Register.LoginIdentity = 0; var Avalibility2 = context.Registrations.FirstOrDefault(x => x.Email == registrationVModel.Email || x.VoterId == registrationVModel.VoterId && x.LoginIdentity == 0); if (Avalibility2 != null) { return(Json(new { Message = "Already Assigned Email or VoterID" }, JsonRequestBehavior.AllowGet)); } } else { Register.LoginIdentity = 1; var Avalibility = context.Registrations.FirstOrDefault(x => x.Location == registrationVModel.Location && x.LoginIdentity == 1); if (Avalibility != null) { return(Json(new { Message = "Already Assigned Councilor at That Location" }, JsonRequestBehavior.AllowGet)); } var Avalibility2 = context.Registrations.FirstOrDefault(x => x.Email == registrationVModel.Email || x.VoterId == registrationVModel.VoterId && x.LoginIdentity == 1 || x.VoterId == registrationVModel.VoterId && x.LoginIdentity == 2); if (Avalibility2 != null) { return(Json(new { Message = "Already Assigned Email or VoterID" }, JsonRequestBehavior.AllowGet)); } } Register.Email = registrationVModel.Email; Register.Location = registrationVModel.Location; Register.VoterId = registrationVModel.VoterId; var Logins = new Login() { EmailAddress = registrationVModel.Email, Password = registrationVModel.Password }; context.Registrations.Add(Register); context.Logins.Add(Logins); context.SaveChanges(); Dictionary <string, string> items = new Dictionary <string, string>(); context.Locations.ToList().ForEach(x => { items.Add(x.LocationName.ToString(), x.LocationName.ToString()); }); ViewBag.User = new SelectList(items, "Key", "Value"); Dictionary <string, string> items1 = new Dictionary <string, string>(); items1.Add("Member", "Member"); items1.Add("Councilor", "Councilor"); items1.Add("Mayor", "Mayor"); ViewBag.Identity = new SelectList(items1, "Key", "Value"); return(Json(new { Message = "Successfully Created Account" }, JsonRequestBehavior.AllowGet)); }