Пример #1
0
        public async Task <HttpResponseMessage> GetBranches()
        {
            var entities = await branchListLoader.LoadAllAsync(
                orderBy : Utilities.GetOrderBy <Branch>("Name", "asc"));

            if (entities.ReturnStatus == false)
            {
                return(CreateErrorResponse(entities));
            }

            var mapper = GetMapper();
            var result = mapper.Map <List <Branch>, List <BranchViewModel> >(entities.ResultValue);

            return(CreateSuccessedListResponse(result));
        }
Пример #2
0
        private async Task ReloadNotCompleteDataAsync(ExternalData externalData)
        {
            //get the list of month and year which those saved in BranchReceipt table.
            var lstMonthYear = await businessService.LoadMonthYearListAsync();

            if (!lstMonthYear.ReturnStatus)
            {
                logger.exError(serviceName, lstMonthYear.ReturnMessage.ConcatAll());
                return;
            }

            //specify the range data for reloading
            NotCompleteRecord notCompleteRecord = await SetNotCompleteRangeTime(
                lstMonthYear.ResultValue.Select(x => new YearMonth()
            {
                Month = x.Month, Year = x.Year
            }).ToList());


            if (notCompleteRecord.ExistAnyRecord)
            {
                //DoLogServiceStarted();

                //load the members records to mapping data
                var lstMembers = await memberListLoader.LoadAllAsync();

                if (!lstMembers.ReturnStatus)
                {
                    logger.exError(serviceName, lstMembers.ReturnMessage.ConcatAll());
                    return;
                }

                //call web service
                var lstEliteData = await ServiceWrapper.Instance.LoadMemberReceiptsAsync(externalData.Year
                                                                                         , externalData.Month
                                                                                         , lstMembers.ResultValue);

                //compare & mapping the exist and just loaded data
                var lstExistData = await businessService.LoadListAsync(externalData.Year, externalData.Month);

                if (!lstExistData.ReturnStatus)
                {
                    logger.exError(serviceName, lstExistData.ReturnMessage.ConcatAll());
                    return;
                }

                var lstNewData = new List <MemberReceipt>();

                //seperation the new data
                lstEliteData
                .Where(x => lstMembers.ResultValue.Any(y => y.RefId == x.MemberRefId))
                .ToList()
                .ForEach(x =>
                {
                    if (!lstExistData.ResultValue.Any(y => y.MemberRefId == x.MemberRefId))
                    {
                        lstNewData.Add(x);
                    }
                });

                //checking the new data with the branch data
                lstEliteData
                .Where(x => !lstMembers.ResultValue.Any(y => y.RefId == x.MemberRefId))
                .Select(x => x.MemberRefId)
                .Distinct()
                .ToList()
                .ForEach(x =>
                {
                    logger.exError(serviceName, "there isn't any member with following data : MemberRefId={0}--Year={1}--Month={2}"
                                   , x, externalData.Year, externalData.Month);
                });


                //insert batch data
                var newDataInserted = await businessService.AddBatchAsync(lstNewData);

                //check result of the inserted data
                if (newDataInserted.ReturnStatus)
                {
                    DoLogInsertedData(lstEliteData.Count, newDataInserted.ResultValue);
                }
                else
                {
                    logger.exError(serviceName, newDataInserted.ReturnMessage.ConcatAll());
                }

                //insert/update data sync status
                await RecordDataSyncStatusAsync(newDataInserted.ResultValue, lstEliteData.Count, notCompleteRecord.DataSyncStatus);

                //DoLogServiceCompleted();
            }
            else
            {
                DoLogNotDataForReloading();
            }
        }