public IHttpActionResult UpdateProject(PROJECT_IMPACT project)
        {
            try
            {
                var repos = new TDAssetRespository();

                PROJECT_IMPACT updateProject = tdmEntities.PROJECT_IMPACT.First(x => x.ID == project.ID);

                updateProject.IS_DELETED   = project.IS_DELETED;
                updateProject.SUBJECT_ID   = project.SUBJECT_ID;
                updateProject.SUBJECT_NAME = project.SUBJECT_NAME;
                updateProject.PUBLISH_DATE = project.PUBLISH_DATE;
                updateProject.IS_PUBLISHED = project.IS_PUBLISHED;
                updateProject.UPDATE_BY    = project.UPDATE_BY;
                updateProject.UPDATE_DATE  = project.UPDATE_DATE;
                updateProject.CREATE_DATE  = project.CREATE_DATE;
                updateProject.CREATE_BY    = project.CREATE_BY;
                updateProject.PROVINCE_ID  = project.PROVINCE_ID;
                updateProject.AMPHOE_ID    = project.AMPHOE_ID;
                updateProject.TAMBOL_ID    = project.TAMBOL_ID;
                updateProject.Shape        = project.Shape != null ? project.Shape : null;
                tdmEntities.SaveChanges();

                repos.AddPROJECT_IMPACT_GEOMETRY(updateProject);

                return(Json(project, jsonSetting));
            }
            catch (Exception ex)
            {
                return(Json(ex));
            }
        }
        public IHttpActionResult AddProject(PROJECT_IMPACT project)
        {
            var repos = new TDAssetRespository();

            try
            {
                project.ID = 0;
                PROJECT_IMPACT saveProject = tdmEntities.PROJECT_IMPACT.Add(project);
                tdmEntities.SaveChanges();

                repos.AddPROJECT_IMPACT_GEOMETRY(saveProject);

                return(Json(saveProject, jsonSetting));
            }
            catch (Exception ex)
            {
                return(Json(ex));
            }
        }
示例#3
0
        public ActionResult AddEditProject(int projectId, int statusId = 0)
        {
            PROJECT_IMPACT_ViewModel model = new PROJECT_IMPACT_ViewModel();

            if (projectId > 0)
            {
                PROJECT_IMPACT project = db.PROJECT_IMPACT.SingleOrDefault(x => x.ID == projectId && x.IS_DELETED == false);
                model.ID           = project.ID;
                model.IS_DELETED   = project.IS_DELETED;
                model.SUBJECT_ID   = project.SUBJECT_ID;
                model.SUBJECT_NAME = project.SUBJECT_NAME;
                model.PUBLISH_DATE = project.PUBLISH_DATE;
                model.UPDATE_BY    = project.UPDATE_BY;
                model.UPDATE_DATE  = project.UPDATE_DATE;
                model.CREATE_DATE  = project.CREATE_DATE;
                model.CREATE_BY    = project.CREATE_BY;
                model.IS_PUBLISHED = project.IS_PUBLISHED;
                model.STATUS_ID    = statusId;
            }
            return(PartialView("Manage_Modal", model));
        }
        public IHttpActionResult DeleteProject(DelProjectImpact project)
        {
            try
            {
                PROJECT_IMPACT deleteProject = tdmEntities.PROJECT_IMPACT.First(x => x.ID == project.ID);
                deleteProject.ID         = project.ID;
                deleteProject.IS_DELETED = project.IS_DELETED;


                tdmEntities.PROJECT_IMPACT.Remove(deleteProject);

                var targetDelete = tdmEntities.PROJECT_IMPACT_GEOMETRY.Where(p => p.ProjectImpactID == project.ID);
                tdmEntities.PROJECT_IMPACT_GEOMETRY.RemoveRange(targetDelete);



                tdmEntities.SaveChanges();
                return(Json(project, jsonSetting));
            }
            catch (Exception ex)
            {
                return(Json(ex));
            }
        }
        public HttpResponseMessage UploadMapShape()
        {
            HttpResponseMessage result = null;
            int bcount = 0;

            try
            {
                var httpRequest = HttpContext.Current.Request;

                PROJECT_IMPACT importInfo = null;

                if (httpRequest.Form.Count > 0)
                {
                    var imageInfo = httpRequest.Form["ImageInfo"];
                    if (imageInfo != null)
                    {
                        importInfo = (new System.Web.Script.Serialization.JavaScriptSerializer()).Deserialize <PROJECT_IMPACT>(imageInfo);
                    }
                }



                List <Geometry> geometries = new List <Geometry>(0);
                if (httpRequest.Files.Count > 0)
                {
                    string sessionID = Guid.NewGuid().ToString();



                    var docfiles = new List <string>();
                    foreach (string file in httpRequest.Files)
                    {
                        var postedFile = httpRequest.Files[file];

                        string targetFolder = $@"{HttpContext.Current.Server.MapPath("~")}UploadShape\{sessionID}";
                        if (!System.IO.Directory.Exists(targetFolder))
                        {
                            System.IO.Directory.CreateDirectory(targetFolder);
                        }

                        /*save file from client*/
                        var zipFilePath = $@"{targetFolder}\{postedFile.FileName}";
                        postedFile.SaveAs(zipFilePath);
                        docfiles.Add(zipFilePath);

                        /*extract zip file*/
                        var extractFilePath = $"{targetFolder}";
                        System.IO.Compression.ZipFile.ExtractToDirectory(zipFilePath, extractFilePath, System.Text.Encoding.UTF8);

                        /*process unzip file*/

                        var zipDirs = System.IO.Directory.GetDirectories(targetFolder);
                        zipDirs.ToList().ForEach(zipDir =>
                        {
                            var dirs = System.IO.Directory.GetDirectories(zipDir);
                            dirs.ToList().ForEach(dir =>
                            {
                                var loop = true;
                                /*search shape file*/
                                while (loop)
                                {
                                    loop      = false;
                                    var files = System.IO.Directory.GetFiles(dir, "*.shp", System.IO.SearchOption.AllDirectories);
                                    /*if dbf file not found then search shp*/
                                    if (files.Count() == 0)
                                    {
                                        files = System.IO.Directory.GetFiles(dir, "*.dbf", System.IO.SearchOption.AllDirectories);
                                    }

                                    files.ToList().ForEach(f =>
                                    {
                                        var fileInfo = new System.IO.FileInfo(f);

                                        try
                                        {
                                            Shapefile indexMapFile = Shapefile.OpenFile(f);
                                            indexMapFile.Reproject(KnownCoordinateSystems.Geographic.Asia.Indian1975);



                                            TDM.Models.Util.LatLngUTMConverter latLngUTMConverter = new TDM.Models.Util.LatLngUTMConverter("WGS 84");
                                            //var rr = latLngUTMConverter.convertLatLngToUtm(15.000095111201411, 100.64638250268084);

                                            string utmShape = "";
                                            foreach (IFeature feature in indexMapFile.Features)
                                            {
                                                if (feature != null && feature.Geometry != null)
                                                {
                                                    utmShape = feature.Geometry.Coordinates
                                                               .Select(coordinate => latLngUTMConverter.convertLatLngToUtm(coordinate.Y, coordinate.X))
                                                               .Select(utm => $"{utm.Easting} {utm.Northing}")
                                                               .Aggregate((current, next) => current + ", " + next);

                                                    geometries.Add(new Geometry()
                                                    {
                                                        //Shape = feature.Geometry.ToString(),
                                                        Shape    = $"{feature.Geometry.OgcGeometryType.ToString().ToUpper()} (({utmShape}))",
                                                        AREA     = Convert.ToDecimal(feature.DataRow["AREA"]),
                                                        ORIGIN_X = feature.DataRow["ORIGIN_X"].ToString(),
                                                        ORIGIN_Y = feature.DataRow["ORIGIN_Y"].ToString()
                                                    });
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            string k = "";
                                        }
                                    });
                                }
                            });
                        });
                    }


                    /*save data*/

                    importInfo.ID   = 0;
                    importInfo.Area = geometries.Sum(g => g.AREA);
                    PROJECT_IMPACT saveProject = tdmEntities.PROJECT_IMPACT.Add(importInfo);
                    tdmEntities.SaveChanges();

                    foreach (var geometry in geometries)
                    {
                        if (!geometry.Shape.Contains("MULTIPO"))
                        {
                            tdmEntities.PROJECT_IMPACT_GEOMETRY.Add(new PROJECT_IMPACT_GEOMETRY()
                            {
                                ProjectImpactID = importInfo.ID,
                                OriginX         = geometry.ORIGIN_X,
                                OriginY         = geometry.ORIGIN_Y,
                                Area            = geometry.AREA,
                                Shape           = (geometry.Shape.Contains("MULTIPO")) ? DbGeometry.MultiPolygonFromText(geometry.Shape, 4326) : DbGeometry.PolygonFromText(geometry.Shape, 4326),
                                UpdateDate      = DateTime.Now,
                                CreateDate      = DateTime.Now
                            });
                        }
                    }

                    tdmEntities.SaveChanges();

                    result = Request.CreateResponse(HttpStatusCode.Created, "Success");
                }
                else
                {
                    result = Request.CreateResponse(HttpStatusCode.BadRequest);
                }
            }
            catch (Exception exc)
            {
                result = Request.CreateResponse(HttpStatusCode.InternalServerError, exc.Message);
            }

            return(result);
        }