public result Get(String username, String password, int partyID, int numbers) { result respo = new result(); UserManager <ApplicationUser> userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext())); var cUser = userManager.Find(username, password); CollationEntry collationEntry = new CollationEntry(); Agent agent = new Agent(); agent = db.Agents.Where(c => c.UserID.Equals(cUser.Id)).First(); if (cUser != null && agent.IsEnable) { collationEntry.AgentID = agent.UserID; collationEntry.ConstituencyID = db.Constituencies.Find(agent.ContituencyID).ConstituencyNo; collationEntry.DateSend = DateTime.Now; collationEntry.NumberOfVote = numbers; collationEntry.PartyID = partyID; collationEntry.PollingStationID = agent.PollingStationID; if (db.CollationEntries.Where(c => c.PollingStationID.Equals(collationEntry.PollingStationID) && c.PartyID == collationEntry.PartyID).Count() == 0) { db.CollationEntries.Add(collationEntry); db.SaveChanges(); respo.Result = 1; } else { respo.Result = 0; } } else { respo.Result = 0; } return(respo); }
public ActionResult Edit(VoteCollationModelView model) { if (ModelState.IsValid) { String AgentID = db.AspNetUsers.Where(u => u.UserName.Equals(User.Identity.Name)).First().Agent.UserID; List <CollationEntry> check = db.CollationEntries.Where(o => o.PollingStationID == model.PollingStationID).ToList(); if (check.Count() == 0) { CollationEntry NDCEntry = new CollationEntry(); NDCEntry.AgentID = AgentID; NDCEntry.ConstituencyID = model.ConstituencyID; NDCEntry.DateSend = DateTime.Now; NDCEntry.PartyID = db.Parties.Where(c => c.Abrev.Equals("NDC")).FirstOrDefault().ID; NDCEntry.NumberOfVote = model.NDC; NDCEntry.PollingStationID = model.PollingStationID; CollationEntry NPPEntry = new CollationEntry(); NPPEntry.AgentID = AgentID; NPPEntry.ConstituencyID = model.ConstituencyID; NPPEntry.DateSend = DateTime.Now; NPPEntry.PartyID = db.Parties.Where(c => c.Abrev.Equals("NPP")).FirstOrDefault().ID; NPPEntry.NumberOfVote = model.NPP; NPPEntry.PollingStationID = model.PollingStationID; CollationEntry CPPEntry = new CollationEntry(); CPPEntry.AgentID = AgentID; CPPEntry.ConstituencyID = model.ConstituencyID; CPPEntry.DateSend = DateTime.Now; CPPEntry.PartyID = db.Parties.Where(c => c.Abrev.Equals("CPP")).FirstOrDefault().ID; CPPEntry.NumberOfVote = model.CPP; CPPEntry.PollingStationID = model.PollingStationID; CollationEntry PPPEntry = new CollationEntry(); PPPEntry.AgentID = AgentID; PPPEntry.ConstituencyID = model.ConstituencyID; PPPEntry.DateSend = DateTime.Now; PPPEntry.PartyID = db.Parties.Where(c => c.Abrev.Equals("PPP")).FirstOrDefault().ID; PPPEntry.NumberOfVote = model.PPP; PPPEntry.PollingStationID = model.PollingStationID; CollationEntry OTHERSEntry = new CollationEntry(); OTHERSEntry.AgentID = AgentID; OTHERSEntry.ConstituencyID = model.ConstituencyID; OTHERSEntry.DateSend = DateTime.Now; OTHERSEntry.PartyID = db.Parties.Where(c => c.Abrev.Equals("OTH")).FirstOrDefault().ID; OTHERSEntry.NumberOfVote = model.OTHERS; OTHERSEntry.PollingStationID = model.PollingStationID; CollationEntry REJECTEDEntry = new CollationEntry(); REJECTEDEntry.AgentID = AgentID; REJECTEDEntry.ConstituencyID = model.ConstituencyID; REJECTEDEntry.DateSend = DateTime.Now; REJECTEDEntry.PartyID = db.Parties.Where(c => c.Abrev.Equals("IRB")).FirstOrDefault().ID; REJECTEDEntry.NumberOfVote = model.REJECTED; REJECTEDEntry.PollingStationID = model.PollingStationID; db.CollationEntries.Add(NDCEntry); db.CollationEntries.Add(NPPEntry); db.CollationEntries.Add(CPPEntry); db.CollationEntries.Add(PPPEntry); db.CollationEntries.Add(OTHERSEntry); db.CollationEntries.Add(REJECTEDEntry); db.SaveChanges(); return(this.RedirectToAction("Index")); } else { throw new HttpException(string.Format("The Polling Station {0} has already posted", db.PollingStations.Find(model.PollingStationID).PollingStationName)); } } else { return(View(model)); } }