public getStudentDiscountsList getStudentDiscountsList()
        {
            var model = new getStudentDiscountsList();

            try
            {
                var StudentDiscountsList = _StudentDiscountsRepo.GetAll().ToList();
                var FeeTypesList         = _FeeTypesRepo.GetAll().ToList();
                var studentsList         = _studentsRepo.GetAll().ToList();
                var classList            = _classesRepo.GetAll().ToList();
                var query = (from _StudentDiscounts in StudentDiscountsList
                             join _FeeTypes in FeeTypesList on _StudentDiscounts?.FeeTypeId equals _FeeTypes?.Id
                             join _students in studentsList on _StudentDiscounts?.StudentId equals _students?.Id
                             join _class in classList on _students?.ClassId equals _class?.Id
                             select new { _StudentDiscounts, _FeeTypes, _students, _class });

                var list = new List <getStudentDiscountsList_StudentDiscounts>();
                foreach (var item in query)
                {
                    var temp = new getStudentDiscountsList_StudentDiscounts()
                    {
                        Id             = item._StudentDiscounts.Id,
                        RegistrationNo = item._students.RegistrationNo,
                        StudentId      = item._StudentDiscounts.StudentId,
                        StudentName    = item._students.FirstName + " " + item._students.LastName,
                        ClassId        = item._students.ClassId,
                        ClassName      = item._class.Name,
                        FeeTypeId      = item._StudentDiscounts.FeeTypeId,
                        FeeType        = item._FeeTypes.Name,
                        DiscountAmout  = item._StudentDiscounts.DiscountAmout
                    };
                    list.Add(temp);
                }
                ;

                model = new getStudentDiscountsList()
                {
                    _StudentDiscounts = list
                };
            }
            catch (Exception)
            {
            }
            return(model);
        }
        public getStudentPaymentsList getStudentPaymentsList()
        {
            var model = new getStudentPaymentsList();

            try
            {
                var StudentPaymentsList = _StudentPaymentsRepo.GetAll().ToList();
                var FeeTypesList        = _FeeTypesRepo.GetAll().ToList();
                var studentsList        = _studentsRepo.GetAll().ToList();
                var query = (from _StudentPayments in StudentPaymentsList
                             join _FeeTypes in FeeTypesList on _StudentPayments?.FeeTypeId equals _FeeTypes?.Id
                             join _Students in studentsList on _StudentPayments?.StudentId equals _Students?.Id
                             select new { _StudentPayments, _Students, _FeeTypes });
                var list = new List <getStudentPaymentsList_StudentPayments>();
                foreach (var item in query)
                {
                    var temp = new getStudentPaymentsList_StudentPayments()
                    {
                        Id          = item._StudentPayments.Id,
                        ClassId     = item._StudentPayments.ClassId,
                        FeeYearDate = item._StudentPayments.FeeYearDate,
                        StudentId   = item._StudentPayments.StudentId,
                        StudentName = item._Students.FirstName + " " + item._Students.LastName,
                        FeeTypeId   = item._StudentPayments.FeeTypeId,
                        FeeType     = item._FeeTypes.Name,
                        Fine        = item._StudentPayments.Fine,
                        PaidAmount  = item._StudentPayments.PaidAmount,
                        PaymentDate = item._StudentPayments.PaymentDate,
                        Remarks     = item._StudentPayments.Remarks
                    };
                    list.Add(temp);
                }
                ;
                model = new getStudentPaymentsList()
                {
                    _StudentPayments = list
                };
            }
            catch (Exception)
            {
            }
            return(model);
        }
        public async Task <ActionResult <StudentsModel[]> > Get(bool includeSubjects = false)
        {
            //try
            //{
            var results = await _repo.GetAll(includeSubjects);

            return(_mapper.Map <StudentsModel[]>(results));

            //}
            //catch (Exception)
            //{
            //    return this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure -Talkss");
            //    //return Ok("Under Maintenance.");
            //}
        }
        public getStudentPromotionsList getStudentPromotionsList()
        {
            var model = new getStudentPromotionsList();

            try
            {
                var StudentPromotionsList = _StudentPromotionsRepo.GetAll().ToList();
                var studentsList          = _studentsRepo.GetAll().ToList();
                var classList             = _classesRepo.GetAll().ToList();
                var query = (from _StudentPromotion in StudentPromotionsList
                             join _Class in classList on _StudentPromotion?.ClassId equals _Class?.Id
                             join _student in studentsList on _StudentPromotion?.StudentId equals _student?.Id
                             select new { _StudentPromotion, _Class, _student });
                var list = new List <getStudentPromotionsList_StudentPromotions>();
                foreach (var item in query)
                {
                    var temp = new getStudentPromotionsList_StudentPromotions()
                    {
                        Id             = item._StudentPromotion.Id,
                        ClassId        = item._StudentPromotion.ClassId,
                        ClassName      = item._Class.Name,
                        StudentId      = item._StudentPromotion.StudentId,
                        RegistrationNo = item._student.RegistrationNo,
                        RollNo         = item._StudentPromotion.RollNo,
                        ClassYear      = item._StudentPromotion.ClassYear,
                        IsActive       = item._StudentPromotion.IsActive,
                        AddedBy        = item._StudentPromotion.AddedBy,
                        AddedDate      = item._StudentPromotion.AddedDate,
                        ModifiedBy     = item._StudentPromotion.ModifiedBy,
                        ModifiedDate   = item._StudentPromotion.ModifiedDate,
                        DataType       = item._StudentPromotion.DataType
                    };
                    list.Add(temp);
                }
                ;


                model = new getStudentPromotionsList()
                {
                    _StudentPromotions = list,
                };
            }
            catch (Exception)
            {
            }
            return(model);
        }
        public GetFeeStructuresByClass GetFeeStructuresByClass(long StudentId, long ClassId, long ClassYear)
        {
            var model = new GetFeeStructuresByClass();

            try
            {
                var StudentPaymentsList = _StudentPaymentsRepo.GetAll().ToList();
                var studentsList        = _studentsRepo.GetAll().ToList();
                var FeeTypesList        = _FeeTypesRepo.GetAll().ToList();
                var classes             = _classesRepo.GetAll().ToList();
                var feeStructure        = _FeeStructuresRepo.GetAll().ToList();
                var studentPromotion    = _StudentPromotionsRepo.GetAll().ToList();
                var studentDiscount     = _StudentDiscountsRepo.GetAll().ToList();
                var feeTermDescription  = _FeeTermDescriptions.GetAll().ToList();
                var StudentDetails      = (from c in studentsList
                                           where c.Id == StudentId
                                           select c).SingleOrDefault();
                var getClass = (from cls in classes
                                where cls.Id == ClassId
                                select cls).SingleOrDefault();
                var getStuFeeYear = (from sp in studentPromotion
                                     where sp.StudentId == StudentId && sp.ClassId == ClassId
                                     select sp).SingleOrDefault();

                //[Note: Step 1- Get Student from promotion table for all class ]
                var query = (from sp in studentPromotion
                             where sp.StudentId == StudentId
                             join s in studentsList on sp.StudentId equals s.Id
                             join c in classes on sp.ClassId equals c.Id
                             join f in FeeTypesList on c?.Id equals f?.ClassId into allFeeTypes
                             from feeTypes in allFeeTypes.DefaultIfEmpty()
                             join fs in feeStructure on feeTypes?.Id equals fs?.FeeTypeId into allfeeStructure
                             from feeStucture in allfeeStructure.DefaultIfEmpty()
                             select new
                {
                    Id = sp.Id,
                    StudentId = StudentId,
                    StuClassId = sp.ClassId,
                    StuFeeYear = sp?.ClassYear,
                    StuFeeType = feeStucture.FeeTypeId,
                    StuClassName = c.Name,
                    FeeTypeName = feeTypes?.Name,
                    FeeAmount = feeStucture?.Amount,
                    StuPaymentDate = (dynamic)null,
                    StuPaidAmount = 0,
                    StuFine = 0,
                    StuRemarks = "",
                    StuDiscount = 0
                }).ToList();

                //[NOTE:Step 2- get discount of the student if exist]
                studentDiscount = studentDiscount.Where(s => s.StudentId == StudentId).ToList();
                if (query != null)
                {
                    //var list = new List<SearchPaymentDetailById_StudentPayments>();
                    var list = new List <GetFeeStructuresByClass_FeeStructures>();
                    //decimal? totalPaid = 0;
                    //decimal? totalDiscount = 0;
                    //decimal? totalFeeAmount = 0;
                    //decimal? totalFine = 0;

                    foreach (var item in query)
                    {
                        var getFeeTerm = from ft in feeTermDescription
                                         join fs in feeStructure on ft.FeeStructureId equals fs.Id
                                         //where fs.ClassId == ClassId && fs.FeeTypeId == item.StuFeeType && fs.StartingYear <= item.StuFeeYear && fs.EndingYear >= item.StuFeeYear
                                         where fs.ClassId == ClassId && fs.FeeTypeId == item.StuFeeType
                                         select new { ft, fs };

                        //[NOTE:Step 3- find feetype discount if exist]
                        decimal?currentTypeDiscountAmount = 0;
                        if (studentDiscount.Count() > 0)
                        {
                            currentTypeDiscountAmount = (from s in studentDiscount
                                                         where s.FeeTypeId == item.StuFeeType
                                                         select s.DiscountAmout).FirstOrDefault();
                        }
                        foreach (var item2 in getFeeTerm)
                        {
                            //[NOTE: get existing payment of the student if exist]
                            var GetPaymentListOfTheStudent = (from p in StudentPaymentsList
                                                              where p.StudentId == StudentId &&
                                                              p.ClassId == item2.fs.ClassId &&
                                                              p.FeeTermDescriptionId == item2.ft.Id &&
                                                              p.FeeTypeId == item2.fs.FeeTypeId &&
                                                              (p.FeeYearDate.Value.Year == ClassYear)
                                                              select p).FirstOrDefault();
                            var temp = new GetFeeStructuresByClass_FeeStructures()
                            {
                                Id                   = item.Id,
                                ClassId              = item.StuClassId,
                                FeeTypeId            = item.StuFeeType,
                                FeeType              = item.FeeTypeName,
                                FeeTypeMood          = item2.ft.TermNo,
                                Amount               = item.FeeAmount != null ? (dynamic)item.FeeAmount : 0,
                                Fine                 = GetPaymentListOfTheStudent != null ? GetPaymentListOfTheStudent.Fine : 0,
                                FeeTermDescriptionId = item2.ft.Id,
                                TermNo               = item2.ft.TermNo,
                                TermName             = item2.ft.TermName,
                                PaidAmount           = GetPaymentListOfTheStudent != null ? GetPaymentListOfTheStudent.PaidAmount : 0,
                                Remarks              = item.StuRemarks,
                                StartingYear         = item2.fs.StartingYear,
                                EndingYear           = item2.fs.EndingYear,
                                DiscountAmount       = (dynamic)currentTypeDiscountAmount,
                                IsActive             = item2.fs.IsActive
                            };
                            list.Add(temp);
                        }
                    }
                    ;
                    model = new GetFeeStructuresByClass()
                    {
                        ClassName      = getClass.Name,
                        FeeYear        = getStuFeeYear.ClassYear.Value.Year,
                        _FeeStructures = list
                    };
                }
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
            }
            return(model);
        }
        public getStudentsList.getStudentsList getStudentList(getStudentsList.getStudentsList obj)
        {
            var model = (dynamic)null;

            try
            {
                var studentsList          = _studentsRepo.GetAll().ToList();
                var StudentPromotionsList = _StudentPromotionsRepo.GetAll().ToList();
                var thisYear    = DateTime.Now.Year;
                var ClassList   = _classesRepo.GetAll().ToList();
                var GendersList = _GendersRepo.GetAll().ToList();
                var query       = (from _students in studentsList
                                   join _Classes in ClassList on _students?.ClassId equals _Classes?.Id
                                   join _Genders in GendersList on _students?.GenderId equals _Genders?.Id
                                   join _studentPromotion in StudentPromotionsList on _students.Id equals _studentPromotion.StudentId
                                   join _promotionClass in ClassList on _studentPromotion.ClassId equals _promotionClass.Id
                                   where _studentPromotion.StudentId == _students.Id && _studentPromotion.ClassYear.Value.Year == thisYear
                                   orderby _students.ClassId, _students.FirstName ascending
                                   select new { _students, _Classes, _Genders, _studentPromotion, _promotionClass });
                var list = new List <getStudentsList.getStudentsList_Students>();
                foreach (var item in query)
                {
                    string path = string.IsNullOrEmpty(item._students.IP300X200) ? "" : item._students.IP300X200;
                    var    temp = new getStudentsList.getStudentsList_Students()
                    {
                        Id               = item._students.Id,
                        ClassId          = item._students.ClassId,
                        RollNO           = item._studentPromotion.RollNo,
                        CurrentClassId   = item._studentPromotion.ClassId,
                        CurrentYear      = item._studentPromotion.ClassYear,
                        ClassName        = item._Classes.Name,
                        GenderId         = item._students.GenderId,
                        RegistrationNo   = item._students.RegistrationNo,
                        GenderName       = item._Genders.Name,
                        FirstName        = item._students.FirstName,
                        LastName         = item._students.LastName,
                        StudentName      = item._students.FirstName + "  " + item._students.LastName,
                        IP300X200        = _commonServ.CommImage_WrapperDefaultImage(path, obj.WebRootPath, item._students.GenderId),
                        AdmittedYear     = item._students.AdmittedYear,
                        PresentAddress   = item._students.PresentAddress,
                        PermanentAddress = item._students.PermanentAddress,
                        DOB              = item._students.DOB,
                        IsActive         = item._students.IsActive,
                        AddedBy          = 0,
                        AddedDate        = DateTime.Now,
                        ModifiedBy       = 0,
                        ModifiedDate     = DateTime.Now,
                        DataType         = null
                    };
                    list.Add(temp);
                }
                ;
                model = new getStudentsList.getStudentsList()
                {
                    _Students = list
                };
            }
            catch (Exception)
            {
            }
            return(model);
        }