Esempio n. 1
0
        private string GenerateActualDescription(Models.Dto.Collateral.Collateral collateral)
        {
            StringBuilder res = new StringBuilder();

            switch (collateral.Type.Name)
            {
            case "COMMERCIAL":
            case "HOME":
            case "LAND":
                var t = (Mortgage)collateral;

                res.Append(t.Region?.Name)
                .Append(", ").Append(t.District?.Name)
                .Append(", ").Append(t.SettlementType?.Name)
                .Append(", ").Append(t.Settlement?.Name)
                .Append(", ").Append(t.Street)
                .Append(", ").Append(t.House)
                .Append(", ").Append(t.Apartment)
                .Append("; общая площадь: = ").Append(t.TotalArea);

                break;

            case "FLAT":
                var f = (Mortgage)collateral;
                res.Append(f.Region?.Name)
                .Append(", ").Append(f.District?.Name)
                .Append(", ").Append(f.SettlementType?.Name)
                .Append(", ").Append(f.Settlement?.Name)
                .Append(", ").Append(f.Street)
                .Append(", ").Append(f.House)
                .Append(", ").Append(f.Apartment)
                .Append("; кол-во комнат: = ").Append(f.NumberOfRooms)
                .Append("; общая площадь: = ").Append(f.TotalArea);

                break;

            case "AUTO":
                var a = (Car)collateral;
                res.Append(a.Brand?.Name)
                .Append(" ").Append(a.Model?.Name)
                .Append("; гос. номер: ").Append(a.StateNumber)
                .Append("; номер кузова: ").Append(a.VinCode)
                .Append("; Год выпуска: ").Append(a.YearIssue);

                break;

            case "OTHER":
                var o = (OtherCollateral)collateral;
                res.Append(o.Specification);

                break;
            }

            return(res.ToString());
        }
Esempio n. 2
0
        private Collateral PrepareNewCollateral(Models.Dto.Collateral.Collateral collateral)
        {
            Entities.Models.Collateral newCollateral = new Collateral();
            collateral.Id = newCollateral.Id;
            collateral.ActualDescription = GenerateActualDescription(collateral);
            collateral.EntryDate         = DateTime.UtcNow;

            newCollateral.ObjectState = Repository.Pattern.Infrastructure.ObjectState.Added;
            newCollateral.Body        = collateral;

            SetHistory(newCollateral, collateral);

            return(newCollateral);
        }
Esempio n. 3
0
        //public async Task<string> PostEvaluationAsync(string id, Models.Dto.Collateral.Evaluation evaluation)
        //{
        //    var dbCollateral = await _repository.FindAsync(id);
        //    if (dbCollateral == null)
        //        throw new KeyNotFoundException(string.Format("There is no collateral with specified id {0}", id));

        //    var evaluationHistory = evaluation;  // new { EvaluationHistory = new List<Models.Dto.Collateral.Evaluation>() { evaluation } };
        //    var evaluationItem = new
        //    {
        //        Evaluation = new Models.Dto.Collateral.Evaluation
        //        {
        //            Date = evaluation.Date,
        //            DateEntry = evaluation.DateEntry,
        //            Responsible = evaluation.Responsible,
        //            Source = evaluation.Source,
        //            Type = evaluation.Type,
        //            Value = evaluation.Value
        //        }
        //    };

        //    SetEvaluationHistory(dbCollateral, evaluationHistory);

        //    Models.Dto.Collateral.Collateral evalBodyOld = dbCollateral;
        //    if (evalBodyOld.Evaluation == null)
        //    {
        //        dbCollateral.Body = MergeJObject(dbCollateral.Body, evaluationItem);
        //    }
        //    else if (evaluationItem.Evaluation.Date > evalBodyOld.Evaluation.Date)
        //    {
        //        dbCollateral.Body = MergeJObject(dbCollateral.Body, evaluationItem);
        //    }

        //    _repository.Update(dbCollateral);

        //    return evaluation.Id;
        //}
        #endregion

        public async Task <string> PostEvaluationAsync(string id, Models.Dto.Collateral.Evaluation evaluation)
        {
            var dbCollateral = await _repository.FindAsync(id);

            if (dbCollateral == null)
            {
                throw new KeyNotFoundException(string.Format("There is no collateral with specified id {0}", id));
            }

            var evaluationHistory = new { EvaluationHistory = new List <Models.Dto.Collateral.Evaluation>()
                                          {
                                              evaluation
                                          } };
            var evaluationItem = new
            {
                Evaluation = new Models.Dto.Collateral.Evaluation
                {
                    Date        = evaluation.Date,
                    DateEntry   = evaluation.DateEntry,
                    Responsible = evaluation.Responsible,
                    Source      = evaluation.Source,
                    Type        = evaluation.Type,
                    Value       = evaluation.Value
                }
            };

            SetHistory(dbCollateral, evaluationHistory);

            Models.Dto.Collateral.Collateral evalBodyOld = dbCollateral;

            if (evalBodyOld.Evaluation == null)
            {
                dbCollateral.Body = MergeJObject(dbCollateral.Body, evaluationItem);
            }
            else if (evaluationItem.Evaluation.Date > evalBodyOld.Evaluation.Date || evaluationItem.Evaluation.Date == evalBodyOld.Evaluation.Date)
            {
                dbCollateral.Body = MergeJObject(dbCollateral.Body, evaluationItem);
            }

            dbCollateral.Body = MergeJObject(dbCollateral.Body, evaluationHistory);

            _repository.Update(dbCollateral);

            return(evaluation.Id);
        }
Esempio n. 4
0
        public async Task PutCollateralAsync(Models.Dto.Collateral.Collateral collateral)
        {
            var dbCollateral = await _repository.FindAsync(collateral.Id);

            if (dbCollateral == null)
            {
                throw new KeyNotFoundException(string.Format("There is no collateral with specified id {0}", collateral.Id));
            }

            collateral.ActualDescription = GenerateActualDescription(collateral);
            collateral.ModifyDate        = DateTime.UtcNow;

            var diffs = GetJsonDiff(dbCollateral.Body, collateral);

            SetHistory(dbCollateral, diffs);

            dbCollateral.Body = MergeJObject(dbCollateral.Body, collateral);

            _repository.Update(dbCollateral);
        }
Esempio n. 5
0
        public async Task <string> PostCollateralToCreditagreementAsync(string creditAgreementId, Models.Dto.Collateral.Collateral collateral)
        {
            var newCollateral = PrepareNewCollateral(collateral);

            CreditAgreement creditagreement = new CreditAgreement {
                Id = creditAgreementId
            };

            newCollateral.CreditAgreements = new List <CreditAgreement>()
            {
                creditagreement
            };

            _repository.Insert(newCollateral);

            return(newCollateral.Id);
        }