// PUT api/Attendence/5 public IHttpActionResult PutAttendence(Attendence p) { // emp.Id = id; if (!repository.Update(p)) { throw new HttpResponseException(HttpStatusCode.NotFound); } // return Ok("Successful"); var data = repository.GetAll(); if (data == null) { return(NotFound()); } return(Ok(data)); }
public async Task <SaveAttendenceResponse> UpdateAsync(int id, Attendence attendence) { var existingAttendence = await _attendenceRepository.FindByIdAsync(id); if (existingAttendence == null) { return(new SaveAttendenceResponse("Attendence not found.")); } //Authorized By NiNiWinMay(Table Joining) 23.6.2019 existingAttendence.empId = attendence.empId; existingAttendence.Employees.employeeId = attendence.Employees.employeeId; existingAttendence.date = attendence.date; existingAttendence.start_time = attendence.start_time; existingAttendence.end_time = attendence.end_time; existingAttendence.attendenceType = attendence.attendenceType; existingAttendence.remark = attendence.remark; existingAttendence.Employees.employee_No = attendence.Employees.employee_No; existingAttendence.Employees.employee_Name = attendence.Employees.employee_Name; existingAttendence.Employees.email = attendence.Employees.email; existingAttendence.Employees.dob = attendence.Employees.dob; existingAttendence.Employees.nrc = attendence.Employees.nrc; existingAttendence.Employees.phone_no_work = attendence.Employees.phone_no_work; existingAttendence.Employees.phone_no_personal = attendence.Employees.phone_no_personal; existingAttendence.Employees.gender = attendence.Employees.gender; existingAttendence.Employees.marital_status = attendence.Employees.marital_status; existingAttendence.Employees.nationality = attendence.Employees.nationality; existingAttendence.Employees.religion = attendence.Employees.religion; existingAttendence.Employees.permanent_address = attendence.Employees.permanent_address; existingAttendence.Employees.education_background = attendence.Employees.education_background; //existingAttendence.Employees.addressId=attendence.Employees.addressId; existingAttendence.Employees.joined_date = attendence.Employees.joined_date; existingAttendence.Employees.employee_state = attendence.Employees.employee_state; existingAttendence.Employees.Addresses.line_1 = attendence.Employees.Addresses.line_1; existingAttendence.Employees.Addresses.line_2 = attendence.Employees.Addresses.line_2; existingAttendence.Employees.Addresses.Township.Name = attendence.Employees.Addresses.Township.Name; existingAttendence.Employees.Addresses.Township.city.Name = attendence.Employees.Addresses.Township.city.Name; existingAttendence.Employees.Addresses.region = attendence.Employees.Addresses.region; existingAttendence.Employees.Addresses.country = attendence.Employees.Addresses.country; try { _attendenceRepository.Update(existingAttendence); await _unitOfWork.CompleteAsync(); return(new SaveAttendenceResponse(existingAttendence)); } catch (Exception ex) { // Do some logging stuff return(new SaveAttendenceResponse($"An error occurred when saving the attendence: {ex.Message}")); } }