예제 #1
0
        /// <summary>
        /// Inserts a new role into the db.
        /// </summary>
        /// <param name="role">The role to add.</param>
        /// <returns>true if the role is valid and successfully added.</returns>
        public bool Insert(Parcel parcel)
        {
            if (parcel.Validate())
            {
                parcel.ParcelID = ObjectId.GenerateNewId();
                SafeModeResult result = Parcels.Insert(parcel);

                return true;
            }
            else return false;
        }
예제 #2
0
        public JsonResult UploadPhase(ObjectId id, HttpPostedFileBase shapeFile)
        {
            bool success = true;

            try
            {
                dynamic file = LoadFile(shapeFile);

                if (file != null)
                {
                    // remove old parcels
                    Context.Parcels.DeleteByPhaseID(id);

                    // add the new parcels
                    List<Parcel> parcels = new List<Parcel>();

                    foreach (var feature in file.features)
                    {
                        Parcel parcel = new Parcel()
                        {
                            ParcelName = feature.properties.Name,
                            ParcelLength = feature.properties.Shape_Leng,
                            ParcelAcres = feature.properties.Acres,
                            ParcelArea = feature.properties.Shape_Area,
                            PhaseId = id
                        };

                        foreach (var coord in feature.geometry.coordinates[0])
                        {
                            parcel.ParcelShape.Add(new Coordinate { Latitude = coord[0], Longitude = coord[1] });
                        }

                        parcels.Add(parcel);
                    }


                    success = Context.Parcels.InsertBatch(parcels);
                }
            }
            catch { success = false; }

            return Json(new { success = success });
        }