コード例 #1
0
ファイル: PULAController.cs プロジェクト: troddick/BLTWeb
        //pula was clicked in mapper, show info in popup
        // GET: /PULA_Details/11
        public PartialViewResult PULA_Details(int shapeId, DateTime date, string status)
        {
            if (status != null)
                ViewData["UpdatePULA"] = "updated";

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

            //get the ACTIVE_INGREDIENT_PULA
            request.Resource = "/PULAs/POI/{shapeId}?publishedDate={date}";
            request.RootElement = "ACTIVE_INGREDIENT_PULA";
            request.AddParameter("shapeId", shapeId, ParameterType.UrlSegment);
            ACTIVE_INGREDIENT_PULA thisPULA = serviceCaller.Execute<ACTIVE_INGREDIENT_PULA>(request);

            if (thisPULA.EFFECTIVE_DATE != null)
            {
                string monthYear = GetThisMonth(thisPULA.EFFECTIVE_DATE.Value.Month) + thisPULA.EFFECTIVE_DATE.Value.Year;
                ViewData["EffectMonthYr"] = monthYear;
            }

            //pull out the comments '[Name|Org|omment][Name2|Org2|comment2]
            if (thisPULA.COMMENTS != null)
            {
                string[] comments = thisPULA.COMMENTS.Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);//Regex.Split(thisPULA.COMMENTS, "]");
                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);
                }
                ViewData["Comments"] = allComments;
            }

            //get the Events
            request.Resource = "Events/{eventID}";
            request.RootElement = "EVENT";
            request.AddParameter("eventID", thisPULA.EVENT_ID, ParameterType.UrlSegment);
            EVENT anEvent = serviceCaller.Execute<EVENT>(request);
            ViewData["EventName"] = anEvent != null ?anEvent.NAME : "";

            //get the version info
            request = new RestRequest();
            request.Resource = "/Version/{entityID}";
            request.RootElement = "VERSION";
            request.AddParameter("entityID", thisPULA.VERSION_ID, ParameterType.UrlSegment);
            VERSION thisVersion = serviceCaller.Execute<VERSION>(request);
            ViewData["Version"] = thisVersion; //store to get created and expired dates

            //get the Users from Version
            //creator
            request = new RestRequest();
            request.Resource = "/Users/{userID}";
            request.RootElement = "ArrayOfUSER_";
            request.AddParameter("userID", thisVersion.CREATOR_ID, ParameterType.UrlSegment);
            List<USER_> creatList = serviceCaller.Execute<List<USER_>>(request);
            USER_ creator = creatList.FirstOrDefault();

            if (creator != null)
            {
                ViewData["CreatorName"] = creator.FNAME + " " + creator.LNAME;

                if (creator.ORGANIZATION_ID != 0 && creator.ORGANIZATION_ID != null)
                {
                    request = new RestRequest();
                    request.Resource = "/Organizations/{organizationID}";
                    request.RootElement = "ORGANIZATION";
                    request.AddParameter("organizationID", creator.ORGANIZATION_ID, ParameterType.UrlSegment);
                    ORGANIZATION thisOrg = serviceCaller.Execute<ORGANIZATION>(request);
                    if (thisOrg != null)
                        ViewData["creatorOrg"] = thisOrg.NAME;
                }
                if (creator.DIVISION_ID != 0 && creator.DIVISION_ID != null)
                {
                    request = new RestRequest();
                    request.Resource = "/Divisions/{divisionID}";
                    request.RootElement = "DIVISION";
                    request.AddParameter("divisionID", creator.DIVISION_ID, ParameterType.UrlSegment);
                    ViewData["creatorDiv"] = serviceCaller.Execute<DIVISION>(request).DIVISION_NAME;
                }
            }
            //Publisher
            if (thisVersion.PUBLISHER_ID != null && thisVersion.PUBLISHER_ID != 0)
            {
                request = new RestRequest();
                request.Resource = "/Users/{userID}";
                request.RootElement = "ArrayOfUSER_";
                request.AddParameter("userID", thisVersion.PUBLISHER_ID, ParameterType.UrlSegment);
                List<USER_> pubList = serviceCaller.Execute<List<USER_>>(request);
                USER_ publisher = pubList.FirstOrDefault();

                if (publisher.ORGANIZATION_ID != 0 && publisher.ORGANIZATION_ID != null)
                {
                    ViewData["publisherName"] = publisher.FNAME + " " + publisher.LNAME;

                    request = new RestRequest();
                    request.Resource = "/Organizations/{organizationID}";
                    request.RootElement = "ORGANIZATION";
                    request.AddParameter("organizationID", publisher.ORGANIZATION_ID, ParameterType.UrlSegment);
                    ORGANIZATION pubOrg = serviceCaller.Execute<ORGANIZATION>(request);
                    if (pubOrg != null)
                        ViewData["publisherOrg"] = pubOrg.NAME;
                }
                if (publisher.DIVISION_ID != 0 && publisher.DIVISION_ID != null)
                {
                    request = new RestRequest();
                    request.Resource = "/Divisions/{divisionID}";
                    request.RootElement = "DIVISION";
                    request.AddParameter("divisionID", publisher.DIVISION_ID, ParameterType.UrlSegment);
                    ViewData["publisherDiv"] = serviceCaller.Execute<DIVISION>(request).DIVISION_NAME;
                }
            }

            //Expirer
            if (thisVersion.EXPIRER_ID != null && thisVersion.EXPIRER_ID != 0)
            {
                request = new RestRequest();
                request.Resource = "/Users/{userID}";
                request.RootElement = "ArrayOfUSER_";
                request.AddParameter("userID", thisVersion.EXPIRER_ID, ParameterType.UrlSegment);
                List<USER_> expList = serviceCaller.Execute<List<USER_>>(request);
                USER_ expirer = expList.FirstOrDefault();

                if (expirer.ORGANIZATION_ID != 0 && expirer.ORGANIZATION_ID != null)
                {
                    ViewData["expirerName"] = expirer.FNAME + " " + expirer.LNAME;

                    request = new RestRequest();
                    request.Resource = "/Organizations/{organizationID}";
                    request.RootElement = "ORGANIZATION";
                    request.AddParameter("organizationID", expirer.ORGANIZATION_ID, ParameterType.UrlSegment);
                    ORGANIZATION expOrg = serviceCaller.Execute<ORGANIZATION>(request);
                    if (expOrg != null)
                        ViewData["expirerOrg"] = expOrg.NAME;
                }
                if (expirer.DIVISION_ID != 0 && expirer.DIVISION_ID != null)
                {
                    request = new RestRequest();
                    request.Resource = "/Divisions/{divisionID}";
                    request.RootElement = "DIVISION";
                    request.AddParameter("divisionID", expirer.DIVISION_ID, ParameterType.UrlSegment);
                    ViewData["expirerDiv"] = serviceCaller.Execute<DIVISION>(request).DIVISION_NAME;
                }
            }

            //get the PULA species
            request = new RestRequest();
            request.Resource = "/ActiveIngredientPULA/{activeIngredientPULAID}/Species";
            //request.RootElement = "ArrayOfSPECIES_ACTIVE_INGREDIENT_PULA";
            request.RootElement = "ArrayOfSPECIES";
            request.AddParameter("activeIngredientPULAID", thisPULA.PULA_ID, ParameterType.UrlSegment);
            SpeciesList PULAspp = serviceCaller.Execute<SpeciesList>(request);
            if (PULAspp != null)
            {
                ViewData["PULASpp"] = PULAspp.SPECIES.OrderBy(x => x.COMNAME).ToList();
            }
            else
            {
                ViewData["TESSError"] = true;
            }
            //get the PULA_LIMITATIONs
            request = new RestRequest();
            request.Resource = "PULAs/{pulaID}/PULALimitations?ActiveDate={date}";
            request.RootElement = "ArrayOfPULA_LIMITATIONS";
            request.AddParameter("pulaID", thisPULA.PULA_ID, ParameterType.UrlSegment);
            List<PULA_LIMITATIONS> PULALimitationList = serviceCaller.Execute<List<PULA_LIMITATIONS>>(request);

            //to display each row in the table, use model
            List<PULALimitation> PubPulaLists = new List<PULALimitation>();

            //get all the Limitation parts
            foreach (PULA_LIMITATIONS pl in PULALimitationList)
            {
                PULALimitation thisPubPULA = new PULALimitation();
                if (pl.ACTIVE_INGREDIENT_ID != null && pl.ACTIVE_INGREDIENT_ID != 0)
                {
                    //get Active Ingredient
                    request = new RestRequest();
                    request.Resource = "/ActiveIngredients?aiID={activeIngredientID}&publishedDate={date}";
                    request.RootElement = "ArrayOfACTIVE_INGREDIENT";
                    request.AddParameter("activeIngredientID", pl.ACTIVE_INGREDIENT_ID, ParameterType.UrlSegment);
                    List<ACTIVE_INGREDIENT> aiList = serviceCaller.Execute<List<ACTIVE_INGREDIENT>>(request);
                    //give me newest version
                    ACTIVE_INGREDIENT thisAI = aiList.OrderByDescending(a => a.VERSION_ID).FirstOrDefault();
                    //store in model
                    thisPubPULA.AI = thisAI.INGREDIENT_NAME;
                }
                if (pl.PRODUCT_ID != null && pl.PRODUCT_ID != 0)
                {
                    //get Active Ingredient
                    request = new RestRequest();
                    request.Resource = "/Products?ProductID={productID}&publishedDate={date}";
                    request.RootElement = "ArrayOfPRODUCT";
                    request.AddParameter("productID", pl.PRODUCT_ID, ParameterType.UrlSegment);
                    List<PRODUCT> prodList = serviceCaller.Execute<List<PRODUCT>>(request);
                    //give me newest version
                    PRODUCT thisprod = prodList.OrderByDescending(a => a.VERSION_ID).FirstOrDefault();
                    //store in model
                    thisPubPULA.Product = thisprod.PRODUCT_NAME;
                    thisPubPULA.Prod_RegNum = thisprod.PRODUCT_REGISTRATION_NUMBER;
                }

                //get crop use
                request = new RestRequest();
                request.Resource = "/CropUses?CropUseID={cropUseID}&publishedDate={date}";
                request.RootElement = "ArrayOfCROP_USE";
                request.AddParameter("cropUseID", pl.CROP_USE_ID, ParameterType.UrlSegment);
                List<CROP_USE> cuList = serviceCaller.Execute<List<CROP_USE>>(request);
                //give me the newest version
                CROP_USE thisCropUse = cuList.OrderByDescending(cu => cu.VERSION_ID).FirstOrDefault();
                //store in model
                thisPubPULA.CropUse = thisCropUse.USE;

                //get application Method and store in model
                thisPubPULA.AppMethod = GetApplicationMethod(pl.APPLICATION_METHOD_ID).METHOD;

                //get formulation
                request = new RestRequest();
                request.Resource = "/Formulations?FormulationID={formulationID}&publishedDate={date}";
                request.RootElement = "ArrayOfFORMULATION";
                request.AddParameter("formulationID", pl.FORMULATION_ID, ParameterType.UrlSegment);
                List<FORMULATION> formList = serviceCaller.Execute<List<FORMULATION>>(request);
                //give me the newest version
                FORMULATION thisFormulation = formList.OrderByDescending(m => m.VERSION_ID).FirstOrDefault();
                //store in model
                thisPubPULA.Formulation = thisFormulation.FORM;

                //get limitation code
                request = new RestRequest();
               // request.Resource = "/Limitations?limitationID={limitationID}&publishedDate={date}";
                request.Resource = "/Limitations/{limitationID}?publishedDate={date}";
                request.RootElement = "ArrayOfLIMITATION";
                request.AddParameter("limitationID", pl.LIMITATION_ID, ParameterType.UrlSegment);
                List<LIMITATION> lList = serviceCaller.Execute<List<LIMITATION>>(request);
                //give me the newest version
                LIMITATION thislimitation = lList.OrderByDescending(l => l.VERSION_ID).FirstOrDefault();
                //store in model
                thisPubPULA.Code = thislimitation.CODE;
                thisPubPULA.Limitation = thislimitation.LIMITATION1;

                PubPulaLists.Add(thisPubPULA);
            }

            ViewData["PULAlimitationList"] = PubPulaLists;

            //get months and years lists
            ViewBag.Months = GetMonthsList();
            ViewBag.Years = GetYearList();

            //get logged in User
            ViewData["loggedIn"] = GetLoggedInUser();

            return PartialView(thisPULA);
        }
コード例 #2
0
ファイル: PULAController.cs プロジェクト: troddick/BLTWeb
        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;
        }