コード例 #1
0
        public IHttpActionResult Postpoll_Location_All(poll_Location_All poll_Location_All)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.poll_Location_All.Add(poll_Location_All);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (poll_Location_AllExists(poll_Location_All.poll_id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = poll_Location_All.poll_id }, poll_Location_All));
        }
コード例 #2
0
        public IHttpActionResult Putpoll_Location_All(double id, poll_Location_All poll_Location_All)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != poll_Location_All.poll_id)
            {
                return(BadRequest());
            }

            db.Entry(poll_Location_All).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!poll_Location_AllExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public IHttpActionResult Getpoll_Location_All(double id)
        {
            poll_Location_All poll_Location_All = db.poll_Location_All.Find(id);

            if (poll_Location_All == null)
            {
                return(NotFound());
            }

            return(Ok(poll_Location_All));
        }
コード例 #4
0
        public IHttpActionResult Deletepoll_Location_All(double id)
        {
            poll_Location_All poll_Location_All = db.poll_Location_All.Find(id);

            if (poll_Location_All == null)
            {
                return(NotFound());
            }

            db.poll_Location_All.Remove(poll_Location_All);
            db.SaveChanges();

            return(Ok(poll_Location_All));
        }
コード例 #5
0
        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));
        }