public void Test_CreateSettlementTransfer()
        {
            DisputeDTO dispute = _clientDisputes.FirstOrDefault(x => x.Status == DisputeStatus.CLOSED && x.DisputeType == DisputeType.NOT_CONTESTABLE);

            RepudiationDTO repudiation = null;
            SettlementDTO  result      = null;

            if (dispute == null)
            {
                Assert.Fail("Cannot test creating settlement transfer because there's no closed disputes in the disputes list.");
            }

            try
            {
                string repudiationId = Api.Disputes.GetTransactions(dispute.Id, new Pagination(1, 1), null)[0].Id;

                repudiation = Api.Disputes.GetRepudiation(repudiationId);

                SettlementTransferPostDTO post = new SettlementTransferPostDTO(repudiation.AuthorId, new Money {
                    Currency = CurrencyIso.EUR, Amount = 1
                }, new Money {
                    Currency = CurrencyIso.EUR, Amount = 0
                });

                result = Api.Disputes.CreateSettlementTransfer(post, repudiationId);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }

            Assert.IsNotNull(result);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Node> > PutSettlement(string te, Node node)
        {
            if (node == null || te != node.Te)
            {
                return(BadRequest($"Failed to update operation."));
            }
            SettlementDTO settlementDTO = new SettlementDTO
            {
                Te = node.Te,
                Nu = node.Nu,
                Np = node.Np
            };

            try
            {
                await _directoryService.UpdateAsync(settlementDTO);
            }
            catch (Exception ex)
            {
                bool isExists = await SettlementExistsAsync(te);

                if (!isExists)
                {
                    return(NotFound($"Failed to update unexisted node with TE={te}."));
                }
                else
                {
                    throw;
                }
            }
            //return NoContent();
            return(Ok(node));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <Node> > PostSettlement(Node node)
        {
            if (node == null)
            {
                return(BadRequest("Failed to create empty node."));
            }
            SettlementDTO settlementDTO = new SettlementDTO
            {
                Te = node.Te,
                Nu = node.Nu,
                Np = node.Np
            };

            try
            {
                await _directoryService.CreateAsync(settlementDTO);
            }
            catch (Exception ex)
            {
                bool isExists = await SettlementExistsAsync(settlementDTO.Te);

                if (isExists)
                {
                    return(Conflict($"Failed to create node with existed TE={node.Te}."));
                }
                else
                {
                    return(BadRequest($"Failed to create node with TE={node.Te}."));
                }
            }

            return(Ok(node));
        }
Ejemplo n.º 4
0
        public ActionResult CreateSettlement([Bind("Id", "Balance")] SettlementDTO settlementDTO)
        {
            try
            {
                BBSettlement newSettlement = new BBSettlement();
                if (settlementDTO != null)
                {
                    newSettlement = new BBSettlement
                    {
                        Id          = settlementDTO.Id,
                        Balance     = settlementDTO.Balance,
                        EntityState = EntityState.Added
                    };

                    _businessLayer.AddBBSettlement(newSettlement);
                }
                return(Ok(newSettlement));
            }

            catch (Exception ex)
            {
                //return new JsonResult(new { HttpStatusCode = NotFound(HttpStatusCode.BadRequest), ex.Message });
                throw new Exception(ex.Message);
            }
        }
Ejemplo n.º 5
0
        public Settlement FromDTO(SettlementDTO dto)
        {
            var buildings = _buildingDictMapper.FromDTO(dto.Buildings);

            return(new Settlement(
                       dto.Id,
                       dto.Population,
                       dto.RawResources,
                       buildings));
        }
Ejemplo n.º 6
0
        public OktmoDtoTests()
        {
            var xCity = new CityDTO {Name = "Москва", Type = "город"};
            var yCity = new CityDTO {Name = "Спб", Type = "город"};

            var xSet = new SettlementDTO();

            x = new OktmoRowDTO{Subject = "Москва",Region = "город Москва",City =xCity,Settlement = xSet};
            y = new OktmoRowDTO{Subject = "Спб",Region = "город Спб",City =yCity,Settlement = xSet};
            z = new OktmoRowDTO{Subject = "Москва",Region = "город Москва",City =xCity,Settlement = xSet};
        }
Ejemplo n.º 7
0
        public async Task Test_GetSettlementTransfer()
        {
            DisputeDTO dispute = _clientDisputes.FirstOrDefault(x => x.Status == DisputeStatus.CLOSED && x.DisputeType.HasValue && x.DisputeType.Value == DisputeType.NOT_CONTESTABLE);

            RepudiationDTO repudiation = null;
            SettlementDTO  transfer    = null;

            if (dispute == null)
            {
                Assert.Fail("Cannot test getting settlement transfer because there's no closed and not contestable disputes in the disputes list.");
            }

            try
            {
                var temp = await Api.Disputes.GetTransactions(dispute.Id, new Pagination(1, 1), null);

                string repudiationId = temp[0].Id;

                repudiation = await Api.Disputes.GetRepudiation(repudiationId);

                SettlementTransferPostDTO post = new SettlementTransferPostDTO(repudiation.AuthorId, new Money {
                    Currency = CurrencyIso.EUR, Amount = 1
                }, new Money {
                    Currency = CurrencyIso.EUR, Amount = 0
                });

                transfer = await Api.Disputes.CreateSettlementTransfer(post, repudiationId);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }

            Assert.IsNotNull(transfer);


            SettlementDTO result = null;

            try
            {
                result = await Api.Disputes.GetSettlementTransfer(transfer.Id);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }

            Assert.IsNotNull(result);
            Assert.IsInstanceOf <SettlementDTO>(result);
            Assert.IsNotNull(result.RepudiationId);
            Assert.AreEqual(result.RepudiationId, repudiation.Id);
        }
Ejemplo n.º 8
0
        public async Task UpdateAsync(SettlementDTO node)
        {
            Settlement settlement = await Manager.Settlements.GetAsync(node.Te);

            settlement.Nu = node.Nu;
            settlement.Np = node.Np;
            try
            {
                await Manager.Settlements.UpdateAsync(settlement);
            }
            catch (Exception ex)
            {
                throw new ValidationException($"Failed to update node with TE={node.Te}." + ex.Message, node.Te);
            }
        }
Ejemplo n.º 9
0
        public async Task CreateAsync(SettlementDTO node)
        {
            Settlement settlement = new Settlement
            {
                Te = node.Te,
                Np = node.Np,
                Nu = node.Nu
            };

            try
            {
                await Manager.Settlements.CreateAsync(settlement);
            }
            catch (Exception ex)
            {
                throw new ValidationException($"Failed to create a settlement with TE={node.Te}", node.Te);
            }
        }
Ejemplo n.º 10
0
 public bool IsTrue(SettlementDTO settlementDTO, IFilterOptions filterOptions)
 {
     if (string.IsNullOrWhiteSpace(filterOptions.Name) != true &&
         settlementDTO.Nu.Contains(filterOptions.Name) == false)
     {
         return(false);
     }
     if (string.IsNullOrWhiteSpace(filterOptions.SettlementType) != true)
     {
         if (string.IsNullOrWhiteSpace(settlementDTO.Np) == true)
         {
             return(false);
         }
         if (settlementDTO.Np.Contains(filterOptions.SettlementType) == false)
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 11
0
        public async Task <ActionResult <Node> > DeleteSettlement(string te, bool cascade)
        {
            SettlementDTO settlementDTO = await _directoryService.GetAsync(te);

            if (settlementDTO == null)
            {
                return(NotFound($"Failed to delete unexisted node with TE={te}."));
            }
            try
            {
                await _directoryService.DeleteAsync(te, cascade);
            }
            catch (Exception ex)
            {
                return(BadRequest($"Failed to delete node with TE={te}."));
            }

            Node node = _mapper.Map <Node>(settlementDTO);

            return(Ok(node));
        }
Ejemplo n.º 12
0
 public OktmoRowDTO()
 {
     Settlement = new SettlementDTO();
     City = new CityDTO();
 }