示例#1
0
        /// <summary>
        /// UPDATE Evaluation в Collateral - из EvaluationHistory берем последнее значение и пишем в поле Evaluation из БД
        /// </summary>
        /// <param name="collateralId"></param>
        /// <returns></returns>
        public static string PostEvaluationToCollateral(string collateralId)
        {
            var    collateral = _service.Collateral.GetCollateralByCollateralId(collateralId);
            var    answer     = Mapper.Map <CollateralService.ApiClient.Client.Models.Presentation.Responses.Collateral.Collateral, Models.Collateral>(collateral);
            string evalId     = string.Empty;

            if (answer.EvaluationHistory.Count() > 0)
            {
                evaluation = answer.EvaluationHistory.ToList().OrderByDescending(x => x.Date).FirstOrDefault();
                var evaluationItem = Mapper.Map <Models.Evaluation, CollateralService.ApiClient.Client.Models.Presentation.Requests.Collateral.Evaluation>(evaluation);

                evalId = _service.Collateral.PostEvaluation(answer.Id, evaluationItem);
            }
            Console.WriteLine(evalId);
            return(evalId);
        }
示例#2
0
        /// <summary>
        /// Update Evaluation to Collateral из *.csv файла
        /// </summary>
        /// <param name="collateralId"></param>
        /// <returns></returns>
        public static void UpdateEvaluationToCollateral()
        {
            string pathUpdateEvaluation = ConfigurationManager.AppSettings["PathUpdateEvaluation"];
            int    count = 0;

            try
            {
                using (StreamReader reader = File.OpenText(pathUpdateEvaluation))
                {
                    var csv = new CsvReader(reader);
                    csv.Configuration.Delimiter = ";";
                    csv.Configuration.Encoding  = Encoding.UTF8;
                    csv.Configuration.RegisterClassMap(new CollateralMap());
                    var collateral = csv.GetRecords <CollateralAgreementId>().Where(i => !string.IsNullOrEmpty(i.CollateralId)).ToList();

                    Parallel.ForEach(collateral, new ParallelOptions {
                        MaxDegreeOfParallelism = 10
                    }, item =>
                    {
                        var baseCollateral = _service.Collateral.GetCollateralByCollateralId(item.CollateralId);
                        var answer         = Mapper.Map <CollateralService.ApiClient.Client.Models.Presentation.Responses.Collateral.Collateral, Models.Collateral>(baseCollateral);

                        if (answer.EvaluationHistory.Count() > 0)
                        {
                            evaluation         = answer.EvaluationHistory.ToList().OrderByDescending(x => x.Date).OrderByDescending(x => x.DateEntry).FirstOrDefault();
                            var evaluationItem = Mapper.Map <Models.Evaluation, CollateralService.ApiClient.Client.Models.Presentation.Requests.Collateral.Evaluation>(evaluation);

                            var response = _service.Collateral.PostEvaluation(answer.Id, evaluationItem);
                            count++;
                            Console.WriteLine("Id: {0} | Update Evaluation Successful | current: {1} ", answer.Id, count);
                        }
                    }
                                     );
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine("{0} Evaluation Collateral have been updated", count);
        }