Exemple #1
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");
            }
        }
Exemple #2
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());
            }
        }
Exemple #3
0
        private StringBuilder GetFormattedExportContent(ACTIVE_INGREDIENT_PULA pula)
        {
            StringBuilder sb = new StringBuilder();

            string[] comments = pula.COMMENTS.Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
            List<CommentsModel> allComments = new List<CommentsModel>();
            foreach (string c in comments)
            {
                CommentsModel aComment = new CommentsModel();
                string[] aCom = c.Split('|');
                foreach (string ac in aCom)
                {
                    aComment.Name = aCom[0];
                    aComment.Org = aCom[1];
                    aComment.Comment = aCom[2];
                }
                allComments.Add(aComment);
            }

            string header1 = "PULA Comments";
            sb.AppendLine(header1);

            sb.AppendLine("Name,Organization,Comment");
            foreach (var c in allComments)
            {
                sb.AppendLine(c.Name + "," + c.Org + "," + c.Comment);
            }

            return sb;
        }