Example #1
0
        public async Task <List <Invoice> > LoadInvoicesAsync(int year, int month, List <Goods> lstGoods, List <Member> lstMembers)
        {
            List <Invoice> result = new List <Invoice>();

            InvoiceInfo[] serviceDataInfos = await eliteClient.GetInvoicesAsync(userName, password, year, month);

            if (serviceDataInfos != null)
            {
                result = mapper.Map <InvoiceInfo[], List <Invoice> >(serviceDataInfos);
                Member sellerInfo = null;
                Goods  goodsInfo  = null;
                result.ForEach(x =>
                {
                    sellerInfo = lstMembers.FirstOrDefault(y => y.RefId == x.SellerRefId);
                    if (sellerInfo != null)
                    {
                        x.SellerId = sellerInfo.Id;
                    }
                    else
                    {
                        logger.Warn(ExternalServices.Invoice, $"Couldn't be found seller with Id: {x.SellerRefId}");
                    }

                    goodsInfo = lstGoods.FirstOrDefault(y => y.RefId == x.GoodsRefId);
                    if (goodsInfo != null)
                    {
                        x.GoodsId = goodsInfo.Id;
                    }
                    else
                    {
                        logger.Warn(ExternalServices.Invoice, $"Couldn't be found goods with Id: {x.GoodsRefId}");
                    }

                    x.Year      = year;
                    x.Month     = month;
                    x.StartDate = Utilities.ToDateTime(year, month);
                    x.EndDate   = Utilities.ToDateTime(year, month, ToDateTimeOptions.EndMonth);
                });
            }
            return(result);
        }