Example #1
0
        public async Task <List <BranchReceipt> > LoadBranchReceiptsAsync(int year, int month, List <Branch> lstBranches)
        {
            var result          = new List <BranchReceipt>();
            var externalService = ExternalServices.BranchReceipts;

            BranchReceiptInfo[]  serviceDataInfos = null;
            List <BranchReceipt> lstBranchReceipt = new List <BranchReceipt>();

            if (lstBranches.Count == 0)
            {
                logger.Warn(externalService, "There isn't any branch");
            }

            foreach (var item in lstBranches)
            {
                try
                {
                    serviceDataInfos = await eliteClient.GetBranchReceiptsAsync(userName, password, year, month, item.RefId);

                    lstBranchReceipt = mapper.Map <BranchReceiptInfo[], List <BranchReceipt> >(serviceDataInfos);
                    lstBranchReceipt.ForEach(x =>
                    {
                        x.BranchId  = item.Id;
                        x.Year      = year;
                        x.Month     = month;
                        x.StartDate = Utilities.ToDateTime(year, month);
                        x.EndDate   = Utilities.ToDateTime(year, month, ToDateTimeOptions.EndMonth);
                    });

                    result.AddRange(lstBranchReceipt);
                }
                catch (Exception ex)
                {
                    logger.Error(externalService, ex, "An error happened at the loading branch's receipts,branchid is {0}", item.RefId);
                }
            }
            return(result);
        }