/// <summary> /// this method is used to edit the employees's personal details /// </summary> /// <param name="employeePersonalDetails">Employee Personal Details</param> public async Task EditEmployeePersonalDetailsAsync(EditEmployeePersonalInformationDto employeePersonalDetails) { List <string> namesOfChildren = new List <string>(); List <DateTime> childrenDateOFBirth = new List <DateTime>(); if (employeePersonalDetails == null) { throw new Exception(" Employee details to be edited are not mentioned"); } var oldEmployeeData = await _employeeRepository.GetEmployeeInformationAsync(employeePersonalDetails.Id); if (oldEmployeeData == null) { throw new Exception("Employee does not exist in the system"); } _mapper.Map(employeePersonalDetails, oldEmployeeData); if (employeePersonalDetails.NumberOfChildren != 0) { foreach (var childData in employeePersonalDetails.childrenData) { string name = childData.Name; DateTime dob = childData.DateOfBirth; namesOfChildren.Add(name); childrenDateOFBirth.Add(dob); } oldEmployeeData.NamesOfChildren = JsonConvert.SerializeObject(namesOfChildren); oldEmployeeData.DateOfBirthOfChildren = JsonConvert.SerializeObject(childrenDateOFBirth); } oldEmployeeData.ModifiedAt = DateTime.UtcNow; await _employeeRepository.SaveChangesAsync(); }
public async Task <ActionResult> EditEmployeePersonalDetailsAsync([FromBody] EditEmployeePersonalInformationDto employeePersonalDetails) { await _employeeService.EditEmployeePersonalDetailsAsync(employeePersonalDetails); return(Ok()); }