public ActionResult CreateCandidateWithPhoto(string name, HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { var imgByte = new Byte[file.ContentLength]; file.InputStream.Read(imgByte, 0, file.ContentLength); using (var candidateRepository = new CandidateRepository()) { candidateRepository.CreateCandidateWithPhoto(new Candidate { ElectionId = ElectionConductor.ElectionId((int)Session["UserId"]), Name = name }, imgByte); } } return RedirectToAction("Index"); }
public JsonResult ChangeElectionStatus(int newStatus) { using (var electionRepository = new ElectionRepository()) using (var candidateRepository = new CandidateRepository()) { var election = electionRepository.GetElectionByElectionId(ElectionConductor.ElectionId((int)Session["UserId"])); if ((newStatus == 1) && election.NoVote) { var path = Server.MapPath("~/Content/Banners/NoVote.jpg"); var noVoteImage = System.IO.File.ReadAllBytes(path); candidateRepository.CreateCandidateWithPhoto(new Candidate { ElectionId = ElectionConductor.ElectionId((int)Session["UserId"]), Name = "No Vote" }, noVoteImage); } var result = electionRepository.ChangeElectionStatus(ElectionConductor.ElectionId((int)Session["UserId"]), newStatus); return new JsonResult { Data = new { isOk = result == 1 } }; } }