public async Task <IActionResult> MemoApproval(MemoApprovalAC memoApprovalAC) { string userId = HttpContext.User.Claims.FirstOrDefault(c => c.Type == "user_id").Value; string fullname = HttpContext.User.Claims.FirstOrDefault(c => c.Type == "fullname").Value; return(Ok(await _iBillMemoRepository.MemoApproval(memoApprovalAC, Convert.ToInt64(userId), fullname))); }
public async Task <ResponseAC> MemoApproval(MemoApprovalAC memoApprovalAC, long userId, string loginUserName) { ResponseAC responseAC = new ResponseAC(); List <Memo> lstMemo = new List <Memo>(); List <Billmaster> billMasters = new List <Billmaster>(); List <string> stringMemoArray = new List <string>(); foreach (var item in memoApprovalAC.billMemoACs) { Memo memoObj = await _dbTeleBilling_V01Context.Memo.Where(x => x.Id == item.Id).Include(x => x.Provider).FirstOrDefaultAsync(); if (memoObj.IsApproved == null) { memoObj.IsApproved = memoApprovalAC.IsApprvoed; memoObj.ApprovedDate = DateTime.Now; memoObj.ApprovedBy = userId; memoObj.Comment = item.Comment; memoObj.UpdatedBy = userId; memoObj.UpdatedDate = DateTime.Now; lstMemo.Add(memoObj); string memoApproval = string.Empty; if (!memoApprovalAC.IsApprvoed) { billMasters.AddRange(await _dbTeleBilling_V01Context.Memobills.Where(x => x.MemoId == item.Id && !x.IsDelete).Include(x => x.Bill).Select(x => x.Bill).ToListAsync()); memoApproval = "Rejected"; } else { memoApproval = "Approved"; } #region Send Mail For Memo Approval TeleBillingUtility.Models.Configuration configuration = await _dbTeleBilling_V01Context.Configuration.FirstOrDefaultAsync(); MstEmployee mstEmployee = await _dbTeleBilling_V01Context.MstEmployee.FirstOrDefaultAsync(x => !x.IsDelete && x.UserId == memoObj.CreatedBy); if (configuration != null && configuration.NMemoApprovalRejection) { if (mstEmployee != null) { if (!string.IsNullOrEmpty(mstEmployee.EmailId)) { Dictionary <string, string> replacements = new Dictionary <string, string>(); EnumList.Month month = (EnumList.Month)memoObj.Month; replacements.Add("{MemoApproval}", memoApproval); replacements.Add("{BillMonth}", month.ToString()); replacements.Add("{BillYear}", memoObj.Year.ToString()); replacements.Add("{RefrenceNo}", memoObj.RefrenceNo); replacements.Add("{newEmpName}", mstEmployee.FullName); replacements.Add("{ApprovalComment}", memoObj.Comment); replacements.Add("{BillAmount}", memoObj.TotalAmount.ToString()); replacements.Add("{MemoSubject}", memoObj.Subject); replacements.Add("{Provider}", memoObj.Provider.Name); if (await _iEmailSender.SendEmail(Convert.ToInt64(EnumList.EmailTemplateType.MemoApproval), replacements, mstEmployee.EmailId)) { await _iEmailSender.AddedReminderNotificationLog(Convert.ToInt64(EnumList.EmailTemplateType.MemoApproval), null, false, mstEmployee.EmailId); } } } } #endregion #region Notification For Memo List <Notificationlog> notificationlogs = new List <Notificationlog>(); if (mstEmployee != null) { if (memoApprovalAC.IsApprvoed) { notificationlogs.Add(_iLogManagement.GenerateNotificationObject(mstEmployee.UserId, userId, Convert.ToInt16(EnumList.NotificationType.MemoApprove), memoObj.Id)); await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.MemoApprove, loginUserName, userId, "Memo(" + memoObj.RefrenceNo + ")", (int)EnumList.ActionTemplateTypes.Approve, memoObj.Id); } else { notificationlogs.Add(_iLogManagement.GenerateNotificationObject(mstEmployee.UserId, userId, Convert.ToInt16(EnumList.NotificationType.MemoReject), memoObj.Id)); await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.MemoReject, loginUserName, userId, "Memo(" + memoObj.RefrenceNo + ")", (int)EnumList.ActionTemplateTypes.Reject, memoObj.Id); } await _iLogManagement.SaveNotificationList(notificationlogs); } #endregion } else { stringMemoArray.Add(memoObj.RefrenceNo); } } #region Update Bill Status if (billMasters.Any()) { foreach (var item in billMasters) { item.BillStatusId = Convert.ToInt16(EnumList.BillStatus.BillAllocated); item.UpdatedBy = userId; item.UpdatedDate = DateTime.Now; } _dbTeleBilling_V01Context.UpdateRange(billMasters); await _dbTeleBilling_V01Context.SaveChangesAsync(); } #endregion if (lstMemo.Any()) { _dbTeleBilling_V01Context.UpdateRange(lstMemo); await _dbTeleBilling_V01Context.SaveChangesAsync(); } if (lstMemo.Count() == memoApprovalAC.billMemoACs.Count()) { responseAC.Message = memoApprovalAC.IsApprvoed ? _iStringConstant.MemoApprovedsuccessfully : _iStringConstant.MemoRejectedsuccessfully; responseAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success); } else { string message = String.Join(',', stringMemoArray); responseAC.Message = memoApprovalAC.IsApprvoed ? _iStringConstant.MemoApprovalMessagesuccessfully.Replace("{{@currentapproval}}", "approved").Replace("{{@memo}}", message) : _iStringConstant.MemoApprovalMessagesuccessfully.Replace("{{@currentapproval}}", "rejected").Replace("{{@memo}}", message); responseAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Warning); } return(responseAC); }