public ActionResult Autherize(UserMetadata userModel) { using (OnlineVotingSystemEntities db = new OnlineVotingSystemEntities()) { if (userModel.Email != null && userModel.Password != null) { var userDetails = db.Users.Where(x => x.Email == userModel.Email && x.Password == userModel.Password).FirstOrDefault(); if (userDetails == null) { userModel.LoginErrorMessage = "Wrong email or password!"; return(View("Index", userModel)); } else { Session["userEmail"] = userDetails.Email; Session["userType"] = "Admin"; return(RedirectToAction("Index", "Home")); } } else { return(View("Index", userModel)); } } }
public ActionResult ChangePassword(ChangePasswordViewModel cp) { using (OnlineVotingSystemEntities db = new OnlineVotingSystemEntities()) { string username = Session["UserName"].ToString(); var user = db.tblUsers.Where(a => a.UserName == username).FirstOrDefault(); if (user != null) { var OldPassword = OnlineVotingSystemForCollege.Models.EncryptPassword.textToEncrypt(cp.OldPassword); if (user.Password == OldPassword) { if (cp.NewPassword == cp.ConfirmNew) { user.Password = OnlineVotingSystemForCollege.Models.EncryptPassword.textToEncrypt(cp.NewPassword); db.SaveChanges(); ViewBag.Message = "Password Changed"; } else { ViewBag.Message = "New Password and Confirm New Mismatched"; } } else { ViewBag.Message = "Wrong Password"; } } return(View()); } }
public ActionResult UserVerification(String id) { using (OnlineVotingSystemEntities db = new OnlineVotingSystemEntities()) { bool Status = false; db.Configuration.ValidateOnSaveEnabled = false; var IsVerify = db.tblUsers.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault(); if (IsVerify != null) { IsVerify.EmailVerification = true; db.SaveChanges(); ViewBag.Message = "Email Verification completed"; Status = true; } else { ViewBag.Message = "Invalid Request...Email not verify"; ViewBag.Status = false; } return(View()); } }
public ActionResult Delete(int id) { using (OnlineVotingSystemEntities db = new OnlineVotingSystemEntities()) { var result = db.tblResults.Where(a => a.UserId == id).ToList(); foreach (var item in result) { var VoteObtained = db.tblCandidates.Where(a => a.CandidateId == item.CandidateId).Select(a => a.VoteObtained).FirstOrDefault(); tblCandidate tbc = db.tblCandidates.Where(a => a.CandidateId == item.CandidateId).FirstOrDefault(); tbc.VoteObtained = VoteObtained - 1; db.tblResults.Remove(item); db.SaveChanges(); } var tb = db.tblUserRoles.Where(x => x.UserId == id).FirstOrDefault(); db.tblUserRoles.Remove(tb); db.SaveChanges(); tblUser sm = db.tblUsers.Where(x => x.UserId == id).FirstOrDefault(); db.tblUsers.Remove(sm); db.SaveChanges(); return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult AddOrEdit(UserViewModel uv) { using (OnlineVotingSystemEntities db = new OnlineVotingSystemEntities()) { tblUser tb = new tblUser(); tb.UserName = uv.UserName; tb.Password = OnlineVotingSystemForCollege.Models.EncryptPassword.textToEncrypt(uv.Password); tb.Fullname = uv.FullName; tb.Email = uv.Email; tb.EmailVerification = true; db.tblUsers.Add(tb); db.SaveChanges(); tblUserRole ud = new tblUserRole(); ud.UserId = tb.UserId; ud.RoleId = 1; db.tblUserRoles.Add(ud); db.SaveChanges(); ViewBag.Message = "User Created Successfully"; return(RedirectToAction("ManageUser")); } }
public JsonResult GetData() { using (OnlineVotingSystemEntities db = new OnlineVotingSystemEntities()) { db.Configuration.LazyLoadingEnabled = false; List <UserViewModel> lstitem = new List <UserViewModel>(); var lst = db.tblUsers.ToList(); foreach (var item in lst) { lstitem.Add(new UserViewModel() { UserId = item.UserId, UserName = item.UserName, FullName = item.Fullname, Email = item.Email }); } return(Json(new { data = lstitem }, JsonRequestBehavior.AllowGet)); } }
// GET: Result public ActionResult Index() { VoteCastingInformationViewModel vm = new VoteCastingInformationViewModel(); OnlineVotingSystemEntities db = new OnlineVotingSystemEntities(); // GET: CandidatePosition vm.VoteCastingPanelViewModel = (from cp in db.CandidatePositions join c in db.Candidates on cp.CandidateId equals c.CandidateId join p in db.Positions on cp.PositionId equals p.PositionId select new VoteCastingPanelViewModel { Position = p, Candidate = c }).ToList(); vm.CandidateVoterViewModel = (from vc in db.VoteCastingInformations join p in db.Positions on vc.PositionId equals p.PositionId join c in db.Candidates on vc.CandidateId equals c.CandidateId group new { vc.PositionId, vc.CandidateId, vc.VoterId } by new { p.PositionName, c.Name, p.PositionId, vc.Candidate, vc.Position } into g orderby g.Key.PositionId select new CandidateVoterViewModel { Position = g.Key.Position, Candidate = g.Key.Candidate, PositionName = g.Key.PositionName, CandidateName = g.Key.Name, VoteCount = g.Count(t => t.VoterId != null) }).ToList(); vm.Voters = (from v in db.Voters where v.IsCommittedVote == false select v).ToList(); return(View(vm)); }
public ActionResult Login(Models.ViewModel.LoginViewModel iv, string ReturnUrl = "") { using (OnlineVotingSystemEntities db = new OnlineVotingSystemEntities()) { var password = OnlineVotingSystemForCollege.Models.EncryptPassword.textToEncrypt(iv.Password); var user = db.tblUsers.Where(a => a.UserName == iv.UserName && a.Password == password).FirstOrDefault(); if (user != null) { if (user.EmailVerification == true) { Session.Add("FullName", user.Fullname); Session.Add("UserName", user.UserName); Session.Add("UserId", user.UserId); FormsAuthentication.SetAuthCookie(iv.UserName, iv.RememberMe); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { return(RedirectToAction("DashBoard", "Admin")); } } else { { ViewBag.Message = "Email not verified"; } } } else { ModelState.AddModelError("", "Invalid User"); ViewBag.Action = "Invalid User"; } return(View()); } }
public ActionResult ForgetPassword(UserViewModel fp) { using (OnlineVotingSystemEntities db = new OnlineVotingSystemEntities()) { var user = db.tblUsers.Where(a => a.Email == fp.Email).FirstOrDefault(); if (user != null) { try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(user.Email); mail.Subject = "Password Recovery Sent From Sachin"; mail.Body = "<b>Password </b>:" + OnlineVotingSystemForCollege.Models.EncryptPassword.textToEncrypt(user.Password); mail.IsBodyHtml = true; SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Online@12345"); SmtpServer.EnableSsl = true; ViewBag.Message = "Mail Sending"; SmtpServer.Send(mail); ViewBag.Action = "Mail Sent ! Use Your Password To Login"; return(View("Login")); } catch (Exception ex) { ViewBag.Action = "Email Sending Failed" + ex.ToString(); } } else { ViewBag.Action = "Invalid Email"; } return(View()); } }
public ActionResult Registration(RegistrationViewModel uv) { using (OnlineVotingSystemEntities db = new OnlineVotingSystemEntities()) { tblUser tbl = db.tblUsers.Where(u => u.UserName == uv.UserName || u.Email == uv.Email).FirstOrDefault(); if (tbl != null) { return(Json(new { success = false, message = "User Already Register" }, JsonRequestBehavior.AllowGet)); } else { tblUser tb = new tblUser(); tb.UserName = uv.UserName; tb.Password = OnlineVotingSystemForCollege.Models.EncryptPassword.textToEncrypt(uv.Password); tb.Fullname = uv.FullName; tb.Email = uv.Email; tb.EmailVerification = false; tb.ActivationCode = Guid.NewGuid(); db.tblUsers.Add(tb); db.SaveChanges(); tblUserRole ud = new tblUserRole(); ud.UserId = tb.UserId; ud.RoleId = 2; db.tblUserRoles.Add(ud); db.SaveChanges(); tblIdRequest tbid = new tblIdRequest(); tbid.UserEmail = tb.Email; tbid.FullName = tb.Fullname; tbid.UserId = tb.UserId; db.tblIdRequests.Add(tbid); db.SaveChanges(); return(Json(new { success = true, message = "Registration Completed . A Email would be send to your email" + tb.Email + "If You are a Valid User" }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult Index(HttpPostedFileBase postedFile) { if (postedFile != null) { try { string fileExtension = Path.GetExtension(postedFile.FileName); //Validate uploaded file and return error. if (fileExtension != ".xls" && fileExtension != ".xlsx") { ViewBag.Message = "Please select the excel file with .xls or .xlsx extension"; return(View()); } string folderPath = Server.MapPath("~/UploadedFiles/"); //Check directory exists else create one if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } //Save file to folder var filePath = folderPath + Path.GetFileName(postedFile.FileName); postedFile.SaveAs(filePath); //Get file extension string excelConString = ""; //Get connection string using extension switch (fileExtension) { //If uploaded file is Excel 1997-2007. case ".xls": excelConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES'"; break; //If uploaded file is Excel 2007 and above case ".xlsx": excelConString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES'"; break; } //Read data from first sheet of excel into datatable DataTable dt = new DataTable(); excelConString = string.Format(excelConString, filePath); using (OleDbConnection excelOledbConnection = new OleDbConnection(excelConString)) { using (OleDbCommand excelDbCommand = new OleDbCommand()) { using (OleDbDataAdapter excelDataAdapter = new OleDbDataAdapter()) { excelDbCommand.Connection = excelOledbConnection; excelOledbConnection.Open(); //Get schema from excel sheet DataTable excelSchema = GetSchemaFromExcel(excelOledbConnection); //Get sheet name string sheetName = excelSchema.Rows[0]["TABLE_NAME"].ToString(); excelOledbConnection.Close(); //Read Data from First Sheet. excelOledbConnection.Open(); excelDbCommand.CommandText = "SELECT * From [" + sheetName + "]"; excelDataAdapter.SelectCommand = excelDbCommand; //Fill datatable from adapter excelDataAdapter.Fill(dt); excelOledbConnection.Close(); } } } //Insert records to Employee table. using (var db = new OnlineVotingSystemEntities()) { //Loop through datatable and add employee data to employee table. foreach (DataRow row in dt.Rows) { db.Voters.Add(GetVoterFromExcelRow(row)); } db.SaveChanges(); } ViewBag.Message = "Voter Information Imported Successfully."; } //catch (Exception ex) //{ // ViewBag.Message = ex.Message; //} catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } } else { ViewBag.Message = "Please select the file first to upload."; } return(View()); }