public virtual IActionResult ResearchersSelect()
        {
            //var model = new List<SelectListItem>();
            var model       = new List <string>();
            var researchers = _researcherService.GetAllResearchers().ToList();

            foreach (var x in researchers)
            {
                string title = (x.Title != null) ? x.Title.TitleNameTH : string.Empty;
                //model.Add(new SelectListItem(item.Id.ToString(), $"{item.FirstName} {item.LastName}"));
                model.Add($"{title}{x.FirstName} {x.LastName}");
            }
            return(Json(model));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Prepare available researchers
        /// </summary>
        /// <param name="items">Researcher 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 PrepareResearchers(IList <SelectListItem> items, bool withSpecialDefaultItem = true, string defaultItemText = null)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            //prepare available researchers
            var availableResearchers = _researcherService.GetAllResearchers();

            foreach (var researcher in availableResearchers)
            {
                items.Add(new SelectListItem {
                    Value = researcher.Id.ToString(), Text = $"{researcher.TitleName}{researcher.FirstName} {researcher.LastName}"
                });
            }

            //insert special item for the default value
            PrepareDefaultItem(items, withSpecialDefaultItem, defaultItemText ?? "ระบุผู้วิจัย");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Prepare paged researcher list model
        /// </summary>
        /// <param name="searchModel">Researcher search model</param>
        /// <returns>Researcher list model</returns>
        public virtual ResearcherListModel PrepareResearcherListModel(ResearcherSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get researchers
            var researchers = _researcherService.GetAllResearchers(agency: searchModel.AgencyId,
                                                                   personalType: searchModel.PersonTypeId,
                                                                   firstName: searchModel.FirstName,
                                                                   lastName: searchModel.LastName,
                                                                   isCompleted: searchModel.IsCompleted,
                                                                   email: searchModel.Email);


            //prepare grid model
            var model = new ResearcherListModel
            {
                Data = researchers.PaginationByRequestModel(searchModel).Select(researcher =>
                {
                    //fill in model values from the entity
                    var researcherModel = researcher.ToModel <ResearcherModel>();
                    //var user = _userService.GetUserByEmail(researcher.Email);
                    //little performance optimization: ensure that "Body" is not returned
                    researcherModel.ResearcherCode   = researcher.ResearcherCode;
                    researcherModel.FirstName        = researcher.FirstName;
                    researcherModel.LastName         = researcher.LastName;
                    researcherModel.PersonalTypeName = (int)researcher.PersonalType != 0 ? researcher.PersonalType.GetAttributeOfType <EnumMemberAttribute>().Value : string.Empty;
                    researcherModel.AgencyName       = researcher.Agency != null ? researcher.Agency.Name : string.Empty;
                    researcherModel.IsCompleted      = researcher.IsCompleted;
                    return(researcherModel);
                }),
                Total = researchers.Count
            };

            return(model);
        }