コード例 #1
0
        public async Task <ResponseAC> EditHandset(HandsetDetailAC handsetDetailAC, long userId)
        {
            ResponseAC responeAC = new ResponseAC();

            if (!await _dbTeleBilling_V01Context.MstHandsetdetail.AnyAsync(x => x.Id != handsetDetailAC.Id && x.Name.ToLower().Trim() == handsetDetailAC.Name.Trim().ToLower() && !x.IsDelete))
            {
                MstHandsetdetail mstHandsetDetail = await _dbTeleBilling_V01Context.MstHandsetdetail.FirstOrDefaultAsync(x => x.Id == handsetDetailAC.Id && !x.IsDelete);

                #region Transaction Log Entry
                if (mstHandsetDetail.TransactionId == null)
                {
                    mstHandsetDetail.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID();
                }

                var jsonSerailzeObj = JsonConvert.SerializeObject(mstHandsetDetail);
                await _iLogManagement.SaveRequestTraseLog(Convert.ToInt64(mstHandsetDetail.TransactionId), userId, Convert.ToInt64(EnumList.TransactionTraseLog.UpdateRecord), jsonSerailzeObj);

                #endregion

                mstHandsetDetail.Name        = handsetDetailAC.Name.Trim();
                mstHandsetDetail.UpdatedBy   = userId;
                mstHandsetDetail.UpdatedDate = DateTime.Now;
                _dbTeleBilling_V01Context.Update(mstHandsetDetail);
                await _dbTeleBilling_V01Context.SaveChangesAsync();

                responeAC.Message    = _iStringConstant.HandsetUpdateSuccessfully;
                responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success);
            }
            else
            {
                responeAC.Message    = _iStringConstant.HandsetAlreadyExists;
                responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Error);
            }
            return(responeAC);
        }
コード例 #2
0
        public async Task <ResponseAC> resetPassword(EmployeeProfileDetailAC employeeProfileDetailAC, long userId)
        {
            ResponseAC  responeAC   = new ResponseAC();
            MstEmployee mstEmployee = new MstEmployee();

            try
            {
                mstEmployee = await _dbTeleBilling_V01Context.MstEmployee.FindAsync(employeeProfileDetailAC.UserId);

                if (mstEmployee != null)
                {
                    #region Transaction Log Entry
                    if (mstEmployee.TransactionId == null)
                    {
                        mstEmployee.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID();
                    }

                    var jsonSerailzeObj = JsonConvert.SerializeObject(mstEmployee);
                    await _iLogManagement.SaveRequestTraseLog(Convert.ToInt64(mstEmployee.TransactionId), userId, Convert.ToInt64(EnumList.TransactionTraseLog.UpdateRecord), jsonSerailzeObj);

                    #endregion

                    mstEmployee.Password    = employeeProfileDetailAC.NewPassword;
                    mstEmployee.UpdatedBy   = userId;
                    mstEmployee.UpdatedDate = DateTime.Now;

                    _dbTeleBilling_V01Context.Update(mstEmployee);
                    await _dbTeleBilling_V01Context.SaveChangesAsync();

                    responeAC.Message    = "Password Reset Successfully";
                    responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success);
                    await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.ResetPassword, mstEmployee.FullName, userId, string.Empty, (int)EnumList.ActionTemplateTypes.ResetPassword, mstEmployee.UserId);
                }
                else
                {
                    responeAC.Message    = "Employee does not found";
                    responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Error);
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(responeAC);
        }
コード例 #3
0
        public async Task <ResponseAC> EditRole(RoleAC roleAC, long userId, string loginUserName)
        {
            ResponseAC responeAC = new ResponseAC();

            try
            {
                if (!await _dbTeleBilling_V01Context.MstRole.AnyAsync(x => x.RoleId != roleAC.RoleId && x.RoleName.ToLower() == roleAC.RoleName.Trim().ToLower() && !x.IsDelete))
                {
                    MstRole mstRole = await _dbTeleBilling_V01Context.MstRole.FirstOrDefaultAsync(x => x.RoleId == roleAC.RoleId && !x.IsDelete);

                    #region Transaction Log Entry

                    if (mstRole.TransactionId == null)
                    {
                        mstRole.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID();
                    }

                    var jsonSerailzeObj = JsonConvert.SerializeObject(mstRole);
                    await _iLogManagement.SaveRequestTraseLog(Convert.ToInt64(mstRole.TransactionId), userId, Convert.ToInt64(EnumList.TransactionTraseLog.UpdateRecord), jsonSerailzeObj);

                    #endregion

                    mstRole.RoleName    = roleAC.RoleName.Trim();
                    mstRole.UpdatedBy   = userId;
                    mstRole.UpdatedDate = DateTime.Now;
                    _dbTeleBilling_V01Context.Update(mstRole);
                    await _dbTeleBilling_V01Context.SaveChangesAsync();

                    responeAC.Message    = _iStringConstant.RoleUpdatedSuccessfully;
                    responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success);
                    await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.EditRole, loginUserName, userId, "Role(" + roleAC.RoleName.Trim() + ")", (int)EnumList.ActionTemplateTypes.Edit, mstRole.RoleId);
                }
                else
                {
                    responeAC.Message    = _iStringConstant.RoleExists;
                    responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Error);
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(responeAC);
        }
コード例 #4
0
        public async Task <bool> DeleteOperatorCallLog(long userId, long id, string loginUserName)
        {
            Operatorcalllog operatorCallLog = await _dbTeleBilling_V01Context.Operatorcalllog.FirstOrDefaultAsync(x => x.Id == id);

            if (operatorCallLog != null)
            {
                operatorCallLog.IsDelete    = true;
                operatorCallLog.UpdatedBy   = userId;
                operatorCallLog.UpdatedDate = DateTime.Now;
                _dbTeleBilling_V01Context.Update(operatorCallLog);
                await _dbTeleBilling_V01Context.SaveChangesAsync();

                await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.DeleteOperatorCallLog, loginUserName, userId, "Operator call log(Dialed Number:" + operatorCallLog.DialedNumber + "Extensino Number:" + operatorCallLog.ExtensionNumber + ")", (int)EnumList.ActionTemplateTypes.Delete, operatorCallLog.Id);

                return(true);
            }
            return(false);
        }
コード例 #5
0
        public async Task <ResponseAC> AddConfiguration(long userId, TeleBillingUtility.Models.Configuration configuration, string loginUserName)
        {
            ResponseAC responseAC = new ResponseAC();

            if (configuration.Id == 0)
            {
                configuration.CreatedBy     = 1;
                configuration.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID();
                configuration.CreatedDate   = DateTime.Now;
                await _dbTeleBilling_V01Context.AddAsync(configuration);

                await _dbTeleBilling_V01Context.SaveChangesAsync();

                responseAC.Message = _iStringConstant.ConfigurationAddedSuccessfully;
            }
            else
            {
                TeleBillingUtility.Models.Configuration configurationObj = await _dbTeleBilling_V01Context.Configuration.FirstAsync(x => x.Id == configuration.Id);

                #region Transaction Log Entry
                if (configurationObj.TransactionId == null)
                {
                    configurationObj.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID();
                }

                var jsonSerailzeObj = JsonConvert.SerializeObject(configurationObj);
                await _iLogManagement.SaveRequestTraseLog(Convert.ToInt64(configurationObj.TransactionId), userId, Convert.ToInt64(EnumList.TransactionTraseLog.UpdateRecord), jsonSerailzeObj);

                #endregion
                configurationObj             = _mapper.Map(configuration, configurationObj);
                configurationObj.UpdatedBy   = 1;
                configurationObj.UpdatedDate = DateTime.Now;

                _dbTeleBilling_V01Context.Update(configurationObj);
                await _dbTeleBilling_V01Context.SaveChangesAsync();

                responseAC.Message = _iStringConstant.ConfigurationUpdateSuccessfully;
            }
            responseAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success);
            await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.UpdateReminderNotificaiton, loginUserName, userId, "Reminder & notification", (int)EnumList.ActionTemplateTypes.ReminderNotificaiton, configuration.Id);

            return(responseAC);
        }
コード例 #6
0
        public async Task <ResponseAC> EditDelegate(BillDelegatesAC billDelegatesAC, long userId, string loginUserName)
        {
            ResponseAC responeAC = new ResponseAC();

            if (await _dbTeleBilling_V01Context.Billdelegate.FirstOrDefaultAsync(x => x.Id != billDelegatesAC.Id && x.EmployeeId == billDelegatesAC.Employee.UserId && x.DelegateEmployeeId == billDelegatesAC.DelegateEmployee.UserId && !x.IsDelete) == null)
            {
                TeleBillingUtility.Models.Billdelegate delegateDetail = await _dbTeleBilling_V01Context.Billdelegate.FirstOrDefaultAsync(x => x.Id == billDelegatesAC.Id && !x.IsDelete);

                #region Transaction Log Entry
                if (delegateDetail.TransactionId == null)
                {
                    delegateDetail.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID();
                }

                var jsonSerailzeObj = JsonConvert.SerializeObject(delegateDetail);
                await _iLogManagement.SaveRequestTraseLog(Convert.ToInt64(delegateDetail.TransactionId), userId, Convert.ToInt64(EnumList.TransactionTraseLog.UpdateRecord), jsonSerailzeObj);

                #endregion

                delegateDetail.EmployeeId              = billDelegatesAC.Employee.UserId;
                delegateDetail.DelegateEmployeeId      = billDelegatesAC.DelegateEmployee.UserId;
                delegateDetail.AllowBillApproval       = billDelegatesAC.AllowBillApproval;
                delegateDetail.AllowBillIdentification = billDelegatesAC.AllowBillIdentification;
                delegateDetail.UpdatedBy   = userId;
                delegateDetail.UpdatedDate = DateTime.Now;

                _dbTeleBilling_V01Context.Update(delegateDetail);
                await _dbTeleBilling_V01Context.SaveChangesAsync();

                responeAC.Message    = _iStringConstant.DelegateUpdateSuccessfully;
                responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success);
                await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.EditDelegate, loginUserName, userId, "Delegate user", (int)EnumList.ActionTemplateTypes.Edit, delegateDetail.Id);
            }
            else
            {
                responeAC.Message    = _iStringConstant.DelegateAlreadyExists;
                responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Error);
            }
            return(responeAC);
        }
コード例 #7
0
        public async Task <ResponseAC> UpdateTelephone(long userId, TelephoneDetailAC telephoneDetailAC, string loginUserName)
        {
            ResponseAC responseAC = new ResponseAC();

            if (await _dbTeleBilling_V01Context.Telephonenumber.FirstOrDefaultAsync(x => x.TelephoneNumber1.Trim() == telephoneDetailAC.TelephoneNumber1.Trim() && !x.IsDelete && x.Id != telephoneDetailAC.Id) == null)
            {
                Telephonenumber telephoneNumber = await _dbTeleBilling_V01Context.Telephonenumber.FirstOrDefaultAsync(x => x.Id == telephoneDetailAC.Id);

                #region Transaction Log Entry
                if (telephoneNumber.TransactionId == null)
                {
                    telephoneNumber.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID();
                }

                var jsonSerailzeObj = JsonConvert.SerializeObject(telephoneNumber);
                await _iLogManagement.SaveRequestTraseLog(Convert.ToInt64(telephoneNumber.TransactionId), userId, Convert.ToInt64(EnumList.TransactionTraseLog.UpdateRecord), jsonSerailzeObj);

                #endregion

                telephoneNumber             = _mapper.Map(telephoneDetailAC, telephoneNumber);
                telephoneNumber.UpdatedBy   = userId;
                telephoneNumber.UpdatedDate = DateTime.Now;


                _dbTeleBilling_V01Context.Update(telephoneNumber);
                await _dbTeleBilling_V01Context.SaveChangesAsync();

                await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.EditTelephone, loginUserName, userId, "Telephone(" + telephoneNumber.TelephoneNumber1 + ")", (int)EnumList.ActionTemplateTypes.Edit, telephoneNumber.Id);

                responseAC.StatusCode = Convert.ToInt32(EnumList.ResponseType.Success);
                responseAC.Message    = _iStringConstant.TelphoneAddedSuccessfully;
            }
            else
            {
                responseAC.StatusCode = Convert.ToInt32(EnumList.ResponseType.Error);
                responseAC.Message    = _iStringConstant.TelphoneAlreadyExists;
            }
            return(responseAC);
        }
コード例 #8
0
        public async Task <bool> DeletePackage(long userId, long id, string loginUserName)
        {
            Providerpackage providerPackage = await _dbTeleBilling_V01Context.Providerpackage.FirstOrDefaultAsync(x => x.Id == id);

            SortedList sl = new SortedList();

            sl.Add("p_packageid", id);
            int result = Convert.ToInt16(_objDalmysql.ExecuteScaler("usp_GetPackageExists", sl));

            if (result == 0)
            {
                providerPackage.IsDelete    = true;
                providerPackage.UpdatedBy   = userId;
                providerPackage.UpdatedDate = DateTime.Now;
                _dbTeleBilling_V01Context.Update(providerPackage);
                await _dbTeleBilling_V01Context.SaveChangesAsync();

                await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.DeletePackage, loginUserName, userId, "Package(" + providerPackage.Name + ")", (int)EnumList.ActionTemplateTypes.Delete, providerPackage.Id);

                return(true);
            }
            return(false);
        }
コード例 #9
0
        public async Task <bool> DeleteExcelMapping(long userId, long id, string loginUserName)
        {
            Mappingexcel mappingExcel = await _dbTeleBilling_V01Context.Mappingexcel.FirstOrDefaultAsync(x => x.Id == id);

            List <Mappingexcel> mappingExcelMerge = new List <Mappingexcel>();

            mappingExcelMerge = await _dbTeleBilling_V01Context.Mappingexcel.Where(x => x.MappedMappingId == id && x.IsCommonMapped == true).ToListAsync();

            if (mappingExcelMerge != null)
            {
                _dbTeleBilling_V01Context.RemoveRange(mappingExcelMerge);
                await _dbTeleBilling_V01Context.SaveChangesAsync();
            }


            if (mappingExcel != null)
            {
                mappingExcel.IsDelete    = true;
                mappingExcel.UpdatedBy   = userId;
                mappingExcel.UpdatedDate = DateTime.Now;
                _dbTeleBilling_V01Context.Update(mappingExcel);
                await _dbTeleBilling_V01Context.SaveChangesAsync();

                List <Mappingexcelcolumn> excelcolumnlst = new List <Mappingexcelcolumn>();
                excelcolumnlst = await _dbTeleBilling_V01Context.Mappingexcelcolumn.Where(x => x.MappingExcelId == mappingExcel.Id).ToListAsync();

                if (excelcolumnlst != null)
                {
                    _dbTeleBilling_V01Context.RemoveRange(excelcolumnlst);
                    await _dbTeleBilling_V01Context.SaveChangesAsync();
                }
                await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.DeleteExcelMapping, loginUserName, userId, "Excel mapping", (int)EnumList.ActionTemplateTypes.Delete, mappingExcel.Id);

                return(true);
            }
            return(false);
        }
コード例 #10
0
        public async Task <bool> DeleteMemoBills(long id, long userId, string loginUserName)
        {
            Memo memo = await _dbTeleBilling_V01Context.Memo.FirstAsync(x => x.Id == id);

            memo.IsDelete    = true;
            memo.UpdatedBy   = userId;
            memo.UpdatedDate = DateTime.Now;

            List <Billmaster> billMaster = await _dbTeleBilling_V01Context.Memobills.Where(x => x.MemoId == id && !x.IsDelete).Include(x => x.Bill).Select(x => x.Bill).ToListAsync();

            billMaster.ForEach(x => { x.BillStatusId = Convert.ToInt16(EnumList.BillStatus.BillClosed); x.UpdatedBy = userId; x.UpdatedDate = DateTime.Now; });

            _dbTeleBilling_V01Context.UpdateRange(billMaster);
            await _dbTeleBilling_V01Context.SaveChangesAsync();

            _dbTeleBilling_V01Context.Update(memo);
            await _dbTeleBilling_V01Context.SaveChangesAsync();

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

            return(true);
        }
コード例 #11
0
        public async Task <ResponseAC> UpdateTemplate(long userId, TemplateDetailAC templateDetailAC, string loginUserName)
        {
            ResponseAC responseAC = new ResponseAC();

            if (await _dbTeleBilling_V01Context.Emailtemplate.FirstOrDefaultAsync(x => x.EmailTemplateTypeId == templateDetailAC.EmailTemplateTypeId && x.Id != templateDetailAC.Id) == null)
            {
                Emailtemplate emailTemplate = await _dbTeleBilling_V01Context.Emailtemplate.FirstOrDefaultAsync(x => x.Id == templateDetailAC.Id);

                #region Transaction Log Entry
                if (emailTemplate.TransactionId == null)
                {
                    emailTemplate.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID();
                }

                var jsonSerailzeObj = JsonConvert.SerializeObject(emailTemplate);
                await _iLogManagement.SaveRequestTraseLog(Convert.ToInt64(emailTemplate.TransactionId), userId, Convert.ToInt64(EnumList.TransactionTraseLog.UpdateRecord), jsonSerailzeObj);

                #endregion

                emailTemplate             = _mapper.Map(templateDetailAC, emailTemplate);
                emailTemplate.UpdatedBy   = userId;
                emailTemplate.UpdatedDate = DateTime.Now;

                _dbTeleBilling_V01Context.Update(emailTemplate);
                await _dbTeleBilling_V01Context.SaveChangesAsync();

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

                await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.EditEmailTemplate, loginUserName, userId, "Email template(" + emailTemplate.Subject + ")", (int)EnumList.ActionTemplateTypes.Edit, emailTemplate.Id);
            }
            else
            {
                responseAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Error);
                responseAC.Message    = _iStringConstant.TemplateTypeAlreadyExists;
            }
            return(responseAC);
        }
コード例 #12
0
        public async Task <ResponseAC> UpdateProvider(long userId, ProviderAC providerAC, string loginUserName)
        {
            ResponseAC responeAC = new ResponseAC();

            if (await _dbTeleBilling_V01Context.Provider.FirstOrDefaultAsync(x => x.Id != providerAC.Id && x.ContractNumber.ToLower() == providerAC.ContractNumber.ToLower() && !x.IsDelete) == null)
            {
                TeleBillingUtility.Models.Provider provider = await _dbTeleBilling_V01Context.Provider.FirstOrDefaultAsync(x => x.Id == providerAC.Id);

                if (provider != null)
                {
                    #region Transaction Log Entry
                    if (provider.TransactionId == null)
                    {
                        provider.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID();
                    }

                    var jsonSerailzeObj = JsonConvert.SerializeObject(provider);
                    await _iLogManagement.SaveRequestTraseLog(Convert.ToInt64(provider.TransactionId), userId, Convert.ToInt64(EnumList.TransactionTraseLog.UpdateRecord), jsonSerailzeObj);

                    #endregion

                    provider             = _mapper.Map(providerAC, provider);
                    provider.UpdatedBy   = userId;
                    provider.UpdatedDate = DateTime.Now;

                    _dbTeleBilling_V01Context.Update(provider);
                    await _dbTeleBilling_V01Context.SaveChangesAsync();

                    #region Update Provider Service List
                    List <Providerservice> providerServiceList = await _dbTeleBilling_V01Context.Providerservice.Where(x => x.ProviderId == providerAC.Id && !x.IsDelete).ToListAsync();

                    if (providerServiceList.Any())
                    {
                        List <Providerservice> dummyProviderServices = new List <Providerservice>();
                        foreach (var item in providerServiceList)
                        {
                            item.IsDelete = true;
                            dummyProviderServices.Add(item);
                        }

                        _dbTeleBilling_V01Context.UpdateRange(dummyProviderServices);
                        _dbTeleBilling_V01Context.SaveChanges();
                    }

                    providerServiceList = new List <Providerservice>();
                    foreach (var serviceType in providerAC.ServiceTypes)
                    {
                        Providerservice providerService = new Providerservice();
                        providerService.ServiceTypeId = serviceType.Id;
                        providerService.ProviderId    = providerAC.Id;
                        providerServiceList.Add(providerService);
                    }

                    await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.EditProvider, loginUserName, userId, "Provider(" + provider.Name + ")", (int)EnumList.ActionTemplateTypes.Edit, provider.Id);

                    await _dbTeleBilling_V01Context.AddRangeAsync(providerServiceList);

                    await _dbTeleBilling_V01Context.SaveChangesAsync();

                    #endregion

                    #region Update Provider Contact Details
                    List <Providercontactdetail> providerContactDetails = await _dbTeleBilling_V01Context.Providercontactdetail.Where(x => x.ProviderId == provider.Id && !x.IsDeleted).ToListAsync();

                    if (providerContactDetails.Any())
                    {
                        List <Providercontactdetail> providerContactDetailList = new List <Providercontactdetail>();
                        foreach (var providerContact in providerContactDetails)
                        {
                            providerContact.IsDeleted = true;
                            providerContactDetailList.Add(providerContact);
                        }
                    }


                    #region Added Provider Contact Detail
                    providerContactDetails = new List <Providercontactdetail>();
                    foreach (var item in providerAC.ProviderContactDetailACList)
                    {
                        Providercontactdetail providerContectDatail = new Providercontactdetail();
                        providerContectDatail            = _mapper.Map <Providercontactdetail>(item);
                        providerContectDatail.Id         = 0;
                        providerContectDatail.ProviderId = provider.Id;
                        providerContactDetails.Add(providerContectDatail);
                    }

                    await _dbTeleBilling_V01Context.AddRangeAsync(providerContactDetails);

                    await _dbTeleBilling_V01Context.SaveChangesAsync();

                    #endregion

                    #endregion

                    responeAC.Message    = _iStringConstant.ProviderUpdatedSuccessfully;
                    responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success);
                }
            }
            else
            {
                responeAC.Message    = _iStringConstant.ContractNumberExists;
                responeAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Error);
            }
            return(responeAC);
        }
コード例 #13
0
        void timerBillClosed_Elapsed(object sender, ElapsedEventArgs e)
        {
            using (var _dbTeleBillingContext = new telebilling_v01Context())
            {
                try
                {
                    int billAllocatedStatusId     = Convert.ToInt16(EnumList.BillStatus.BillAllocated);
                    List <Billmaster> billMasters = _dbTeleBillingContext.Billmaster.Where(x => !x.IsDelete && (x.BillStatusId == billAllocatedStatusId)).ToList();
                    if (billMasters.Any())
                    {
                        foreach (var item in billMasters)
                        {
                            if (item.BillDueDate != null)
                            {
                                if (Convert.ToDateTime(item.BillDueDate).Date < DateTime.Now.Date)
                                {
                                    int billCloseStatusId         = Convert.ToInt16(EnumList.EmployeeBillStatus.CloseBill);
                                    int billAutoCloseBillStatusId = Convert.ToInt16(EnumList.EmployeeBillStatus.AutoCloseBill);
                                    List <Employeebillmaster> employeeBillMasters = _dbTeleBillingContext.Employeebillmaster.Where(x => x.BillMasterId == item.Id && !x.IsDelete && (x.EmployeeBillStatus != billCloseStatusId && x.EmployeeBillStatus != billAutoCloseBillStatusId)).Include(x => x.Employee).Include(x => x.Provider).ToList();
                                    List <Notificationlog>    notificationlogs    = new List <Notificationlog>();
                                    if (employeeBillMasters.Any())
                                    {
                                        foreach (var subItem in employeeBillMasters)
                                        {
                                            #region Transaction Log Entry

                                            if (subItem.TransactionId == null)
                                            {
                                                subItem.TransactionId = GenerateTeleBillingTransctionID();
                                            }

                                            //var jsonSerailzeObj = JsonConvert.SerializeObject(subItem);

                                            //SaveRequestTraseLog(Convert.ToInt64(subItem.TransactionId), 0, Convert.ToInt64(EnumList.TransactionTraseLog.BillClosed), jsonSerailzeObj);
                                            #endregion

                                            List <Employeebillservicepackage> employeeBillServicePackages = _dbTeleBillingContext.Employeebillservicepackage.Where(x => x.EmployeeBillId == subItem.Id && !x.IsDelete).Include(x => x.Package).ToList();
                                            foreach (var employeeBillServicePackage in employeeBillServicePackages)
                                            {
                                                if (!subItem.Employee.IsPresidentOffice)
                                                {
                                                    if (string.IsNullOrEmpty(subItem.TelephoneNumber))                                                    //For Skyp
                                                    {
                                                        //for service landline or voip
                                                        if (employeeBillServicePackage.ServiceTypeId == Convert.ToInt64(EnumList.ServiceType.VOIP) || employeeBillServicePackage.ServiceTypeId == Convert.ToInt64(EnumList.ServiceType.MOC))
                                                        {
                                                            if (subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.WaitingForIdentification) || subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.BillReject))
                                                            {
                                                                List <Billdetails> billdetails       = _dbTeleBillingContext.Billdetails.Where(x => x.EmployeeBillId == subItem.Id && x.ServiceTypeId == employeeBillServicePackage.ServiceTypeId).ToList();
                                                                decimal            personalDeduction = 0;
                                                                decimal            businessCharge    = 0;
                                                                foreach (var subBillDetail in billdetails)
                                                                {
                                                                    if (subBillDetail.CallIdentificationType == Convert.ToInt16(EnumList.AssignType.Business))
                                                                    {
                                                                        businessCharge += subBillDetail.CallAmount != null?Convert.ToDecimal(subBillDetail.CallAmount) : 0;
                                                                    }
                                                                    else if (subBillDetail.CallIdentificationType == Convert.ToInt16(EnumList.AssignType.Employee))
                                                                    {
                                                                        personalDeduction += subBillDetail.CallAmount != null?Convert.ToDecimal(subBillDetail.CallAmount) : 0;
                                                                    }
                                                                }
                                                                employeeBillServicePackage.PersonalIdentificationAmount = personalDeduction;
                                                                employeeBillServicePackage.BusinessIdentificationAmount = businessCharge;
                                                                employeeBillServicePackage.DeductionAmount = personalDeduction;
                                                            }
                                                            else if (subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.WaitingForLineManagerApproval) || subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.LineManagerApproved))
                                                            {
                                                                employeeBillServicePackage.DeductionAmount = employeeBillServicePackage.PersonalIdentificationAmount;
                                                            }
                                                            SendEmailNotificationToEmployee(employeeBillServicePackage, subItem);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        var telephoneNumberAllocation = _dbTeleBillingContext.Telephonenumberallocation.FirstOrDefault(x => x.TelephoneNumber == subItem.TelephoneNumber && x.EmployeeId == subItem.EmployeeId && !x.IsDelete);
                                                        if (telephoneNumberAllocation.AssignTypeId != Convert.ToInt16(EnumList.AssignType.Business))
                                                        {
                                                            employeeBillServicePackage.DeductionAmount = 0;
                                                            List <Billdetails> billDetails = _dbTeleBillingContext.Billdetails.Where(x => x.EmployeeBillId == subItem.Id && x.ServiceTypeId == employeeBillServicePackage.ServiceTypeId).ToList();
                                                            decimal            totalAmount = billDetails.Sum(x => x.CallAmount).Value;

                                                            //for service landline
                                                            if (employeeBillServicePackage.ServiceTypeId == Convert.ToInt64(EnumList.ServiceType.LandLine) || employeeBillServicePackage.ServiceTypeId == Convert.ToInt64(EnumList.ServiceType.StaticIP))
                                                            {
                                                                //remaning
                                                                employeeBillServicePackage.DeductionAmount = employeeBillServicePackage.PersonalIdentificationAmount;
                                                                SendEmailNotificationToEmployee(employeeBillServicePackage, subItem);
                                                            }
                                                            else
                                                            {
                                                                if (subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.WaitingForIdentification) || subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.BillReject))
                                                                {
                                                                    if (employeeBillServicePackage.Package.PackageAmount < totalAmount)
                                                                    {
                                                                        decimal amount = 0;
                                                                        decimal businessIdentificationAmount = employeeBillServicePackage.BusinessIdentificationAmount != null?Convert.ToDecimal(employeeBillServicePackage.BusinessIdentificationAmount) : 0;

                                                                        if (employeeBillServicePackage.Package.PackageAmount < businessIdentificationAmount)
                                                                        {
                                                                            amount = businessIdentificationAmount;
                                                                        }
                                                                        else
                                                                        {
                                                                            amount = employeeBillServicePackage.Package.PackageAmount != null?Convert.ToDecimal(employeeBillServicePackage.Package.PackageAmount) : 0;
                                                                        }
                                                                        //BusinessIdentificationAmount alway less than or equal Package Amount
                                                                        employeeBillServicePackage.DeductionAmount = totalAmount - amount;
                                                                        SendEmailNotificationToEmployee(employeeBillServicePackage, subItem);
                                                                    }
                                                                    else
                                                                    {
                                                                        employeeBillServicePackage.DeductionAmount = 0;
                                                                    }
                                                                }
                                                                else if (subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.WaitingForLineManagerApproval) || subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.LineManagerApproved))
                                                                {
                                                                    if (subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.WaitingForLineManagerApproval))
                                                                    {
                                                                        List <Billdetails> billdetails = _dbTeleBillingContext.Billdetails.Where(x => x.EmployeeBillId == subItem.Id).ToList();
                                                                        var serviceBillDetials         = billdetails.GroupBy(x => x.ServiceTypeId);
                                                                        var finalServiceDetails        = serviceBillDetials.Where(x => x.Key == employeeBillServicePackage.ServiceTypeId);

                                                                        foreach (var billDetailsData in finalServiceDetails)
                                                                        {
                                                                            decimal personalDeduction = 0;
                                                                            decimal businessCharge    = 0;
                                                                            foreach (var subBillDetail in billDetailsData)
                                                                            {
                                                                                if (subBillDetail.CallIdentificationType == Convert.ToInt16(EnumList.AssignType.Business))
                                                                                {
                                                                                    businessCharge += subBillDetail.CallAmount != null?Convert.ToDecimal(subBillDetail.CallAmount) : 0;
                                                                                }
                                                                                else if (subBillDetail.CallIdentificationType == Convert.ToInt16(EnumList.AssignType.Employee))
                                                                                {
                                                                                    personalDeduction += subBillDetail.CallAmount != null?Convert.ToDecimal(subBillDetail.CallAmount) : 0;
                                                                                }
                                                                            }
                                                                            employeeBillServicePackage.PersonalIdentificationAmount = personalDeduction;
                                                                            employeeBillServicePackage.BusinessIdentificationAmount = businessCharge;
                                                                        }
                                                                    }

                                                                    if (employeeBillServicePackage.Package.PackageAmount < totalAmount)
                                                                    {
                                                                        decimal businessIdentificationAmount = employeeBillServicePackage.BusinessIdentificationAmount != null?Convert.ToDecimal(employeeBillServicePackage.BusinessIdentificationAmount) : 0;

                                                                        decimal amount = 0;
                                                                        if (employeeBillServicePackage.Package.PackageAmount < businessIdentificationAmount)
                                                                        {
                                                                            amount = businessIdentificationAmount;
                                                                        }
                                                                        else
                                                                        {
                                                                            amount = employeeBillServicePackage.Package.PackageAmount != null?Convert.ToDecimal(employeeBillServicePackage.Package.PackageAmount) : 0;
                                                                        }
                                                                        employeeBillServicePackage.DeductionAmount = totalAmount - amount;
                                                                        SendEmailNotificationToEmployee(employeeBillServicePackage, subItem);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            employeeBillServicePackage.DeductionAmount = 0;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    employeeBillServicePackage.DeductionAmount = 0;
                                                }
                                                employeeBillServicePackage.UpdateDate = DateTime.Now;
                                            }

                                            _dbTeleBillingContext.UpdateRange(employeeBillServicePackages);
                                            _dbTeleBillingContext.SaveChanges();

                                            subItem.EmployeeBillStatus = Convert.ToInt16(EnumList.EmployeeBillStatus.AutoCloseBill);
                                            subItem.UpdatedDate        = DateTime.Now;
                                            subItem.BillClosedDate     = DateTime.Now;


                                            #region Notification FOR Bill Close
                                            notificationlogs.Add(GenerateNotificationObject(Convert.ToInt16(subItem.EmployeeId), 1, Convert.ToInt16(EnumList.NotificationType.BillClosed), subItem.Id));
                                            #endregion
                                        }

                                        if (notificationlogs.Any())
                                        {
                                            _dbTeleBillingContext.AddRange(notificationlogs);
                                            _dbTeleBillingContext.SaveChanges();
                                        }

                                        _dbTeleBillingContext.UpdateRange(employeeBillMasters);
                                        _dbTeleBillingContext.SaveChanges();

                                        Billmaster billMaster = _dbTeleBillingContext.Billmaster.FirstOrDefault(x => x.Id == employeeBillMasters[0].BillMasterId && !x.IsDelete);
                                        if (billMaster != null)
                                        {
                                            billMaster.BillStatusId = Convert.ToInt16(EnumList.BillStatus.BillClosed);
                                            billMaster.UpdatedDate  = DateTime.Now;

                                            _dbTeleBillingContext.Update(billMaster);
                                            _dbTeleBillingContext.SaveChanges();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (global::System.Exception ex)
                {
                    throw ex;
                }
            }
        }