Example #1
0
        private Task ThirdBatch(List <OracleCost> list)
        {
            var groupedOracleCostList = list
                                        .GroupBy(q => q.QuoteNumber, (quoteNumber, quoteRevenues) => new
            {
                key   = quoteNumber,
                value = quoteRevenues
            });

            using (TransactionScope scope = new TransactionScope())
            {
                foreach (var group in groupedOracleCostList)
                {
                    string  quoteNumber = group.key.Trim();
                    Project dbProject   = _projectRepository.GetBy(p => p.QuoteNumber == quoteNumber).FirstOrDefault();
                    new ExcelImportOrderIncorrectExceptionTriger(dbProject);
                    Income[] incomes = BindHelper.GetIncomes(group.value.ToArray(), dbProject.Id);

                    //根据kickoff的年月和币种得到汇率
                    string yearmonth          = dbProject.GetYearAndMonthString();
                    List <ExchangeRate> rates = _exchangeRateRepository.GetBy(r => r.YearMonthDate == yearmonth).ToList();
                    if (rates.Count == 0)
                    {
                        throw new Exception("请先上传当月的Exchange rate");
                    }
                    else
                    {
                        float finalCost = 0, different = 0;
                        foreach (var income in incomes)
                        {
                            ExchangeRate rate = rates.FirstOrDefault(r => r.Currency == income.OracleCurrency);
                            if (rate == null)
                            {
                                throw new ExchangeRateMissingException(yearmonth, income.OracleCurrency);
                            }
                            finalCost         += income.CostAmount / rate.Rate;
                            income.ExchageRate = rate.Rate;
                            income.Format();
                        }

                        OracleCost one = group.value.First();
                        different                   = finalCost - dbProject.TotalBooking;
                        dbProject.FinalCost         = finalCost;
                        dbProject.different         = different;
                        dbProject.Status            = one.Status;
                        dbProject.ProjectClosedDate = one.ProjectClosedDate;
                        dbProject.Format();
                        _incomeRepository.BatchAdd(incomes);
                        _projectRepository.Update(dbProject);
                    }
                }
                _projectRepository.Save();
                scope.Complete();
            }
            return(Task.CompletedTask);
        }
        // Manager in charge of get a ExchangeRate by ID.
        public async Task <ExchangeRateModel> GetExchangeRateById(int id)
        {
            var exchangeRateFound = await _exchangeRateRepository.GetBy(id);

            return(_mapper.Map <ExchangeRate, ExchangeRateModel>(exchangeRateFound));
        }