/// <summary>
        /// Method to generate auto sequence data - SS
        /// </summary>
        /// <param name="instituteId">institue id</param>
        /// <param name="typeEnum">type of data</param>
        /// <returns>response</returns>
        public async Task <GenerateAutoSequenceDataResponse> GetAutoSequenceNumberByTypeAndInstituteIdAsync(int instituteId, AutoSequenceGeneratorTypeEnum typeEnum)
        {
            var autoSequence = await _iMSDbContext.AutoSequenceGenerators.Include(s => s.AutoSequenceGeneratorDataTypes)
                               .Include(d => d.Institute).FirstOrDefaultAsync(x => x.InstituteId == instituteId && x.AutoSequenceGeneratorType == typeEnum);

            if (autoSequence == null)
            {
                return new GenerateAutoSequenceDataResponse()
                       {
                           HasValue = false
                       }
            }
            ;
            else
            {
                string value = string.Empty;

                var selected = autoSequence.AutoSequenceGeneratorDataTypes.OrderByDescending(x => x.OrderId).Where(x => x.IsSelected).ToList();
                selected.Reverse();
                for (int i = 0; i < selected.Count; i++)
                {
                    var data = selected[i];
                    switch (data.Name)
                    {
                    case "Institute":
                    {
                        value += autoSequence.Institute.Name.Substring(0, (autoSequence.Institute.Name.Length >= data.Length ? data.Length : autoSequence.Institute.Name.Length));

                        if ((selected.Count - 1) != i)
                        {
                            value += EnumHelperService.GetDescription(autoSequence.Seperator);
                        }
                    }
                    break;

                    case "Day":
                    {
                        value += DateTime.UtcNow.DayOfWeek.GetDescription();
                        if ((selected.Count - 1) != i)
                        {
                            value += EnumHelperService.GetDescription(autoSequence.Seperator);
                        }
                    }
                    break;

                    case "Month":
                    {
                        value += DateTime.UtcNow.Month;
                        if ((selected.Count - 1) != i)
                        {
                            value += EnumHelperService.GetDescription(autoSequence.Seperator);
                        }
                    }
                    break;

                    case "Year":
                    {
                        value += DateTime.UtcNow.Year;
                        if ((selected.Count - 1) != i)
                        {
                            value += EnumHelperService.GetDescription(autoSequence.Seperator);
                        }
                    }
                    break;

                    case "Date":
                    {
                        value += DateTime.UtcNow.Day;
                        if ((selected.Count - 1) != i)
                        {
                            value += EnumHelperService.GetDescription(autoSequence.Seperator);
                        }
                    }
                    break;

                    case "Text":
                    {
                        value += autoSequence.CustomText.Substring(0, data.Length);
                        if ((selected.Count - 1) != i)
                        {
                            value += EnumHelperService.GetDescription(autoSequence.Seperator);
                        }
                    }
                    break;

                    case "Sequence Number":
                    {
                        var count = 0;
                        if (typeEnum == AutoSequenceGeneratorTypeEnum.RollNumber)
                        {
                            count = await _iMSDbContext.StudentBasicInformation.CountAsync();
                        }
                        else if (typeEnum == AutoSequenceGeneratorTypeEnum.RefundNumber)
                        {
                            count = await _iMSDbContext.FeeRefunds.CountAsync();
                        }
                        else if (typeEnum == AutoSequenceGeneratorTypeEnum.ReceiptNumber)
                        {
                            count = await _iMSDbContext.FeeReceipts.CountAsync();
                        }
                        else if (typeEnum == AutoSequenceGeneratorTypeEnum.ChartOfAccountsCode)
                        {
                            count = await _iMSDbContext.FinanceChartOfAccounts.CountAsync();
                        }
                        else
                        {
                            count = await _iMSDbContext.StaffBasicPersonalInformation.CountAsync();
                        }
                        count++;
                        var length = "D" + data.Length;
                        value += count.ToString(length);
                        if ((selected.Count - 1) != i)
                        {
                            value += EnumHelperService.GetDescription(autoSequence.Seperator);
                        }
                    }
                    break;
                    }
                }
                return(new GenerateAutoSequenceDataResponse()
                {
                    HasValue = true, Data = value, Seperator = EnumHelperService.GetDescription(autoSequence.Seperator)
                });
            }
        }
        /// <summary>
        /// Method to seed data for auto sequence - SS
        /// </summary>
        /// <param name="instituteId">institute id</param>
        /// <param name="loggedInUserId">logged in user</param>
        private async Task SeedDataForAutoSequenceByTypeAsync(int instituteId, string loggedInUserId, AutoSequenceGeneratorTypeEnum type)
        {
            await semaphore.WaitAsync();

            try
            {
                if (!await _iMSDbContext.AutoSequenceGenerators.AnyAsync(x => x.InstituteId == instituteId && x.AutoSequenceGeneratorType == type))
                {
                    var availableData = new List <string>()
                    {
                        "Institute", "Day", "Month", "Year", "Date", "Text", "Sequence Number"
                    };
                    var autoSequence = new AutoSequenceGenerator()
                    {
                        AutoSequenceGeneratorType = type,
                        CreatedById = loggedInUserId,
                        CreatedOn   = DateTime.UtcNow,
                        CustomText  = string.Empty,
                        InstituteId = instituteId,
                        Seperator   = AutoSequenceGeneratorSeperatorEnum.None,
                        UpdateById  = loggedInUserId,
                        UpdateDate  = DateTime.UtcNow
                    };
                    _iMSDbContext.AutoSequenceGenerators.Add(autoSequence);
                    await _iMSDbContext.SaveChangesAsync();

                    #region AutoSequenceGeneratorDataType
                    List <AutoSequenceGeneratorDataType> generatorDataTypes = new List <AutoSequenceGeneratorDataType>();
                    int orderId = 0;
                    foreach (var data in availableData)
                    {
                        generatorDataTypes.Add(new AutoSequenceGeneratorDataType()
                        {
                            CreatedOn  = DateTime.UtcNow,
                            IsSelected = (data == "Sequence Number"),
                            AutoSequenceGeneratorId = autoSequence.Id,
                            OrderId = orderId,
                            Name    = data,
                            Length  = (data == "Sequence Number") ? 5 : 3
                        });
                        orderId++;
                    }
                    _iMSDbContext.AutoSequenceGeneratorDataTypes.AddRange(generatorDataTypes);
                    await _iMSDbContext.SaveChangesAsync();

                    #endregion
                }
            }
            finally
            {
                semaphore.Release();
            }
        }
        /// <summary>
        /// Method to get auto sequence data - SS
        /// </summary>
        /// <param name="loggedInUser">logged in user detail</param>
        /// <param name="generatorTypeEnum">auto sequence type</param>
        /// <returns>auto sequence data</returns>
        public async Task <AutoSequenceGenerator> GetSequenceGeneratorsAsync(ApplicationUser loggedInUser, AutoSequenceGeneratorTypeEnum generatorTypeEnum)
        {
            var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true);

            await SeedDataForAutoSequenceByTypeAsync(instituteId, loggedInUser.Id, generatorTypeEnum);

            var autoSequence = await _iMSDbContext.AutoSequenceGenerators.Include(x => x.AutoSequenceGeneratorDataTypes)
                               .FirstAsync(x => x.AutoSequenceGeneratorType == generatorTypeEnum && x.InstituteId == instituteId);

            autoSequence.SeperatorDescription           = EnumHelperService.GetDescription(autoSequence.Seperator);
            autoSequence.AutoSequenceGeneratorDataTypes = autoSequence.AutoSequenceGeneratorDataTypes.OrderByDescending(x => x.OrderId).ToList();
            autoSequence.AutoSequenceGeneratorDataTypes = autoSequence.AutoSequenceGeneratorDataTypes.Reverse().ToList();
            return(autoSequence);
        }