Exemplo n.º 1
0
        private OBJECTIVE_POINT BuildOP(OPModel newObjPt)
        {
            OBJECTIVE_POINT newOP = new OBJECTIVE_POINT();

            if (newObjPt.OBJECTIVE_POINT_ID > 0)
            {
                newOP.OBJECTIVE_POINT_ID = newObjPt.OBJECTIVE_POINT_ID;
            }

            newOP.NAME        = newObjPt.NAME;
            newOP.DESCRIPTION = newObjPt.DESCRIPTION;
            if (newObjPt.ELEV_FT.HasValue)
            {
                var radio = Convert.ToString(Request.Form["ElevationUnit"]);
                //elevation is stored in ft, do conversion if == meter
                if (radio == "meter")
                {
                    decimal converted = Convert.ToDecimal(newObjPt.ELEV_FT) * 3.2808M;
                    newOP.ELEV_FT = Math.Round(converted, 3);
                }
                else
                {
                    newOP.ELEV_FT = newObjPt.ELEV_FT;
                }
            }
            newOP.DATE_ESTABLISHED = newObjPt.DATE_ESTABLISHED;
            newOP.OP_IS_DESTROYED  = newObjPt.OP_IS_DESTROYED == null ? 0 : newObjPt.OP_IS_DESTROYED;
            newOP.OP_NOTES         = newObjPt.OP_NOTES;
            newOP.SITE_ID          = newObjPt.SITE_ID;
            newOP.VDATUM_ID        = newObjPt.VDATUM_ID;
            newOP.LATITUDE_DD      = newObjPt.LATITUDE_DD;
            //make sure it's neg
            newOP.LONGITUDE_DD = newObjPt.LONGITUDE_DD.Value < 0 ? newObjPt.LONGITUDE_DD.Value : newObjPt.LONGITUDE_DD.Value * (-1);
            //and that it's only 6 dec places
            newOP.LONGITUDE_DD       = Math.Round(newOP.LONGITUDE_DD.Value, 6);
            newOP.HDATUM_ID          = newObjPt.HDATUM_ID;
            newOP.HCOLLECT_METHOD_ID = newObjPt.HCOLLECT_METHOD_ID;
            newOP.VCOLLECT_METHOD_ID = newObjPt.VCOLLECT_METHOD_ID;
            newOP.OP_TYPE_ID         = newObjPt.OP_TYPE_ID;
            newOP.DATE_RECOVERED     = newObjPt.DATE_RECOVERED;
            if (newObjPt.UNCERTAINTY > 0)
            {
                var rad = Convert.ToString(Request.Form["UncertainUnit"]);
                if (rad == "cm")
                {
                    decimal convertedV = Convert.ToDecimal(newObjPt.UNCERTAINTY) / 30.48M;
                    newOP.UNCERTAINTY = Math.Round(convertedV, 3);
                }
                else
                {
                    newOP.UNCERTAINTY = newObjPt.UNCERTAINTY;
                }
            }

            newOP.UNQUANTIFIED  = newObjPt.UNQUANTIFIED;
            newOP.OP_QUALITY_ID = newObjPt.OP_QUALITY_ID;

            return(newOP);
        }
Exemplo n.º 2
0
        public ActionResult ObjPointCreate(OPModel newObjPt, string Create)
        {
            try
            {
                OBJECTIVE_POINT newOP = BuildOP(newObjPt);

                STNServiceCaller serviceCaller = STNServiceCaller.Instance;
                var request = new RestRequest(Method.POST);
                request.Resource      = "/ObjectivePoints";
                request.RequestFormat = DataFormat.Xml;
                request.AddHeader("Content-Type", "application/xml");

                //use extended serializer
                STNWebSerializer serializer = new STNWebSerializer();
                request.AddParameter("application/xml", serializer.Serialize <OBJECTIVE_POINT>(newOP), ParameterType.RequestBody);
                OBJECTIVE_POINT createdOP = serviceCaller.Execute <OBJECTIVE_POINT>(request);

                //post ControlIdentifiers if some were chosen
                if (newObjPt.OPIdentifiers != null)
                {
                    if (newObjPt.OPIdentifiers.Count >= 1)
                    {
                        foreach (OP_CONTROL_IDENTIFIER opCI in newObjPt.OPIdentifiers)
                        {
                            //post each one for this OP
                            request          = new RestRequest(Method.POST);
                            request.Resource = "ObjectivePoints/{objectivePointId}/AddOPControls";
                            request.AddParameter("objectivePointId", createdOP.OBJECTIVE_POINT_ID, ParameterType.UrlSegment);
                            request.RequestFormat = DataFormat.Xml;
                            request.AddHeader("Content-Type", "application/xml");
                            serializer = new STNWebSerializer();
                            request.AddParameter("application/xml", serializer.Serialize <OP_CONTROL_IDENTIFIER>(opCI), ParameterType.RequestBody);
                            serviceCaller.Execute <OP_CONTROL_IDENTIFIER>(request);
                        }
                    }
                }
                string siteId = newObjPt.SITE_ID.ToString();
                //determine which submit button was selected
                if (Create == "Submit &\r\nAdd Another OP") //Submit & Add Another OP
                {
                    return(RedirectToAction("ObjPointCreate", "ObjPoints", new { siteID = siteId }));
                }
                else if (Create == "Submit &\r\nAdd Upload File")
                {
                    return(RedirectToAction("FileCreate", "Files", new { Id = createdOP.OBJECTIVE_POINT_ID, aPage = "OP" }));
                }
                else if (Create == "Submit &\r\nDeploy Sensor") // Submit & Deploy Sensor
                {
                    return(RedirectToAction("Create", "Instruments", new { siteID = siteId }));
                }
                else if (Create == "Submit\r\n& Add HWM") //Submit & Add HWM
                {
                    return(RedirectToAction("Create", "HWMs", new { siteID = siteId }));
                }
                else //just Submit
                {
                    return(RedirectToAction("Details", "Sites", new { id = siteId }));
                }
            }
            catch (Exception e)
            {
                return(View("../Shared/Error", e));
            }
        }
Exemplo n.º 3
0
        public ActionResult ObjPointEdit(int id, OPModel anObjPtM)
        {
            try
            {
                OBJECTIVE_POINT editedOP = BuildOP(anObjPtM);

                STNServiceCaller serviceCaller = STNServiceCaller.Instance;
                var request = new RestRequest(Method.POST);

                request.Resource      = "/ObjectivePoints/{entityId}";
                request.RequestFormat = DataFormat.Xml;
                request.AddParameter("entityId", id, ParameterType.UrlSegment);
                request.AddHeader("X-HTTP-Method-Override", "PUT");
                request.AddHeader("Content-Type", "application/xml");
                //Use extended serializer
                STNWebSerializer serializer = new STNWebSerializer();
                request.AddParameter("application/xml", serializer.Serialize <OBJECTIVE_POINT>(editedOP), ParameterType.RequestBody);
                OBJECTIVE_POINT anObjPoint = serviceCaller.Execute <OBJECTIVE_POINT>(request);

                if (anObjPtM.OPIdentifiers != null)
                {
                    foreach (OP_CONTROL_IDENTIFIER opi in anObjPtM.OPIdentifiers)
                    {
                        //if it has an id, it's a PUT
                        if (opi.OP_CONTROL_IDENTIFIER_ID == 0)
                        {
                            //POST it
                            request          = new RestRequest(Method.POST);
                            request.Resource = "ObjectivePoints/{objectivePointId}/AddOPControls";
                            request.AddParameter("objectivePointId", editedOP.OBJECTIVE_POINT_ID, ParameterType.UrlSegment);
                            request.RequestFormat = DataFormat.Xml;
                            request.AddHeader("Content-Type", "application/xml");
                            serializer = new STNWebSerializer();
                            request.AddParameter("application/xml", serializer.Serialize <OP_CONTROL_IDENTIFIER>(opi), ParameterType.RequestBody);
                            serviceCaller.Execute <OP_CONTROL_IDENTIFIER>(request);
                        }
                        else
                        {
                            //PUT it
                            opi.OBJECTIVE_POINT_ID = editedOP.OBJECTIVE_POINT_ID;
                            request               = new RestRequest(Method.POST);
                            request.Resource      = "/OPControlIdentifiers/{entityId}";
                            request.RequestFormat = DataFormat.Xml;
                            request.AddParameter("entityId", opi.OP_CONTROL_IDENTIFIER_ID, ParameterType.UrlSegment);
                            request.AddHeader("X-HTTP-Method-Override", "PUT");
                            request.AddHeader("Content-Type", "application/xml");
                            //Use extended serializer
                            serializer = new STNWebSerializer();
                            request.AddParameter("application/xml", serializer.Serialize <OP_CONTROL_IDENTIFIER>(opi), ParameterType.RequestBody);
                            serviceCaller.Execute <OP_CONTROL_IDENTIFIER>(request);
                        }
                    }
//                    List<decimal> identifiersExisted = anObjPtM.IdentifiersIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToDecimal(x)).ToList();
                }

                //remove these
                if (!string.IsNullOrEmpty(anObjPtM.IdentifiersToRemove))
                {
                    List <decimal> identifiersRemoving = anObjPtM.IdentifiersToRemove.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToDecimal(x)).ToList();
                    foreach (decimal identifierID in identifiersRemoving)
                    {
                        //DELETE
                        request          = new RestRequest(Method.POST);
                        request.Resource = "/OPControlIdentifiers/{entityId}";
                        request.AddParameter("entityId", identifierID, ParameterType.UrlSegment);
                        request.AddHeader("X-HTTP-Method-Override", "DELETE");
                        request.AddHeader("Content-Type", "application/xml");

                        serviceCaller.Execute <OP_CONTROL_IDENTIFIER>(request);
                    }
                }

                return(RedirectToAction("ObjPointDetailsPV", new { id = editedOP.OBJECTIVE_POINT_ID }));
            }
            catch (Exception e)
            {
                return(View("../Shared/Error", e));
            }
        }