Ejemplo n.º 1
0
        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());
            }
        }
Ejemplo n.º 2
0
        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");
            }
        }
Ejemplo n.º 3
0
        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");
            }
        }