public async Task <IActionResult> AddMemo(MemoAC memoAC)
        {
            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.AddMemo(memoAC, Convert.ToInt64(userId), fullname)));
        }
        public async Task <ResponseAC> AddMemo(MemoAC memoAC, long userId, string loginUserName)
        {
            ResponseAC responseAC = new ResponseAC();
            Memo       memo       = _mapper.Map <Memo>(memoAC);

            memo.Id            = 0;
            memo.CreatedBy     = userId;
            memo.CreatedDate   = DateTime.Now;
            memo.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID();
            memo.RefrenceNo    = memoAC.ProviderName + "/INV/" + memoAC.Month + "/" + memo.Year;
            _dbTeleBilling_V01Context.Add(memo);
            await _dbTeleBilling_V01Context.SaveChangesAsync();

            List <Memobills>  billMemos   = new List <Memobills>();
            List <Billmaster> billMasters = new List <Billmaster>();

            foreach (long item in memoAC.BillIds)
            {
                Memobills memoBill = new Memobills();
                memoBill.BillId        = item;
                memoBill.MemoId        = memo.Id;
                memoBill.TransactionId = memo.TransactionId;
                memoBill.CreatedBy     = userId;
                memoBill.CreatedDate   = DateTime.Now;
                billMemos.Add(memoBill);

                Billmaster billMaster = await _dbTeleBilling_V01Context.Billmaster.FirstOrDefaultAsync(x => x.Id == item);

                billMaster.UpdatedBy    = userId;
                billMaster.BillStatusId = Convert.ToInt16(EnumList.BillStatus.MemoCreated);
                billMaster.UpdatedDate  = DateTime.Now;
                billMasters.Add(billMaster);
            }

            if (billMemos.Any())
            {
                await _dbTeleBilling_V01Context.AddRangeAsync(billMemos);

                await _dbTeleBilling_V01Context.SaveChangesAsync();
            }


            if (billMasters.Any())
            {
                _dbTeleBilling_V01Context.UpdateRange(billMasters);
                await _dbTeleBilling_V01Context.SaveChangesAsync();

                memo = await _dbTeleBilling_V01Context.Memo.Where(x => x.Id == memo.Id && !x.IsDelete).Include(x => x.Provider).FirstOrDefaultAsync();

                #region Send Mail For Create Memo
                TeleBillingUtility.Models.Configuration configuration = await _dbTeleBilling_V01Context.Configuration.FirstOrDefaultAsync();

                List <MstEmployee> mstEmployees = await _dbTeleBilling_V01Context.MstEmployee.Where(x => !x.IsDelete && x.IsActive && x.IsPresidentOffice).ToListAsync();

                if (configuration != null && configuration.NSendMemo)
                {
                    foreach (var item in billMasters)
                    {
                        if (mstEmployees.Any())
                        {
                            foreach (var employee in mstEmployees)
                            {
                                if (!string.IsNullOrEmpty(employee.EmailId))
                                {
                                    Emailtemplate emailTemplate = new Emailtemplate();
                                    Dictionary <string, string> replacements = new Dictionary <string, string>();
                                    EnumList.Month month = (EnumList.Month)item.BillMonth;

                                    replacements.Add("{BillMonth}", month.ToString());
                                    replacements.Add("{BillYear}", item.BillYear.ToString());
                                    replacements.Add("{RefrenceNo}", memo.RefrenceNo);
                                    replacements.Add("{newEmpName}", employee.FullName);
                                    replacements.Add("{MemoSubject}", memo.Subject);
                                    replacements.Add("{BillNumber}", item.BillNumber);
                                    replacements.Add("{BillAmount}", memo.TotalAmount.ToString());
                                    replacements.Add("{Provider}", memo.Provider.Name);

                                    if (await _iEmailSender.SendEmail(Convert.ToInt64(EnumList.EmailTemplateType.SendMemo), replacements, employee.EmailId))
                                    {
                                        await _iEmailSender.AddedReminderNotificationLog(Convert.ToInt64(EnumList.EmailTemplateType.SendMemo), null, false, employee.EmailId);
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion


                #region Notification For Memo
                List <Notificationlog> notificationlogs = new List <Notificationlog>();
                if (mstEmployees.Any())
                {
                    foreach (var item in mstEmployees)
                    {
                        notificationlogs.Add(_iLogManagement.GenerateNotificationObject(item.UserId, userId, Convert.ToInt16(EnumList.NotificationType.SendMemo), memo.Id));
                    }
                    await _iLogManagement.SaveNotificationList(notificationlogs);
                }
                #endregion
            }

            await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.AddMemo, loginUserName, userId, "Memo(" + memo.RefrenceNo + ")", (int)EnumList.ActionTemplateTypes.Add, memo.Id);

            responseAC.Message    = _iStringConstant.MemoAddedsuccessfully;
            responseAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success);

            return(responseAC);
        }