/// <summary>
        /// Get List Education
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public static List <CreateEducationResource> GetListEducation(List <string> list, int id)
        {
            List <CreateEducationResource> listEducation = new List <CreateEducationResource>();
            int indexEducation   = list.IndexOf("EDUCATION");
            int indexCertificate = list.IndexOf("CERTIFICATION");
            int index            = 0;

            for (int i = indexEducation; i < indexCertificate - 2; i = i + 2)
            {
                index++;
                CreateEducationResource educationInfo = new CreateEducationResource();
                string    dateEducation = GetDate(list[i + 1]);
                Hashtable hashtable     = FormatYear(dateEducation);
                educationInfo = new CreateEducationResource
                {
                    StartDate   = hashtable["StartDate"],
                    EndDate     = (hashtable.Count > 1) ? hashtable["EndDate"] : null,
                    CollegeName = GetCollegeName(list[i + 1]),
                    Major       = GetInformation(list[i + 2]),
                    PersonId    = id
                };
                listEducation.Add(educationInfo);
            }
            return(listEducation);
        }
        public async Task <IActionResult> CreateEducation([FromBody] CreateEducationResource educationObj)
        {
            var tempEducationModel = await _educationService.CreateEducation(educationObj);

            if (!tempEducationModel.AppResult.Result)
            {
                return(BadRequest(tempEducationModel.AppResult));
            }
            return(Ok(tempEducationModel.AppResult));
        }
Пример #3
0
        public async Task <EducationViewModel <SaveEducationResource> > CreateEducation(CreateEducationResource educationObj)
        {
            model.AppResult.Result = false;
            // Validate CollegeName, Major
            if (string.IsNullOrEmpty(educationObj.CollegeName) ||
                string.IsNullOrEmpty(educationObj.Major) ||
                educationObj.Major.Length > 255 ||
                educationObj.CollegeName.Length > 255)
            {
                model.AppResult.Message = "CollegeName/Major invalid";
                return(model);
            }
            // Validate Start/End Date
            if (!Functions.ValidateInputTime(educationObj.StartDate, educationObj.EndDate))
            {
                model.AppResult.Message = Constant.DATETIME_ERROR;
                return(model);
            }
            // Validate PersonId
            var taskValidPeronId = await _educationRepository.ValidatePersonIdAsync(educationObj.PersonId);

            if (taskValidPeronId < 1)
            {
                model.AppResult.Message = Constant.PERSONID_ERROR;
                return(model);
            }

            // Define DateTime.Year = "1111" is null
            var valueStartDate = Functions.ConvertDateTime(educationObj.StartDate);
            var valueEndDate   = Functions.ConvertDateTime(educationObj.EndDate);
            // Find maximum value of OrderIndex
            int maximumOrderIndex = await _educationRepository.MaximumOrderIndexAsync(educationObj.PersonId);

            maximumOrderIndex = (maximumOrderIndex <= 0) ? 1 : maximumOrderIndex + 1;
            // Insert info into temporary model
            var tempEducationInfo = new EducationInfo()
            {
                CollegeName = Regex.Replace(educationObj.CollegeName.Trim(), @"\s{2,}", " "),
                Major       = Regex.Replace(educationObj.Major.Trim(), @"\s{2,}", " "),
                StartDate   = valueStartDate,
                EndDate     = (valueEndDate.Year == 1111) ? (DateTime?)null : valueEndDate, // Define DateTime.Year = "1111" is null
                PersonId    = educationObj.PersonId,
                UpdatedBy   = null,
                UpdatedAt   = null,
                CreatedBy   = Helpers.HttpContext.CurrentUser,
                CreatedAt   = DateTime.Now,
                Status      = true,
                OrderIndex  = maximumOrderIndex
            };
            var tempEducationInfoId = await _educationRepository.InsertAsync(tempEducationInfo);

            // Set response to FE
            model.ObjModel.Id          = tempEducationInfoId;
            model.ObjModel.OrderIndex  = tempEducationInfo.OrderIndex;
            model.ObjModel.CollegeName = tempEducationInfo.CollegeName;
            model.ObjModel.Major       = tempEducationInfo.Major;
            model.ObjModel.StartDate   = tempEducationInfo.StartDate.Year.ToString();
            model.ObjModel.EndDate     = (tempEducationInfo.EndDate is null) ? string.Empty : string.Format(tempEducationInfo.EndDate?.Year.ToString());

            model.AppResult.Result     = true;
            model.AppResult.Message    = Constant.INSERT_SUCCESS;
            model.AppResult.DataResult = model.ObjModel;

            return(model);
        }