public async Task LeaveByIdAsync() { await _leaveRequestRepository.ApplyLeaveAsync(leave); var leaves = await _leaveRequestRepository.LeaveByIdAsync(1); Assert.Equal(Condition.Pending, leaves.Status); }
/// <summary> /// Method to get leave Updated from slack button response /// </summary> /// <param name="leaveResponse">leave update response from slack</param> public async Task UpdateLeaveAsync(SlashChatUpdateResponse leaveResponse) { try { _logger.Debug("UpdateLeaveAsync Leave update method"); // method to get leave by its id LeaveRequest leave = await _leaveRepository.LeaveByIdAsync(Convert.ToInt32(leaveResponse.CallbackId)); _logger.Debug("UpdateLeaveAsync leave applied by : " + leave.EmployeeId); ApplicationUser user = await _userManagerRepository.FirstOrDefaultAsync(x => x.Id == leave.EmployeeId); _logger.Debug("UpdateLeaveAsync User name : " + user.UserName); SlackUserDetailAc slackUser = await _slackUserRepository.GetByIdAsync(user.SlackUserId); _logger.Debug("UpdateLeaveAsync User slack name : " + slackUser.Name); ApplicationUser updaterUser = await _userManagerRepository.FirstOrDefaultAsync(x => x.SlackUserId == leaveResponse.User.Id); if (updaterUser != null) { _logger.Debug("UpdateLeaveAsync User want to update the leave : " + updaterUser.UserName); // only pending status can be modified if (leave.Status == Condition.Pending) { if (leaveResponse.Actions[0].Value == _stringConstant.Approved) { leave.Status = Condition.Approved; } else { leave.Status = Condition.Rejected; } await _leaveRepository.UpdateLeaveAsync(leave); _logger.Debug("UpdateLeaveAsync leave updated successfully"); _logger.Debug("Leave details : " + leave.ToString()); replyText = string.Format(_stringConstant.CasualLeaveUpdateMessageForUser, leave.Id, leave.FromDate.ToShortDateString(), leave.EndDate.Value.ToShortDateString(), leave.Reason, leave.Status, leaveResponse.User.Name); _logger.Debug("Reply text to user : "******"UpdateLeaveAsync user incoming webhook is null : " + string.IsNullOrEmpty(incomingWebHook.IncomingWebHookUrl)); // Used to send slack message to the user about leave updation _logger.Debug("UpdateLeaveAsync Client repository - UpdateMessageAsync"); await _clientRepository.UpdateMessageAsync(incomingWebHook.IncomingWebHookUrl, replyText); _logger.Debug("Creating Email object"); // Used to send email to the user about leave updation EmailApplication email = new EmailApplication(); email.To = new List <string>(); email.Body = _emailTemplateRepository.EmailServiceTemplateLeaveUpdate(leave); _logger.Debug("Email body is null : " + email.Body); email.From = updaterUser.Email; _logger.Debug("Email from : " + email.From); email.To.Add(user.Email); _logger.Debug("Email from : " + email.To); email.Subject = string.Format(_stringConstant.LeaveUpdateEmailStringFormat, _stringConstant.Leave, leave.Status); replyText = string.Format(_stringConstant.ReplyTextForUpdateLeave, leave.Status, slackUser.Name, leave.FromDate.ToShortDateString(), leave.EndDate.Value.ToShortDateString(), leave.Reason, leave.RejoinDate.Value.ToShortDateString()); _logger.Debug("Reply text to updator : " + replyText); _logger.Debug("UpdateLeaveAsync Email sending"); _emailService.Send(email); _logger.Debug("UpdateLeaveAsync Email successfully send"); } else { _logger.Debug("UpdateLeaveAsync leave already updated"); replyText = string.Format(_stringConstant.AlreadyUpdatedMessage, leave.Status); } } else { replyText = _stringConstant.YouAreNotInExistInOAuthServer; } } catch (SmtpException ex) { replyText += string.Format(_stringConstant.ReplyTextForSMTPExceptionErrorMessage, _stringConstant.ErrorWhileSendingEmail, ex.Message.ToString()); } _logger.Debug("UpdateLeaveAsync Client Repository - SendMessageAsync"); // updating leave applied text of slack await _clientRepository.SendMessageAsync(leaveResponse.ResponseUrl, replyText); }