public IHttpActionResult Getpoll_Location(int id) { poll_Location poll_Location = db.poll_Location.Find(id); if (poll_Location == null) { return(NotFound()); } return(Ok(poll_Location)); }
public IHttpActionResult Deletepoll_Location(int id) { poll_Location poll_Location = db.poll_Location.Find(id); if (poll_Location == null) { return(NotFound()); } db.poll_Location.Remove(poll_Location); db.SaveChanges(); return(Ok(poll_Location)); }
public IHttpActionResult Postpoll_Location(poll_Location poll_Location) { if (poll_Location.poll_Id != 0) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (poll_Location.poll_Id != poll_Location.poll_Id) { return(BadRequest()); } db.Entry(poll_Location).State = EntityState.Modified; try { db.SaveChanges(); locationUpdatesHub.SayHello(); } catch (DbUpdateConcurrencyException) { if (!poll_LocationExists(poll_Location.poll_Id)) { return(NotFound()); } else { throw; } } } // return StatusCode(HttpStatusCode.NoContent); else { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.poll_Location.Add(poll_Location); try { db.SaveChanges(); } catch (DbUpdateException) { if (poll_LocationExists(poll_Location.poll_Id)) { return(Conflict()); } else { throw; } } } return(CreatedAtRoute("DefaultApi", new { id = poll_Location.poll_Id }, poll_Location)); }
public IHttpActionResult Post() { string sPath = ""; string kmlPath = ""; int iUploadedCnt = 0; sPath = HostingEnvironment.MapPath("~/locker/"); // kmlPath = HostingEnvironment.MapPath("~/KML/"); HttpFileCollection hfc = HttpContext.Current.Request.Files; for (int iCnt = 0; iCnt <= hfc.Count - 1; iCnt++) { HttpPostedFile hpf = hfc[iCnt]; if (hpf.ContentLength > 0) { // CHECK IF THE SELECTED FILE(S) ALREADY EXISTS IN FOLDER. (AVOID DUPLICATE) if (!File.Exists(sPath + Path.GetFileName(hpf.FileName))) { //SAVE THE FILES IN THE FOLDER. hpf.SaveAs(sPath + Path.GetFileName(hfc.AllKeys[iCnt].ToString() + ".csv")); iUploadedCnt = iUploadedCnt + 1; } } } if (iUploadedCnt > 0) { for (int i = 0; i < iUploadedCnt; i++) { ExcelObject excel = new ExcelObject(); excel.readExcelFile(sPath + hfc.AllKeys[i].ToString() + ".csv"); if (hfc.AllKeys[i].ToString() == "Location List") { int colcnt = 4; // poll_Location poll = new poll_Location(); while (colcnt < excel.ReadList.Count) { poll_Location poll = new poll_Location(); poll.poll_Id = int.Parse(excel.ReadList[colcnt].ToString()); colcnt++; poll.poll_Name = excel.ReadList[colcnt].ToString(); colcnt++; poll.poll_Address = excel.ReadList[colcnt].ToString(); colcnt++; poll.Zone = int.Parse(excel.ReadList[colcnt].ToString()); colcnt++; poll.Monday_Arrival = 0; poll.Tuesday_Arrival = 0; poll.OpenReady = 0; poll.ClosePollReady = 0; db.Entry(poll).State = EntityState.Modified; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.poll_Location.Add(poll); try { db.SaveChanges(); } catch (DbUpdateException) { if (poll_LocationExists(poll.poll_Id)) { return(Conflict()); } else { throw; } } } } else if (hfc.AllKeys[i].ToString() == "Location Details") { int colcnt = 4; while (colcnt < excel.ReadList.Count) { dbo_poll_ContactDetails pollCnt = new dbo_poll_ContactDetails(); pollCnt.poll_Id = int.Parse(excel.ReadList[colcnt].ToString()); colcnt++; pollCnt.contact_FirstName = excel.ReadList[colcnt].ToString(); colcnt++; pollCnt.contact_LastName = excel.ReadList[colcnt].ToString(); colcnt++; pollCnt.contact_Type = excel.ReadList[3].ToString(); // colcnt++; pollCnt.contact_Info = excel.ReadList[colcnt].ToString(); colcnt++; db.Entry(pollCnt).State = EntityState.Modified; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.dbo_poll_ContactDetails.Add(pollCnt); try { db.SaveChanges(); } catch (DbUpdateException) { //if (!dbo_poll_ContactDetails(pollCnt.poll_Id)) //{ // return Conflict(); //} //else //{ // throw; //} } } } else if (hfc.AllKeys[i].ToString() == "Precinct List") { int colcnt = 4; while (colcnt < excel.ReadList.Count) { election_Precinct precinct = new election_Precinct(); precinct.poll_Id = int.Parse(excel.ReadList[colcnt].ToString()); colcnt++; precinct.precinct_Id = int.Parse(excel.ReadList[colcnt].ToString()); colcnt++; precinct.ward_Name = excel.ReadList[colcnt].ToString(); colcnt++; precinct.precinct = excel.ReadList[colcnt].ToString(); colcnt++; db.Entry(precinct).State = EntityState.Modified; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.election_Precinct.Add(precinct); try { db.SaveChanges(); } catch (DbUpdateException) { if (!election_PrecinctExists(precinct.poll_Id)) { return(Conflict()); } else { throw; } } } } else if (hfc.AllKeys[i].ToString() == "KMLFile") { } else if (hfc.AllKeys[i].ToString() == "Polling Location All") { int colcnt = 8; while (colcnt < excel.ReadList.Count) { poll_Location_All pollAll = new poll_Location_All(); pollAll.poll_id = int.Parse(excel.ReadList[colcnt].ToString()); colcnt++; pollAll.status = excel.ReadList[colcnt].ToString(); colcnt++; pollAll.latitude = double.Parse(excel.ReadList[colcnt].ToString()); colcnt++; pollAll.longitude = double.Parse(excel.ReadList[colcnt].ToString()); colcnt++; pollAll.location_Name = excel.ReadList[colcnt].ToString(); colcnt++; pollAll.location_Address = excel.ReadList[colcnt].ToString(); colcnt++; pollAll.city = excel.ReadList[colcnt].ToString(); colcnt++; pollAll.state = excel.ReadList[colcnt].ToString(); colcnt++; db.Entry(pollAll).State = EntityState.Modified; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.poll_Location_All.Add(pollAll); try { db.SaveChanges(); } catch (DbUpdateException) { if (!poll_Location_AllExists(pollAll.poll_id)) { return(Conflict()); } else { throw; } } } } } DirectoryInfo di = new DirectoryInfo(sPath); foreach (FileInfo file in di.GetFiles()) { file.Delete(); } } else { // return "Upload Failed"; } return(StatusCode(HttpStatusCode.NoContent)); }