Example #1
0
        /// <summary>
        /// Prepare available Research Issues
        /// </summary>
        /// <param name="items">Research issues items</param>
        /// <param name="withSpecialDefaultItem">Whether to insert the first special item for the default value</param>
        /// <param name="defaultItemText">Default item text; pass null to use default value of the default item text</param>
        public virtual void PrepareResearchIssues(IList <SelectListItem> items, int fiscalYear = 0, bool withSpecialDefaultItem = true, string defaultItemText = null)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            //prepare available research issues
            var researchIssuesStatusItems = new List <ResearchIssue>();

            if (fiscalYear != 0)
            {
                researchIssuesStatusItems = _researchIssueService.GetAllResearchIssues().Where(x => x.FiscalYear == fiscalYear).ToList();
            }
            else
            {
                researchIssuesStatusItems = _researchIssueService.GetAllResearchIssues();
            }

            foreach (var researchIssue in researchIssuesStatusItems)
            {
                items.Add(new SelectListItem {
                    Value = researchIssue.Id.ToString(), Text = researchIssue.Name
                });
            }

            //insert special item for the default value
            PrepareDefaultItem(items, withSpecialDefaultItem, defaultItemText);
        }
Example #2
0
        /// <summary>
        /// Prepare paged researchIssue list model
        /// </summary>
        /// <param name="searchModel">ResearchIssue search model</param>
        /// <returns>ResearchIssue list model</returns>
        public virtual ResearchIssueListModel PrepareResearchIssueListModel(ResearchIssueSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get researchIssues
            var researchIssues = _researchIssueService.GetAllResearchIssues(researchIssueName: searchModel.Name);


            //prepare grid model
            var model = new ResearchIssueListModel
            {
                Data = researchIssues.PaginationByRequestModel(searchModel).Select(researchIssue =>
                {
                    //fill in model values from the entity
                    var researchIssueModel = researchIssue.ToModel <ResearchIssueModel>();

                    //little performance optimization: ensure that "Body" is not returned
                    researchIssueModel.Id         = researchIssue.Id;
                    researchIssueModel.FiscalYear = researchIssue.FiscalYear;
                    researchIssueModel.IssueCode  = researchIssue.IssueCode;
                    researchIssueModel.Name       = researchIssue.Name;

                    return(researchIssueModel);
                }),
                Total = researchIssues.Count
            };

            return(model);
        }