public ActionResult Delete(int id) { tblElection tbl = db.tblElections.Where(a => a.ElectionId == id).FirstOrDefault(); db.tblElections.Remove(tbl); db.SaveChanges(); return(Json(new { success = true, message = "Deleted Sucessfully" }, JsonRequestBehavior.AllowGet)); }
public JsonResult AddEdit(ElectionViewModel pvm) { if (pvm.ElectionId > 0) { tblElection tb = db.tblElections.Where(x => x.ElectionId == pvm.ElectionId).FirstOrDefault(); tb.ElectionName = pvm.ElectionName; tb.ElectionStartDate = pvm.ElectionStartDate; tb.ElectionEndDate = pvm.ElectionEndDate; db.SaveChanges(); return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet)); } else { tblElection tb = new tblElection(); tb.ElectionName = pvm.ElectionName; tb.ElectionStartDate = pvm.ElectionStartDate; tb.ElectionEndDate = pvm.ElectionEndDate; tb.NoOfCandidate = 0; db.tblElections.Add(tb); db.SaveChanges(); return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Add(CandidateViewModel pvm) { tblCandidate tbl = new tblCandidate(); tbl.CandidateName = pvm.CandidateName; tbl.ElectionId = pvm.ElectionId; tbl.Description = pvm.Description; tbl.VoteObtained = 0; HttpPostedFileBase fup = Request.Files["Photo"]; if (fup != null) { tbl.Photo = fup.FileName; fup.SaveAs(Server.MapPath("~/CandidateImages/" + fup.FileName)); } var candidatenum = db.tblElections.Where(a => a.ElectionId == pvm.ElectionId).Select(a => a.NoOfCandidate).FirstOrDefault(); tblElection tb = db.tblElections.Where(a => a.ElectionId == pvm.ElectionId).FirstOrDefault(); tb.NoOfCandidate = candidatenum + 1; db.tblCandidates.Add(tbl); db.SaveChanges(); return(RedirectToAction("AddCandidate")); }