public async Task <IActionResult> UpdateLeaveStatus(LeaveRequest leaveRequest) { var updateLeaveDto = new UpdateLeaveDto(); await LeaveRepo.UpdateLeaveStatus(leaveRequest.Id, leaveRequest.Status); String logFilePath = Environment.ContentRootPath + Configuration.GetValue <String>("LogFile"); if (leaveRequest.Status.Equals("Approved")) { DateTimeHandler dateTimeHandler = new DateTimeHandler(); float usedCasualLeaves = 0, usedEarnedLeaves = 0; if (leaveRequest.Type.Equals("Casual")) { usedCasualLeaves = dateTimeHandler.CalculateDays(leaveRequest.FromDate, leaveRequest.ToDate); } else if (leaveRequest.Type.Equals("Earned")) { usedEarnedLeaves = dateTimeHandler.CalculateDays(leaveRequest.FromDate, leaveRequest.ToDate); } updateLeaveDto = new UpdateLeaveDto { UsedCasualLeaves = usedCasualLeaves, UsedEarnedLeaves = usedEarnedLeaves }; await LeaveRepo.UpdateUsedLeaves(leaveRequest.EId, updateLeaveDto); } else { updateLeaveDto = new UpdateLeaveDto { UsedCasualLeaves = 0, UsedEarnedLeaves = 0 }; } Logger.log(" LRSU\t:" + " ID: " + leaveRequest.Id + ", E-ID: " + leaveRequest.EId + ", M-ID: " + leaveRequest.ManagerId + ", Type: " + leaveRequest.Type + ", From: " + leaveRequest.FromDate + ", To: " + leaveRequest.ToDate + ", Status: " + leaveRequest.Status, logFilePath); return(Ok( new { leaveRequest.EId, updateLeaveDto } )); }
public async Task <bool> UpdateUsedLeaves(int userId, UpdateLeaveDto updateLeaveDto) { try { var user = await Context.Users.FirstOrDefaultAsync(u => u.Id == userId); user.UsedCasualLeaves += updateLeaveDto.UsedCasualLeaves; user.UsedEarnedLeaves += updateLeaveDto.UsedEarnedLeaves; await SaveAll(); return(true); } catch (Exception) { return(false); } }