public async Task <IActionResult> UpdatetEducation(int id, [FromBody] UpdateEducationResource educationObj) { var tempEducationModel = await _educationService.UpdateInfomationEducation(id, educationObj); if (!tempEducationModel.AppResult.Result) { return(BadRequest(tempEducationModel.AppResult)); } return(Ok(tempEducationModel.AppResult)); }
public async Task <EducationViewModel <SaveEducationResource> > UpdateInfomationEducation(int educationId, UpdateEducationResource educationObj) { model.AppResult.Result = false; // Validate Start/End Date if (!Functions.ValidateInputTime(educationObj.StartDate, educationObj.EndDate)) { model.AppResult.Message = Constant.DATETIME_ERROR; return(model); } // Validate Id of EducationInfo var tempEducationInfo = await _educationRepository.FindAsync(educationId); if (tempEducationInfo is null) { 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); // Set value into EducationInfo tempEducationInfo.CollegeName = Regex.Replace(educationObj.CollegeName.Trim(), @"\s{2,}", " "); tempEducationInfo.Major = Regex.Replace(educationObj.Major.Trim(), @"\s{2,}", " "); tempEducationInfo.StartDate = valueStartDate; tempEducationInfo.EndDate = (valueEndDate.Year == 1111) ? (DateTime?)null : valueEndDate; // Define DateTime.Year = "1111" is null tempEducationInfo.UpdatedBy = Helpers.HttpContext.CurrentUser; tempEducationInfo.UpdatedAt = DateTime.Now; var isSuccess = await _educationRepository.UpdateAsync(tempEducationInfo); if (isSuccess > 0) { model.AppResult.Result = true; model.AppResult.Message = Constant.UPDATE_SUCCESS; return(model); } model.AppResult.Message = "Bad Request"; return(model); }