Exemple #1
0
        public async Task <ActionResult> UpdateFee(string id, string feeStatus)
        {
            var fees = await _feeService.Get(x => x.Id == id.AsObjectId());

            var fee   = fees.FirstOrDefault();
            var model = new FeeCollectionComponentViewModel();

            model.OnlinePayment = false;
            foreach (var tran in fee.Transactions)
            {
                var transcaions = await _transactionService.Get(x => x.Id == tran.TransactionId);

                var transcaion = transcaions.FirstOrDefault();
                if (transcaion != null)
                {
                    if (transcaion.AmountMode == AmountMode.OnlinePayement)
                    {
                        model.OnlinePayment = true;
                    }
                }
            }

            var school = await _schoolService.GetSchoolById(fee.SchoolId.ToString());

            var schoolComponent = school.SchoolFeeComponents;

            var allPaidComponents = fee.Transactions.SelectMany(x => x.Components);
            var dict = allPaidComponents.GroupBy(x => x.ComponetId)
                       .ToDictionary(x => x.Key, x => x.Sum(p => p.Value));

            foreach (var comp in fee.Components)
            {
                var feeComp = new ComponentsViewModel
                {
                    ComponetId = comp.ComponetId.ToString(),
                    Value      = comp.Value
                };
                var schoolCompSingle = schoolComponent.FirstOrDefault(x => x.Id == comp.ComponetId);
                if (schoolCompSingle != null)
                {
                    feeComp.Name = schoolCompSingle.Name;
                }
                var paidVal = 0.0;
                if (dict.ContainsKey(comp.ComponetId))
                {
                    paidVal = paidVal + dict[comp.ComponetId];
                }
                feeComp.Paid = paidVal;
                model.Components.Add(feeComp);
            }

            model.FeeId = id;

            model.Remark = fee.Remark;

            model.FeeStatus = feeStatus;
            return(Ok(model));
        }
Exemple #2
0
        public async Task <ActionResult> UpdateFee(FeeCollectionComponentViewModel model)
        {
            var feeCollections = await _feeService.Get(x => x.Id == model.FeeId.AsObjectId());

            var fee = feeCollections.FirstOrDefault();

            if (fee == null)
            {
                return(RedirectToAction("Index", new { model.ClassId, model.FeeCycleId, model.StudentId }));
            }
            var feeComponents = model.Components.ToDictionary(comp =>
                                                              comp.ComponetId.AsObjectId(),
                                                              comp => comp.Value
                                                              );

            var school = await _schoolService.GetSchoolById(fee.SchoolId.ToString());

            FeeStatus feeStatus = (FeeStatus)Enum.Parse(typeof(FeeStatus), model.FeeStatus);
            await _feeService.UpdateStudentFee(feeComponents, fee.Id, school, feeStatus, remark : model.Remark);

            return(Ok());
        }