コード例 #1
0
ファイル: PartsController.cs プロジェクト: troddick/BLTWeb
        public ActionResult Division_New(DIVISION newDiv)
        {
            try
            {
                BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
                var request = new RestRequest(Method.POST);

                request.Resource = "/Divisions";
                request.RequestFormat = DataFormat.Xml;
                request.AddHeader("Content-Type", "application/xml");
                //Use extended serializer
                BLTWebSerializer serializer = new BLTWebSerializer();
                request.AddParameter("application/xml", serializer.Serialize<DIVISION>(newDiv), ParameterType.RequestBody);

                DIVISION createdDiv = serviceCaller.Execute<DIVISION>(request);

                return RedirectToAction("../Parts/Index");
            }
            catch (Exception e)
            {
                return View(e.ToString());
            }
        }
コード例 #2
0
ファイル: PartsController.cs プロジェクト: troddick/BLTWeb
        public ActionResult CropUse_Edit(int id, CROP_USE editedCropUse)
        {
            BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
            var request = new RestRequest(Method.POST);
            request.Resource = "/CropUses/{entityID}";
            request.RequestFormat = DataFormat.Xml;
            request.AddParameter("entityID", id, ParameterType.UrlSegment);
            request.AddHeader("X-HTTP-Method-Override", "PUT");
            //Use extended serializer
            BLTWebSerializer serializer = new BLTWebSerializer();
            request.AddParameter("application/xml", serializer.Serialize<CROP_USE>(editedCropUse), ParameterType.RequestBody);
            CROP_USE updatedCropUse = serviceCaller.Execute<CROP_USE>(request);

            //update the AI and go back to the AI index
            return RedirectToAction("Index");
        }
コード例 #3
0
ファイル: PartsController.cs プロジェクト: troddick/BLTWeb
        public ActionResult Division_Edit(int id, DIVISION editedDiv)
        {
            BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
            var request = new RestRequest(Method.POST);
            request.Resource = "/Divisions/{divisionID}";
            request.RequestFormat = DataFormat.Xml;
            request.AddParameter("divisionID", id, ParameterType.UrlSegment);
            request.AddHeader("X-HTTP-Method-Override", "PUT");

            //Use extended serializer
            BLTWebSerializer serializer = new BLTWebSerializer();
            request.AddParameter("application/xml", serializer.Serialize<DIVISION>(editedDiv), ParameterType.RequestBody);
            DIVISION updatedDiv = serviceCaller.Execute<DIVISION>(request);

            //update the AI and go back to the AI index
            return RedirectToAction("Index");
        }
コード例 #4
0
ファイル: PartsController.cs プロジェクト: troddick/BLTWeb
        public ActionResult AI_New(AIModel newAI)
        {
            try
            {
                BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
                var request = new RestRequest(Method.POST);

                request.Resource = "/ActiveIngredients";
                request.RequestFormat = DataFormat.Xml;
                request.AddHeader("Content-Type", "application/xml");
                //Use extended serializer
                BLTWebSerializer serializer = new BLTWebSerializer();
                request.AddParameter("application/xml", serializer.Serialize<ACTIVE_INGREDIENT>(newAI.AI), ParameterType.RequestBody);
                ACTIVE_INGREDIENT createdAI = serviceCaller.Execute<ACTIVE_INGREDIENT>(request);

                //if Products were chosen, add to PRODUCT_ACTIVE_INGREDIENT
                if (newAI.AIProdsToAdd != null)
                {
                    if (newAI.AIProdsToAdd.Length >= 1)
                    {
                        string[] prods = Regex.Split(newAI.AIProdsToAdd, ",");
                        List<PRODUCT> productList = new List<PRODUCT>();

                        foreach (string pr in prods)
                        {
                            if (!string.IsNullOrWhiteSpace(pr))
                            {
                                request = new RestRequest(Method.POST);
                                request.Resource = "/Products/{entityID}/AddProductToAI";
                                request.AddParameter("entityID", Convert.ToDecimal(pr), ParameterType.UrlSegment);
                                request.RequestFormat = DataFormat.Xml;
                                request.XmlSerializer = new RestSharp.Serializers.DotNetXmlSerializer();
                                request.AddBody(createdAI);
                                serviceCaller.Execute<PRODUCT_ACTIVE_INGREDIENT>(request);
                            }
                        }
                    }
                }
                //if AIClasses were chosen, add to ACTIVE_INGREDIENT_AI_CLASS
                if (newAI.AIClassesToAdd != null)
                {
                    if (newAI.AIClassesToAdd.Length >= 1)
                    {
                        string[] AIclasses = Regex.Split(newAI.AIClassesToAdd, ",");
                        List<AI_CLASS> aiClList = new List<AI_CLASS>();

                        foreach (string aic in AIclasses)
                        {
                            if (!string.IsNullOrWhiteSpace(aic))
                            {
                                //now post it
                                request = new RestRequest(Method.POST);
                                request.Resource = "/AIClasses/{entityID}/AddAIClass";
                                request.AddParameter("entityID", Convert.ToDecimal(aic), ParameterType.UrlSegment);
                                request.RequestFormat = DataFormat.Xml;
                                request.XmlSerializer = new RestSharp.Serializers.DotNetXmlSerializer();
                                request.AddBody(createdAI);
                                ACTIVE_INGREDIENT_AI_CLASS newAIcAI = serviceCaller.Execute<ACTIVE_INGREDIENT_AI_CLASS>(request);
                            }
                        }
                    }
                }
                return RedirectToAction("../Parts/Index");
            }
            catch (Exception e)
            {
                return View(e.ToString());
            }
        }
コード例 #5
0
ファイル: PartsController.cs プロジェクト: troddick/BLTWeb
        public ActionResult ApplicationMethods_New(APPLICATION_METHOD newApplicationMethod)
        {
            try
            {
                BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
                var request = new RestRequest(Method.POST);

                request.Resource = "/ApplicationMethods";
                request.RequestFormat = DataFormat.Xml;
                request.AddHeader("Content-Type", "application/xml");
                //Use extended serializer
                BLTWebSerializer serializer = new BLTWebSerializer();
                request.AddParameter("application/xml", serializer.Serialize<APPLICATION_METHOD>(newApplicationMethod), ParameterType.RequestBody);

                APPLICATION_METHOD createdApplicationMethod = serviceCaller.Execute<APPLICATION_METHOD>(request);

                //now activate it for use
                //request = new RestRequest();
                //request.Resource = "/ApplicationMethods/{entityID}/Activate?ActiveDate={date}";
                //request.RootElement = "APPLICATION_METHOD";
                //request.AddParameter("entityID", createdApplicationMethod.ID, ParameterType.UrlSegment);
                //APPLICATION_METHOD activatedAppMeth = serviceCaller.Execute<APPLICATION_METHOD>(request);

                return RedirectToAction("../Parts/Index");
            }
            catch (Exception e)
            {
                return View(e.ToString());
            }
        }
コード例 #6
0
ファイル: PartsController.cs プロジェクト: troddick/BLTWeb
        public ActionResult AI_Copy(ACTIVE_INGREDIENT newAI)
        {
            try
            {
                BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
                var request = new RestRequest(Method.POST);

                request.Resource = "/ActiveIngredients";
                request.RequestFormat = DataFormat.Xml;
                request.AddHeader("Content-Type", "application/xml");
                //Use extended serializer
                BLTWebSerializer serializer = new BLTWebSerializer();
                request.AddParameter("application/xml", serializer.Serialize<ACTIVE_INGREDIENT>(newAI), ParameterType.RequestBody);

                ACTIVE_INGREDIENT createdAI = serviceCaller.Execute<ACTIVE_INGREDIENT>(request);

                return RedirectToAction("../Parts/Index");
            }
            catch (Exception e)
            {
                return View(e.ToString());
            }
        }
コード例 #7
0
ファイル: PartsController.cs プロジェクト: troddick/BLTWeb
        public ActionResult AI_Edit(int id, AIModel updatedAIModel)
        {
            ACTIVE_INGREDIENT thisAI = updatedAIModel.AI;
            string AIClasses2Add = updatedAIModel.AIClassesToAdd;
            string AIClasses2Remove = updatedAIModel.AIClassesIDsToRemove;

            BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
            var request = new RestRequest();
            //see if any products have been related or any removed from relationship
            //if prodsToRemove != null -> expire those
            if (!string.IsNullOrWhiteSpace(AIClasses2Remove))
            {
                //parse entityIDs
                string[] RemoveAIC = Regex.Split(AIClasses2Remove, ",");
                foreach (string p in RemoveAIC)
                {
                    if (!string.IsNullOrWhiteSpace(p))
                    {
                        if (thisAI != null)
                        {
                            //send request to expire it
                            request = new RestRequest(Method.POST);
                            request.Resource = "/AIClasses/{entityID}/RemoveAIClassFromAI?activeIngredientID={aiEntityID}";
                            request.AddParameter("entityID", Convert.ToDecimal(p), ParameterType.UrlSegment);
                            request.AddParameter("aiEntityID", Convert.ToDecimal(thisAI.ACTIVE_INGREDIENT_ID), ParameterType.UrlSegment);
                            request.AddHeader("X-HTTP-Method-Override", "DELETE");
                            request.AddHeader("Content-Type", "application/xml");
                            serviceCaller.Execute<AI_CLASS>(request);
                        }
                    }
                }
            }
            // if prodsToAdd != null -> post those (there's a check to see if they already exist)
            if (!string.IsNullOrWhiteSpace(AIClasses2Add))
            {
                //parse
                string[] AddAIC = Regex.Split(AIClasses2Add, ",").ToArray();
                foreach (string a in AddAIC)
                {
                    if (!string.IsNullOrWhiteSpace(a))
                    {
                        if (thisAI != null)
                        {
                            request = new RestRequest(Method.POST);
                            request.Resource = "/AIClasses/{entityID}/AddAIClass";
                            request.AddParameter("entityID", Convert.ToDecimal(a), ParameterType.UrlSegment);
                            request.RequestFormat = DataFormat.Xml;
                            request.XmlSerializer = new RestSharp.Serializers.DotNetXmlSerializer();
                            request.AddBody(thisAI);
                            ACTIVE_INGREDIENT_AI_CLASS newAIC = serviceCaller.Execute<ACTIVE_INGREDIENT_AI_CLASS>(request);
                        }
                    }
                }
            }

            request = new RestRequest(Method.POST);
            request.Resource = "/ActiveIngredients/{entityID}";
            request.RequestFormat = DataFormat.Xml;
            request.AddParameter("entityID", id, ParameterType.UrlSegment);
            request.AddHeader("X-HTTP-Method-Override", "PUT");
            //Use extended serializer
            BLTWebSerializer serializer = new BLTWebSerializer();
            request.AddParameter("application/xml", serializer.Serialize<ACTIVE_INGREDIENT>(thisAI), ParameterType.RequestBody);
            ACTIVE_INGREDIENT updatedAI = serviceCaller.Execute<ACTIVE_INGREDIENT>(request);

            //update the AI and go back to the AI index
            return RedirectToAction("Index");
        }
コード例 #8
0
ファイル: PartsController.cs プロジェクト: troddick/BLTWeb
        public ActionResult Product_New(PRODUCT newProduct)
        {
            try
            {
                BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
                var request = new RestRequest(Method.POST);

                request.Resource = "/Products";
                request.RequestFormat = DataFormat.Xml;
                request.AddHeader("Content-Type", "application/xml");
                //Use extended serializer
                BLTWebSerializer serializer = new BLTWebSerializer();
                request.AddParameter("application/xml", serializer.Serialize<PRODUCT>(newProduct), ParameterType.RequestBody);

                PRODUCT createdProd = serviceCaller.Execute<PRODUCT>(request);

                //now activate it for use
                //request = new RestRequest();
                //request.Resource = "/Products/{entityID}/Activate?ActiveDate={date}";
                //request.RootElement = "PRODUCT";
                //request.AddParameter("entityID", createdProd.ID, ParameterType.UrlSegment);
                //PRODUCT activatedProd = serviceCaller.Execute<PRODUCT>(request);

                return RedirectToAction("../Parts/Index");
            }
            catch (Exception e)
            {
                return View(e.ToString());
            }
        }
コード例 #9
0
ファイル: PartsController.cs プロジェクト: troddick/BLTWeb
        public ActionResult AI_Class_New(AI_CLASS newAIClass)
        {
            try
            {
                BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
                var request = new RestRequest(Method.POST);
                request.Resource = "/AIClasses";
                request.RequestFormat = DataFormat.Xml;
                request.AddHeader("Content-Type", "application/xml");
                //Use extended serializer
                BLTWebSerializer serializer = new BLTWebSerializer();
                request.AddParameter("application/xml", serializer.Serialize<AI_CLASS>(newAIClass), ParameterType.RequestBody);

                AI_CLASS createdAIclass = serviceCaller.Execute<AI_CLASS>(request);

                ////now activate it for use
                //request = new RestRequest();
                //request.Resource = "/AIClasses/{entityID}/Activate?ActiveDate={date}";
                //request.RootElement = "AI_CLASS";
                //request.AddParameter("entityID", createdAIclass.ID, ParameterType.UrlSegment);
                //AI_CLASS activatedaiClass = serviceCaller.Execute<AI_CLASS>(request);

                return RedirectToAction("../Parts/Index");
            }
            catch (Exception e)
            {
                return View(e.ToString());
            }
        }
コード例 #10
0
ファイル: PartsController.cs プロジェクト: troddick/BLTWeb
        public ActionResult Formulations_New(FORMULATION newFormulation)
        {
            try
            {
                BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
                var request = new RestRequest(Method.POST);

                request.Resource = "/Formulations";
                request.RequestFormat = DataFormat.Xml;
                request.AddHeader("Content-Type", "application/xml");
                //Use extended serializer
                BLTWebSerializer serializer = new BLTWebSerializer();
                request.AddParameter("application/xml", serializer.Serialize<FORMULATION>(newFormulation), ParameterType.RequestBody);

                FORMULATION createdFormulation = serviceCaller.Execute<FORMULATION>(request);

                //now activate it for use
                //request = new RestRequest();
                //request.Resource = "/Formulations/{entityID}/Activate?ActiveDate={date}";
                //request.RootElement = "FORMULATION";
                //request.AddParameter("entityID", createdFormulation.ID, ParameterType.UrlSegment);
                //FORMULATION activatedMod = serviceCaller.Execute<FORMULATION>(request);

                return RedirectToAction("../Parts/Index");
            }
            catch (Exception e)
            {
                return View(e.ToString());
            }
        }
コード例 #11
0
ファイル: PULAController.cs プロジェクト: troddick/BLTWeb
        public ActionResult ContributorDetails(PULA_Model thisPULA)
        {
            try
            {
                ACTIVE_INGREDIENT_PULA anAIPula = new ACTIVE_INGREDIENT_PULA();
                string commentName = thisPULA.CommentName;
                string commentOrg = thisPULA.CommentOrg;
                string comment = thisPULA.Comment;
                string fullCOMMENT = "[" + commentName + "|" + commentOrg + "|" + comment + "]";
                anAIPula.COMMENTS = fullCOMMENT;

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

                request.Resource = "/PULAs/{pulaID}/AddComments";
                request.RequestFormat = DataFormat.Xml;
                request.AddParameter("pulaID", thisPULA.anAIPULA.ID, ParameterType.UrlSegment);
                request.AddHeader("X-HTTP-Method-Override", "PUT");
                request.AddHeader("Content-Type", "application/xml");
                //Use extended serializer
                BLTWebSerializer serializer = new BLTWebSerializer();
                request.AddParameter("application/xml", serializer.Serialize<ACTIVE_INGREDIENT_PULA>(anAIPula), ParameterType.RequestBody);
                serviceCaller.Execute<ACTIVE_INGREDIENT_PULA>(request);

                return RedirectToAction("ThankYou");
            }
            catch (Exception e)
            {
                return RedirectToAction("Error", e.ToString());
            }
        }
コード例 #12
0
ファイル: PULAController.cs プロジェクト: troddick/BLTWeb
        public ActionResult PULAEdit(PULA_Model thisPULA, string Create)
        {
            if (Create == "Cancel")
            {
                return RedirectToAction("PULA_Details", new { shapeId = thisPULA.anAIPULA.PULA_SHAPE_ID, date = DateTime.Now });
            }

            ACTIVE_INGREDIENT_PULA updatedPULA = new ACTIVE_INGREDIENT_PULA();
            try
            {
                //if Create == "Save Changes" or "Publish", Update everything

                ACTIVE_INGREDIENT_PULA anAIPULA = thisPULA.anAIPULA;
                if (thisPULA.EffMonths != null)
                {
                    string EffectiveMonth = thisPULA.EffMonths;
                    string EffectiveYear = thisPULA.EffYears;
                    string effectiveDate = EffectiveMonth + "/01/" + EffectiveYear;
                    anAIPULA.EFFECTIVE_DATE = DateTime.Parse(effectiveDate);
                }
                BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
                var request = new RestRequest(Method.POST);
                request.Resource = "/PULAs/{entityID}";
                request.RequestFormat = DataFormat.Xml;
                request.AddParameter("entityID", anAIPULA.ID, ParameterType.UrlSegment);
                request.AddHeader("X-HTTP-Method-Override", "PUT");
                //Use extended serializer
                BLTWebSerializer serializer = new BLTWebSerializer();
                request.AddParameter("application/xml", serializer.Serialize<ACTIVE_INGREDIENT_PULA>(anAIPULA), ParameterType.RequestBody);
                updatedPULA = serviceCaller.Execute<ACTIVE_INGREDIENT_PULA>(request);

                //update expire timestamp on version if changed
                if (thisPULA.ExpirationChanged == "true")
                {
                    string ExpireMonth = thisPULA.ExMonths;
                    string ExpireYear = thisPULA.ExYears;
                    string expirationDate = ExpireMonth + "/01/" + ExpireYear;
                    request = new RestRequest();
                    request.Resource = "/PULAs/{entityID}/updateStatus?status={status}&statusDate={date}";
                    request.RootElement = "ACTIVE_INGREDIENT_PULA";
                    request.AddParameter("entityID", updatedPULA.ID, ParameterType.UrlSegment);
                    request.AddParameter("status", "EXPIRED", ParameterType.UrlSegment);
                    request.AddParameter("date", expirationDate, ParameterType.UrlSegment);
                    ACTIVE_INGREDIENT_PULA updatedPULA2 = serviceCaller.Execute<ACTIVE_INGREDIENT_PULA>(request);
                }

                //update spp
                //see if any were removed
                if (thisPULA.SpeciesToRemove != null)
                {
                    SpeciesList SppList = new SpeciesList();
                    string[] RemoveSpp = Regex.Split(thisPULA.SpeciesToRemove, ",");
                    List<Int32> speciesIDs = new List<int>();
                    foreach (string rs in RemoveSpp)
                    {
                        if (!(string.IsNullOrWhiteSpace(rs)))
                        {
                            speciesIDs.Add(Convert.ToInt32(rs));
                        }
                    }
                    SppList.SPECIES = speciesIDs.Select(s => new SimpleSpecies { ENTITY_ID = s }).ToList<SimpleSpecies>();
                    //now remove all of them
                    request = new RestRequest(Method.POST);
                    request.Resource = "/PULAs/{entityID}/RemoveSpeciesFromPULA?publishedDate={date}";
                    request.RootElement = "SpeciesList";
                    request.AddParameter("entityID", updatedPULA.PULA_ID, ParameterType.UrlSegment);
                    request.AddHeader("Content-Type", "application/xml");
                    //Use extended serializer
                    serializer = new BLTWebSerializer();
                    request.AddParameter("application/xml", serializer.Serialize<SpeciesList>(SppList), ParameterType.RequestBody);
                    serviceCaller.Execute<SpeciesList>(request);
                }

                //now add the spp
                if (thisPULA.SpeciesToAdd != null)
                {
                    SpeciesList aSppList = new SpeciesList();
                    string[] AddSpp = Regex.Split(thisPULA.SpeciesToAdd, ",");
                    List<Int32> sppIDs = new List<int>();
                    foreach (string addS in AddSpp)
                    {
                        if (!(string.IsNullOrWhiteSpace(addS)))
                        {
                            sppIDs.Add(Convert.ToInt32(addS));
                        }
                    }
                    aSppList.SPECIES = sppIDs.Select(s => new SimpleSpecies { ENTITY_ID = s }).ToList<SimpleSpecies>();
                    //now add all of them
                    request = new RestRequest(Method.POST);
                    request.Resource = "/PULAs/{entityID}/AddSpeciesToPULA?publishedDate={date}";
                    request.RootElement = "SpeciesList";
                    request.AddParameter("entityID", updatedPULA.PULA_ID, ParameterType.UrlSegment);
                    request.AddHeader("Content-Type", "application/xml");
                    //Use extended serializer
                    serializer = new BLTWebSerializer();
                    request.AddParameter("application/xml", serializer.Serialize<SpeciesList>(aSppList), ParameterType.RequestBody);
                    serviceCaller.Execute<SpeciesList>(request);
                }

                if (thisPULA.ExistingLimitToRemove != null)
                {
                    string[] RemoveLim = Regex.Split(thisPULA.ExistingLimitToRemove, ",");
                    foreach (string rl in RemoveLim)
                    {
                        if (!(string.IsNullOrWhiteSpace(rl)))
                        {
                            //now removeit
                            request = new RestRequest(Method.POST);
                            request.Resource = "/PULALimitation/{entityID}";
                            request.AddParameter("entityID", Convert.ToInt32(rl), ParameterType.UrlSegment);
                            request.AddHeader("X-HTTP-Method-Override", "DELETE");
                            request.AddHeader("Content-Type", "application/xml");
                            serviceCaller.Execute<PULA_LIMITATIONS>(request);
                        }
                    }
                }

                //now add the pula limitations
                if (thisPULA.LimitationsToAdd != null)
                {
                    //PULA_LIMITATIONS
                    List<PULA_LIMITATIONS> pulaLimitations = new List<PULA_LIMITATIONS>();
                    // parse it out by the [ ]
                    string[] eachLim = Regex.Split(thisPULA.LimitationsToAdd, "]");

                    // find out if its an A or P (AI or Product) at the start
                    foreach (string e in eachLim)
                    {
                        PULA_LIMITATIONS thisLimit = new PULA_LIMITATIONS();
                        if (e.Contains("A"))
                        {
                            //it's an AI limitation (aiID,useID,amID,formID,codeID )
                            //parse it again on the ","
                            string[] aiLimit = Regex.Split(e, ",");
                            aiLimit = aiLimit.Where(x => !string.IsNullOrEmpty(x)).ToArray();
                            if (aiLimit[0] != "0")
                            {
                                thisLimit.PULA_ID = updatedPULA.PULA_ID;
                                thisLimit.ACTIVE_INGREDIENT_ID = Convert.ToDecimal(aiLimit[0].Substring(2)); //errored here.. check this
                                thisLimit.CROP_USE_ID = Convert.ToDecimal(aiLimit[1]);
                                thisLimit.APPLICATION_METHOD_ID = Convert.ToDecimal(aiLimit[2]);
                                thisLimit.FORMULATION_ID = Convert.ToDecimal(aiLimit[3]);
                                thisLimit.LIMITATION_ID = Convert.ToDecimal(aiLimit[4]);
                            }
                        }
                        else if (e.Contains("P"))
                        {
                            //it's a Product Limitation (prodID,useID,amID,formID,codeID )
                            string[] prLimit = Regex.Split(e, ",");
                            prLimit = prLimit.Where(x => !string.IsNullOrEmpty(x)).ToArray();
                            if (prLimit[0] != "0")
                            {

                                thisLimit.PULA_ID = updatedPULA.PULA_ID;
                                thisLimit.PRODUCT_ID = Convert.ToDecimal(prLimit[0].Substring(2));
                                thisLimit.CROP_USE_ID = Convert.ToDecimal(prLimit[1]);
                                thisLimit.APPLICATION_METHOD_ID = Convert.ToDecimal(prLimit[2]);
                                thisLimit.FORMULATION_ID = Convert.ToDecimal(prLimit[3]);
                                thisLimit.LIMITATION_ID = Convert.ToDecimal(prLimit[4]);
                            }
                        }
                        //add it to the list of PULALimitations to POST (make sure there's a populated pulaLimitation first
                        if (thisLimit.FORMULATION_ID > 0)
                        {
                            pulaLimitations.Add(thisLimit);
                        }
                    }

                    //now that i have the pula-limitations, post them
                    foreach (PULA_LIMITATIONS pl in pulaLimitations)
                    {
                        //post it
                        request = new RestRequest(Method.POST);
                        request.Resource = "PULALimitations";
                        request.AddHeader("Content-Type", "application/xml");
                        //Use extended serializer
                        serializer = new BLTWebSerializer();
                        request.AddParameter("application/xml", serializer.Serialize<PULA_LIMITATIONS>(pl), ParameterType.RequestBody);
                        PULA_LIMITATIONS createdPULALimit = serviceCaller.Execute<PULA_LIMITATIONS>(request);
                    }
                } //end if (thisPULA.LimitationsToAdd != null)

                if (Create == "Publish PULA")
                {
                    request = new RestRequest();
                    request.Resource = "/PULAs/{entityID}/updateStatus?status={status}&statusDate={date}";
                    request.RootElement = "ACTIVE_INGREDIENT_PULA";
                    request.AddParameter("entityID", updatedPULA.ID, ParameterType.UrlSegment);
                    request.AddParameter("status", "published", ParameterType.UrlSegment);
                    request.AddParameter("date", DateTime.Now.Date, ParameterType.UrlSegment);
                    //ACTIVE_INGREDIENT_PULA publishedPULA = serviceCaller.Execute<ACTIVE_INGREDIENT_PULA>(request);
                    //may be null coming back if effective date is > published date or not set at all
                } //end if (Create == "Publish PULA")

                return RedirectToAction("PULA_Details", new { shapeId = updatedPULA.PULA_SHAPE_ID, date = DateTime.Now, status = "update" });
            }
            catch
            {
                return RedirectToAction("ErrorPage");
            }
        }
コード例 #13
0
ファイル: PULAController.cs プロジェクト: troddick/BLTWeb
        public ActionResult PULACreate(PULA_Model thisPULA)
        {
            try
            {
                BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
                var request = new RestRequest(Method.POST);

                //post the ACTIVE_INGREDIENT_PULA
                ACTIVE_INGREDIENT_PULA anAIPULA = thisPULA.anAIPULA;

                //format created date

                //format effective Date
                if (!string.IsNullOrWhiteSpace(thisPULA.EffMonths))
                {
                    string effectiveMonth = thisPULA.EffMonths;
                    string effectiveYear = thisPULA.EffYears;
                    string effectiveDate = effectiveMonth + "/01/" + effectiveYear;
                    anAIPULA.EFFECTIVE_DATE = DateTime.Parse(effectiveDate);
                }

                request.Resource = "/PULAs";
                request.RequestFormat = DataFormat.Xml;
                request.AddHeader("Content-Type", "application/xml");
                //Use extended serializer
                BLTWebSerializer serializer = new BLTWebSerializer();
                request.AddParameter("application/xml", serializer.Serialize<ACTIVE_INGREDIENT_PULA>(anAIPULA), ParameterType.RequestBody);
                ACTIVE_INGREDIENT_PULA createdPULA = serviceCaller.Execute<ACTIVE_INGREDIENT_PULA>(request);

                //if expiration date is set, ExpirePULA
                if (!string.IsNullOrWhiteSpace(thisPULA.ExMonths))
                {
                    string ExpireMonth = thisPULA.ExMonths;
                    string ExpireYear = thisPULA.ExYears;
                    string expirationDate = ExpireMonth + "/01/" + ExpireYear;
                    request = new RestRequest();
                    request.Resource = "/PULAs/{entityID}/updateStatus?status={status}&statusDate={date}";
                    request.RootElement = "ACTIVE_INGREDIENT_PULA";
                    request.AddParameter("entityID", createdPULA.ID, ParameterType.UrlSegment);
                    request.AddParameter("status", "EXPIRED", ParameterType.UrlSegment);
                    request.AddParameter("date", expirationDate, ParameterType.UrlSegment);
                    serviceCaller.Execute<ACTIVE_INGREDIENT_PULA>(request);
                }

                //add SPECIES_ACTIVE_INGREDIENT_PULA
                SpeciesList theSPpList = new SpeciesList();
                if (!string.IsNullOrWhiteSpace(thisPULA.SpeciesToAdd))
                {
                    List<Int32> speciesIDs = new List<int>();
                    //parse
                    string[] spp = Regex.Split(thisPULA.SpeciesToAdd, ",");
                    //put them into a list of ints to add to the simpleSpecies
                    foreach (string sp in spp)
                    {
                        if (!string.IsNullOrEmpty(sp))
                        {
                            speciesIDs.Add(Convert.ToInt32(sp));
                        }
                    }
                    //create a SimpleSpecies with each id (s)
                    theSPpList.SPECIES = speciesIDs.Select(s => new SimpleSpecies { ENTITY_ID = s }).ToList<SimpleSpecies>();

                    //now post the list
                    request = new RestRequest(Method.POST);
                    request.Resource = "PULAs/{entityID}/AddSpeciesToPULA?publishedDate={date}";
                    request.AddParameter("entityID", createdPULA.PULA_ID, ParameterType.UrlSegment);
                    request.AddHeader("Content-Type", "application/xml");
                    //Use extended serializer
                    serializer = new BLTWebSerializer();
                    request.AddParameter("application/xml", serializer.Serialize<SpeciesList>(theSPpList), ParameterType.RequestBody);
                   SpeciesList createdAIsppList = serviceCaller.Execute<SpeciesList>(request);
                }

                //post each PULA_LIMITATIONS
                List<PULA_LIMITATIONS> pulaLimitations = new List<PULA_LIMITATIONS>();

                if (!string.IsNullOrWhiteSpace(thisPULA.LimitationsToAdd))
                {
                    // parse it out by the [ ]
                    string[] eachLim = Regex.Split(thisPULA.LimitationsToAdd, "]");

                    // find out if its an A or P (AI or Product) at the start
                    foreach (string e in eachLim)
                    {
                        PULA_LIMITATIONS thisLimit = new PULA_LIMITATIONS();
                        if (e.Contains("A"))
                        {
                            //it's an AI limitation (aiID,useID,amID,formID,codeID )
                            //parse it again on the ","
                            string[] aiLimit = Regex.Split(e, ",");

                            //make sure there are no empty ones
                            aiLimit = aiLimit.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                            //populate the PULA_LIMITATION
                            if (aiLimit[0] != "0")
                            {
                                thisLimit.PULA_ID = createdPULA.PULA_ID;
                                thisLimit.ACTIVE_INGREDIENT_ID = Convert.ToDecimal(aiLimit[0].Substring(2));
                                thisLimit.CROP_USE_ID = Convert.ToDecimal(aiLimit[1]);
                                thisLimit.APPLICATION_METHOD_ID = Convert.ToDecimal(aiLimit[2]);
                                thisLimit.FORMULATION_ID = Convert.ToDecimal(aiLimit[3]);
                                thisLimit.LIMITATION_ID = Convert.ToDecimal(aiLimit[4]);
                            }
                        }
                        else if (e.Contains("P"))
                        {
                            //it's a Product Limitation (prodID,useID,amID,formID,codeID )
                            string[] prLimit = Regex.Split(e, ",");

                            //make sure there are no empty ones
                            prLimit = prLimit.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                            //populate the PULA_LIMITATION
                            if (prLimit[0] != "0")
                            {
                                thisLimit.PULA_ID = createdPULA.PULA_ID;
                                thisLimit.PRODUCT_ID = Convert.ToDecimal(prLimit[0].Substring(2));
                                thisLimit.CROP_USE_ID = Convert.ToDecimal(prLimit[1]);
                                thisLimit.APPLICATION_METHOD_ID = Convert.ToDecimal(prLimit[2]);
                                thisLimit.FORMULATION_ID = Convert.ToDecimal(prLimit[3]);
                                thisLimit.LIMITATION_ID = Convert.ToDecimal(prLimit[4]);
                            }
                        }
                        //add it to the list of PULALimitations to POST (make sure there's a populated pulaLimitation first
                        if (thisLimit.FORMULATION_ID > 0)
                        {
                            pulaLimitations.Add(thisLimit);
                        }
                    }
                }

                //now that i have the pula-limitations, post them
                foreach (PULA_LIMITATIONS pl in pulaLimitations)
                {
                    //post it
                    request = new RestRequest(Method.POST);
                    request.Resource = "PULALimitations";
                    request.AddHeader("Content-Type", "application/xml");
                    serializer = new BLTWebSerializer();
                    request.AddParameter("application/xml", serializer.Serialize<PULA_LIMITATIONS>(pl), ParameterType.RequestBody);
                    PULA_LIMITATIONS createdPULALimit = serviceCaller.Execute<PULA_LIMITATIONS>(request);
                }
                ViewData["UpdatePULA"] = "Created";
                return RedirectToAction("PULA_Details", new { shapeId = createdPULA.PULA_SHAPE_ID, date = DateTime.Now, status = "update" });
            }
            catch
            {
                return RedirectToAction("ErrorPage");
            }
        }
コード例 #14
0
ファイル: UsersController.cs プロジェクト: troddick/BLTWeb
        public ActionResult UserCreate(USER_ newUser)
        {
            try
            {
                BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
                var request = new RestRequest(Method.POST);
                request.Resource = "/Users";
                request.RequestFormat = DataFormat.Xml;
                request.AddHeader("Content-Type", "application/xml");
                //Use extended serializer
                BLTWebSerializer serializer = new BLTWebSerializer();
                request.AddParameter("application/xml", serializer.Serialize<USER_>(newUser), ParameterType.RequestBody);
                USER_ createdUser = serviceCaller.Execute<USER_>(request);

                return RedirectToAction("UserDetails", new { id = createdUser.USER_ID });
            }
            catch
            {
                return View();
            }
        }