Example #1
0
        public async Task <IBusinessResultValue <MemberPromotion> > LoadMemberPromotionAsync(int memberId, int month, int year, ReviewPromotionStepEnum stepPromotionTypeId)
        {
            var result = new BusinessResultValue <MemberPromotion>();

            try
            {
                result.ResultValue = await unitOfWork.MemberPromotionDataService.FirstOrDefaultAsync(x => x.MemberId == memberId &&
                                                                                                     x.BranchPromotion.Month == month && x.BranchPromotion.Year == year &&
                                                                                                     x.Details.Any(y => y.ReviewPromotionStepId == stepPromotionTypeId)
                                                                                                     , includes : x => new { x.BranchPromotion, x.Details });

                if (result.ResultValue == null && stepPromotionTypeId == ReviewPromotionStepEnum.Manager)
                {
                    var sellerTotalPromtion = await(from mep in unitOfWork.SellerPromotionDataService.GetQuery()
                                                    join brp in unitOfWork.BranchPromotionDataService.GetQuery()
                                                    on mep.BranchPromotionId equals brp.Id
                                                    where mep.MemberId == memberId && brp.Month == month && brp.Year == year && mep.Deleted == false
                                                    group mep by mep.MemberId into grp_memp
                                                    select grp_memp.Sum(x => x.Promotion)).FirstOrDefaultAsync();

                    MemberPromotion memberPromotion = new MemberPromotion {
                        MemberId = memberId
                    };
                    memberPromotion.Details.Add(new MemberPromotionDetail {
                        CompensatoryPromotion = sellerTotalPromtion
                    });
                    result.ResultValue = memberPromotion;
                }
                else
                {
                    result.ResultValue = new MemberPromotion {
                        MemberId = memberId
                    };
                }
            }
            catch (Exception ex)
            {
                CatchException(ex, result, "");
            }
            return(result);
        }
 private decimal getTotalPromotion(MemberPromotion memberPromotion, ReviewPromotionStepEnum reviewPromotionStepId)
 {
     return(memberPromotion.Details.Where(c => c.ReviewPromotionStepId == reviewPromotionStepId).Sum(c => c.BranchSalesPromotion + c.CompensatoryPromotion + c.ReceiptPromotion + c.SupplierPromotion));
 }