Example #1
0
        /// <summary>
        /// Prepare researcher model
        /// </summary>
        /// <param name="model">Researcher model</param>
        /// <param name="researcher">Researcher</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Researcher model</returns>
        public virtual ResearcherModel PrepareResearcherModel(ResearcherModel model, Researcher researcher, bool excludeProperties = false)
        {
            if (researcher != null)
            {
                //fill in model values from the entity
                model = model ?? researcher.ToModel <ResearcherModel>();
                model.ResearcherCode   = researcher.ResearcherCode;
                model.TitleId          = researcher.TitleId;
                model.FirstName        = researcher.FirstName;
                model.LastName         = researcher.LastName;
                model.FirstNameEN      = researcher.FirstNameEN;
                model.LastNameEN       = researcher.LastNameEN;
                model.DateOfBirthDay   = researcher.Birthdate?.Day;
                model.DateOfBirthMonth = researcher.Birthdate?.Month;
                model.DateOfBirthYear  = researcher.Birthdate?.Year;
                model.IDCard           = researcher.IDCard;
                model.Telephone        = researcher.Telephone;
                model.Email            = researcher.Email;
                model.PictureId        = researcher.PictureId;
                model.PersonalTypeId   = researcher.PersonalTypeId;
                model.AgencyId         = researcher.AgencyId;
                model.AcademicRankId   = researcher.AcademicRankId;
                model.IsActive         = researcher.IsActive;
                if (researcher.Birthdate.HasValue)
                {
                    model.DateOfBirthDay   = researcher.Birthdate.Value.Day;
                    model.DateOfBirthMonth = researcher.Birthdate.Value.Month;
                    model.DateOfBirthYear  = researcher.Birthdate.Value.Year + 543;
                    model.DateOfBirthName  = CommonHelper.ConvertToThaiDate(researcher.Birthdate.Value);
                }

                PrepareResearcherEducationSearchModel(model.ResearcherEducationSearchModel, researcher);
                model.AcademicRankName             = researcher.AcademicRank != null ? researcher.AcademicRank.NameTh : string.Empty;
                model.PersonalTypeName             = researcher.PersonalType.GetAttributeOfType <EnumMemberAttribute>().Value;
                model.ResearcherEducationListModel = PrepareResearcherEducationListModel(new ResearcherEducationSearchModel {
                    ResearcherId = researcher.Id
                }, researcher);
            }
            else
            {
                model.ResearcherCode = _researcherService.GetNextNumber();
            }
            PrepareAddressModel(model.AddressModel, researcher);
            _baseAdminModelFactory.PrepareTitles(model.AvailableTitles, true, "--ระบุคำนำหน้าชื่อ--");
            _baseAdminModelFactory.PrepareAgencies(model.AvailableAgencies, true, "--ระบุประเภทหน่วยงาน--");
            _baseAdminModelFactory.PreparePersonalTypes(model.AvailablePersonalTypes, true, "--ระบุประเภทบุคลากร--");
            int personType = 1;

            if (model.PersonalTypeId != 0)
            {
                personType = model.PersonalTypeId;
            }
            _baseAdminModelFactory.PrepareAcademicRanks(model.AvailableAcademicRanks, personType, true, "--ระบุตำแหน่งวิชาการ--");

            _baseAdminModelFactory.PrepareDegrees(model.AvailableAddEducationDegrees, true, "--ระบุระดับปริญญา--");
            _baseAdminModelFactory.PrepareEducationLevels(model.AvailableAddEducationEducationLevels, true, "--ระบุวุฒิการศึกษา--");
            _baseAdminModelFactory.PrepareInstitutes(model.AvailableAddEducationInstitutes, true, "--ระบุสถาบันการศึกษา--");
            _baseAdminModelFactory.PrepareCountries(model.AvailableAddEducationCountries, true, "--ระบุประเทศ--");
            //Default Thailand
            model.AddEducationCountryId      = 229;
            model.AddEducationGraduationYear = DateTime.Now.Year + 543;
            return(model);
        }