Example #1
0
        public JsonResult FeeAllocationInsert(string[] txtFeeHeadId, string[] txtAmount, string [] txtDiscountAmnt, string [] txtDiscountPer, int [] ddlPaymentType)
        {
            FeeAllocationType feeAllocationType = (FeeAllocationType)(int)TempData["allocationId"];
            var result = _feeAllocationRepository.AllocateStudentFee(feeAllocationType, TempData["allocationOn"].ToString(), txtFeeHeadId, txtAmount, txtDiscountPer, txtDiscountAmnt, ddlPaymentType);

            return(Json(result));
        }
        public string AllocateStudentFee(FeeAllocationType feeAllocationType, string paramsData, string[] headId, string[] amount, string [] discountPerce, string[] discountAmnt, int [] paymentType)
        {
            UpSertFeeAllocationMaster(feeAllocationType, paramsData, headId, amount, discountPerce, discountAmnt, paymentType);
            List <int> studentIds = new List <int>();

            switch (feeAllocationType)
            {
            case FeeAllocationType.Class:
                studentIds = GetStudentListFromMapping(paramsData.ConvertStringTolistInt <int>());
                DeActiveFeeForStudent(studentIds);
                AllocateStudentFee(studentIds, headId, amount, discountAmnt, discountPerce, paymentType);
                return("Class Fee Allocation");

            case FeeAllocationType.Gender:
                List <int> genderIds = paramsData.ConvertStringTolistInt <int>();
                studentIds = GetStudentListFromMaster(item => genderIds.Contains((int)item.GenderId));
                DeActiveFeeForStudent(studentIds);
                AllocateStudentFee(studentIds, headId, amount, discountAmnt, discountPerce, paymentType);
                return("Gender Fee Allocation");

            case FeeAllocationType.Cast:
                List <int> castIds = paramsData.ConvertStringTolistInt <int>();
                studentIds = GetStudentListFromMaster(item => castIds.Contains((int)item.CastId));
                DeActiveFeeForStudent(studentIds);
                AllocateStudentFee(studentIds, headId, amount, discountAmnt, discountPerce, paymentType);
                return("Cast Fee Allocation");

            case FeeAllocationType.Religion:
                List <int> religionIds = paramsData.ConvertStringTolistInt <int>();
                studentIds = GetStudentListFromMaster(item => religionIds.Contains((int)item.ReligionId));
                DeActiveFeeForStudent(studentIds);
                AllocateStudentFee(studentIds, headId, amount, discountAmnt, discountPerce, paymentType);
                return("Religion Fee Allocation");

            case FeeAllocationType.Category:
                List <int> categoryIds = paramsData.ConvertStringTolistInt <int>();
                studentIds = GetStudentListFromMaster(item => categoryIds.Contains((int)item.CategoryId));
                DeActiveFeeForStudent(studentIds);
                AllocateStudentFee(studentIds, headId, amount, discountAmnt, discountPerce, paymentType);
                return("Category Fee Allocation");

            default:
                return("Default fee Allocation");
            }
        }
        public void UpSertFeeAllocationMaster(FeeAllocationType feeAllocationType, string allocationOn, string[] HeadType, string[] amount, string[] discountPercenatge, string[] discountAmount, int [] paymentType)
        {
            var allocationList = (string.Join(",", allocationOn)).ConvertStringTolistInt <int>();

            using (var dbContext = new DB_SPADevelopementEntities())
            {
                var result = dbContext.StudentFeeAllocationMasters.Where(item => allocationList.Contains(item.AllocationTypeId)).ToList();
                result.ForEach(item =>
                {
                    item.IsActive               = 0;
                    item.UpdatedBy              = 1;
                    item.UpDatedDate            = DateTime.Now.Date;
                    dbContext.Entry(item).State = System.Data.Entity.EntityState.Modified;
                    dbContext.SaveChanges();
                });

                for (int i = 0; i < allocationOn.Count(); i++)
                {
                    for (int j = 0; j < HeadType.Count(); j++)
                    {
                        StudentFeeAllocationMaster studentFeeAllocationMaster = new StudentFeeAllocationMaster();
                        studentFeeAllocationMaster.AllocationOn       = Convert.ToInt32(allocationOn[i]);
                        studentFeeAllocationMaster.AllocationTypeId   = Convert.ToInt32(feeAllocationType);
                        studentFeeAllocationMaster.HeadTypeId         = Convert.ToInt32(HeadType[j]);
                        studentFeeAllocationMaster.Amount             = Convert.ToDecimal(amount[j]);
                        studentFeeAllocationMaster.DiscountPercenatge = !string.IsNullOrEmpty(discountPercenatge[j])? Convert.ToDecimal(discountPercenatge[j]) :0;
                        studentFeeAllocationMaster.DiscountAmount     = !string.IsNullOrEmpty(discountAmount[j]) ? Convert.ToDecimal(discountAmount[j]) :0;
                        studentFeeAllocationMaster.FeeType            = Convert.ToInt32(paymentType[j]);

                        studentFeeAllocationMaster.IsActive  = 1;
                        studentFeeAllocationMaster.CreatedBy = 1;

                        dbContext.StudentFeeAllocationMasters.Add(studentFeeAllocationMaster);
                        dbContext.SaveChanges();
                    }
                }
            }
        }