public bool DeleteMantri(int mantriId) { try { Mantri mantri = _context.Mantri.Find(mantriId); List <Workdone> workdone = _context.Workdone.Where(p => p.MantriId == mantri.MantriId).ToList(); Constituency constituency = _context.Constituency.Where(p => p.ConstituencyName == mantri.Constituency).FirstOrDefault(); constituency.Status = "not registered"; List <Complaint> complaints = _context.Complaint.Where(p => p.Constituency == mantri.Constituency).ToList(); List <Feedback> feedbacks = new List <Feedback>(); foreach (var item in complaints) { Feedback feedbackitem = _context.Feedback.Where(p => p.ComplaintId == item.ComplaintId).FirstOrDefault(); feedbacks.Add(feedbackitem); } UserCredentials userCredentials = _context.UserCredentials.Find(mantriId); _context.Feedback.RemoveRange(feedbacks); _context.Complaint.RemoveRange(complaints); _context.Workdone.RemoveRange(workdone); _context.Mantri.Remove(mantri); _context.UserCredentials.Remove(userCredentials); _context.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public string ViewMantriName(int mantriId) { try { Mantri mantri = _context.Mantri.Find(mantriId); return(mantri.Name); } catch (Exception ex) { return(null); } }
public Mantri GetMantriByConstituency(string ConstituencyName) { Mantri mantri = null; try { mantri = _context.Mantri.Where(p => p.Constituency == ConstituencyName).FirstOrDefault(); return(mantri); } catch (Exception ex) { return(null); } }
public bool AddMantri(Mantri mantri) { bool status = false; try { _context.Mantri.Add(mantri); _context.SaveChanges(); status = true; } catch (Exception ex) { status = false; } return(status); }
public bool ForgotPassword(string EmailID, string SecurityAns, string pwd) { bool status = false; try { Voters voter = null; voter = _context.Voters.Where(p => p.EmailId.Equals(EmailID.ToLower())).FirstOrDefault(); Mantri mantri = null; mantri = _context.Mantri.Where(p => p.EmailId.Equals(EmailID.ToLower())).FirstOrDefault(); if (voter != null) { if (SecurityAns.ToLower() == voter.SecurityAns.ToLower()) { UserCredentials UC = _context.UserCredentials.Find(voter.VoterId); UC.Password = pwd; _context.SaveChanges(); status = true; } } else if (mantri != null) { if (SecurityAns.ToLower() == mantri.SecurityAns.ToLower()) { UserCredentials UC = _context.UserCredentials.Find(mantri.MantriId); UC.Password = pwd; _context.SaveChanges(); status = true; } } else { status = false; } } catch (Exception ex) { status = false; } return(status); }
public List <Mantri> GetMantriList() { List <Mantri> mantris = new List <Mantri>(); SqlConnection conn = new SqlConnection(connectionstring); SqlCommand cmd = new SqlCommand("select * from tpl_mantri", conn); conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Mantri mantri = new Mantri { Id = reader.GetInt64(reader.GetOrdinal("id")) }; mantris.Add(mantri); } conn.Close(); return(mantris); }
public bool UpdateMantri(Mantri mantri) { try { Mantri man = _context.Mantri.Find(mantri.MantriId); man.Address = mantri.Address; man.Constituency = mantri.Constituency; man.DateOfBirth = mantri.DateOfBirth; man.EmailId = mantri.EmailId; man.Gender = mantri.Gender; man.MantriId = mantri.MantriId; man.MantriUid = mantri.MantriUid; man.Mobile = mantri.Mobile; man.Name = mantri.Name; man.SecurityAns = mantri.SecurityAns; _context.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public ActionResult SaveRegistration(Models.User user) { try { //Minimum age to register is 18 years. #region if (user.DateOfBirth >= DateTime.Now.AddYears(-18)) { TempData["msg"] = "Minimum age to register is 18 years"; return(RedirectToAction("Index", new { n = user.Name, e = user.EmailId, p = user.Password, k = hashsecure })); } #endregion if (_repObj.ValidateEmailId(user.EmailId) != null) { TempData["msg"] = "Email Id already exists."; return(RedirectToAction("Index", new { user.Name, user.EmailId, user.Password, hashsecure })); } //Assigning values to enter in user credentials table. #region UserCredentials userCredential = new UserCredentials(); ServiceRepository serviceRepository = new ServiceRepository(configuration); userCredential.RollId = 3; userCredential.Password = user.Password; #endregion //Check if mantri or not and verify mantri. #region if (user.MantriUid != null) { HttpResponseMessage response1 = serviceRepository.GetResponse("api/Home/ValidateMantri?mantriId=" + user.MantriUid + "&constituency=" + user.Constituency); response1.EnsureSuccessStatusCode(); int a = response1.Content.ReadAsAsync <int>().Result; if (a == 1) { userCredential.RollId = 2; } else if (a == 2) { TempData["msg"] = "Mantri already exists for opted constituency."; return(RedirectToAction("Index", new { user.Name, user.EmailId, user.Password, hashsecure })); } else { TempData["msg"] = "Enter valid mantri credentials"; return(RedirectToAction("Index", new { user.Name, user.EmailId, user.Password, hashsecure })); } } #endregion //Add user credentials to userCredentials table. //store User Id in Tempdata for retrieving username to display on Index page. #region HttpResponseMessage response2 = serviceRepository.PostRequest("api/Home/AddUserCredentials/", userCredential); response2.EnsureSuccessStatusCode(); int userId = response2.Content.ReadAsAsync <int>().Result; TempData["userId"] = userId; #endregion //Create and enter details of mantri and voter on basis of role id. #region //Mantri if (userCredential.RollId == 2) { user.MantriId = userId; Mantri mantri = _mapper.Map <Mantri>(user); HttpResponseMessage response3 = serviceRepository.PostRequest("api/Home/AddMantri/", mantri); response3.EnsureSuccessStatusCode(); if (response3.Content.ReadAsAsync <bool>().Result) { return(View("Success")); } } //Voter else if (userCredential.RollId == 3) { user.VoterId = userId; Voter voter = _mapper.Map <Voter>(user); HttpResponseMessage response3 = serviceRepository.PostRequest("api/Home/AddVoter", voter); response3.EnsureSuccessStatusCode(); if (response3.Content.ReadAsAsync <bool>().Result) { return(View("Success")); } } #endregion TempData["msg"] = "Email ID already exists."; return(RedirectToAction("Index", new { user.Name, user.EmailId, user.Password, hashsecure })); } catch (Exception ex) { TempData["msg"] = "Server Error. Please retry after sometime."; return(RedirectToAction("Index", new { user.Name, user.EmailId, user.Password, hashsecure })); } }