Exemple #1
0
        public void GetBrokerInvestmentsInitDataExpiredOrFuture()
        {
            var manager1 = new ManagerAccounts
            {
                Id = Guid.NewGuid(),
                BrokerTradeServerId = brokerTradeServer.Id
            };
            var inv1 = new InvestmentPrograms
            {
                Id               = Guid.NewGuid(),
                IsEnabled        = true,
                DateFrom         = DateTime.UtcNow.AddDays(-10),
                DateTo           = DateTime.UtcNow.AddDays(-3),
                ManagerAccountId = manager1.Id,
                Token            = new ManagerTokens
                {
                    Id          = Guid.NewGuid(),
                    TokenName   = "TokenName1",
                    TokenSymbol = "TokenSymbol1"
                }
            };
            var manager2 = new ManagerAccounts
            {
                Id = Guid.NewGuid(),
                BrokerTradeServerId = brokerTradeServer.Id
            };
            var inv2 = new InvestmentPrograms
            {
                Id               = Guid.NewGuid(),
                IsEnabled        = true,
                DateFrom         = DateTime.UtcNow.AddDays(10),
                DateTo           = DateTime.UtcNow.AddDays(17),
                ManagerAccountId = manager2.Id,
                Token            = new ManagerTokens
                {
                    Id          = Guid.NewGuid(),
                    TokenName   = "TokenName2",
                    TokenSymbol = "TokenSymbol2"
                }
            };

            context.Add(manager1);
            context.Add(manager2);
            context.Add(inv1);
            context.Add(inv2);
            context.SaveChanges();

            var result = trustManagementService.GetBrokerInvestmentsInitData(brokerTradeServer.Id);

            Assert.IsTrue(result.IsSuccess);
            Assert.AreEqual(0, result.Data.Count);

            inv1.DateTo   = DateTime.UtcNow.AddMinutes(1);
            inv2.DateFrom = DateTime.UtcNow.AddMinutes(-1);
            context.SaveChanges();

            result = trustManagementService.GetBrokerInvestmentsInitData(brokerTradeServer.Id);
            Assert.IsTrue(result.IsSuccess);
            Assert.AreEqual(2, result.Data.Count);
        }
Exemple #2
0
        public IActionResult AddUserToRole(ManagerAccounts model)
        {
            UtilityWorker   utility = new UtilityWorker(roleManager, userManager);
            ApplicationUser user    = userManager.FindByEmailAsync(model.user.Email).Result;

            utility.AddUserToRole(user, model.user.roleName).Wait();
            return(Redirect("UsersAcount"));
        }
Exemple #3
0
        public void Init()
        {
            var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>();

            optionsBuilder.UseInMemoryDatabase("databaseManagerValidator");
            context = new ApplicationDbContext(optionsBuilder.Options);

            applicationUser = new ApplicationUser
            {
                Id        = Guid.NewGuid(),
                IsEnabled = true,
                Type      = UserType.Manager,
                Wallets   = new List <Wallets> {
                    new Wallets {
                        Amount = 10000, Currency = Currency.GVT
                    }
                },
            };
            broker = new BrokersAccounts
            {
                Id               = Guid.NewGuid(),
                UserId           = applicationUser.Id,
                Description      = string.Empty,
                IsEnabled        = true,
                Name             = "Broker #1",
                RegistrationDate = DateTime.UtcNow
            };
            brokerTradeServer = new BrokerTradeServers
            {
                Id               = Guid.NewGuid(),
                Name             = "Server #1",
                IsEnabled        = true,
                Host             = string.Empty,
                RegistrationDate = DateTime.UtcNow,
                Type             = BrokerTradeServerType.MetaTrader4,
                BrokerId         = broker.Id
            };
            managerAccount = new ManagerAccounts
            {
                Id = Guid.NewGuid(),
                BrokerTradeServerId = brokerTradeServer.Id,
                Currency            = Currency.USD,
                Login            = "******",
                RegistrationDate = DateTime.UtcNow,
                UserId           = applicationUser.Id,
                IsConfirmed      = true
            };

            context.Add(applicationUser);
            context.Add(broker);
            context.Add(brokerTradeServer);
            context.Add(managerAccount);
            context.SaveChanges();

            managerValidator = new ManagerValidator(context);
        }
Exemple #4
0
        public IActionResult UsersAcount()
        {
            ViewData["Title"] = "";
            UtilityWorker uWorker = new UtilityWorker(roleManager, userManager);

            uWorker.AddNewRoleAsync("admin").Wait();
            uWorker.AddNewRoleAsync("regular").Wait();
            ManagerAccounts mua = new ManagerAccounts();

            mua.AppRoles                = uWorker.getRoles();
            mua.AppUserEmails           = uWorker.getAppUsers();
            mua.getRolesForDropDownList = uWorker.getRolesForDropDownList();
            uWorker.initializedAllUsers(mua);
            return(View(mua));
        }
Exemple #5
0
        public void GetBrokerInvestmentsInitData()
        {
            var manager1 = new ManagerAccounts
            {
                Id = Guid.NewGuid(),
                BrokerTradeServerId = brokerTradeServer.Id
            };
            var inv1 = new InvestmentPrograms
            {
                Id               = Guid.NewGuid(),
                IsEnabled        = true,
                DateFrom         = DateTime.UtcNow.AddDays(-1),
                DateTo           = DateTime.UtcNow.AddDays(1),
                Period           = 5,
                ManagerAccountId = manager1.Id,
                Description      = "#1",
                Token            = new ManagerTokens
                {
                    TokenName   = "TokenName1",
                    TokenSymbol = "TokenSymbol1"
                }
            };
            var period1 = new Periods
            {
                Id = Guid.NewGuid(),
                InvestmentProgramId = inv1.Id,
                Status = PeriodStatus.InProccess,
                Number = 5
            };
            var period2 = new Periods
            {
                Id = Guid.NewGuid(),
                InvestmentProgramId = inv1.Id,
                Status = PeriodStatus.Planned,
                Number = 6
            };
            var manager2 = new ManagerAccounts
            {
                Id = Guid.NewGuid(),
                BrokerTradeServerId = brokerTradeServer.Id
            };
            var inv2 = new InvestmentPrograms
            {
                Id               = Guid.NewGuid(),
                IsEnabled        = true,
                DateFrom         = DateTime.UtcNow.AddDays(-1),
                DateTo           = DateTime.UtcNow.AddDays(1),
                Period           = 7,
                ManagerAccountId = manager2.Id,
                Description      = "#2",
                Token            = new ManagerTokens
                {
                    TokenName    = "TokenName2",
                    TokenSymbol  = "TokenSymbol2",
                    TokenAddress = "TokenAddress2",
                }
            };

            context.Add(manager1);
            context.Add(inv1);
            context.Add(period1);
            context.Add(period2);
            context.Add(manager2);
            context.Add(inv2);
            context.SaveChanges();

            var result = trustManagementService.GetBrokerInvestmentsInitData(brokerTradeServer.Id);

            Assert.IsTrue(result.IsSuccess);
            Assert.AreEqual(2, result.Data.Count);
            Assert.AreEqual(inv1.Description, result.Data.First(x => x.Id == inv1.Id).Description);
            Assert.AreEqual(inv1.DateFrom, result.Data.First(x => x.Id == inv1.Id).DateFrom);
            Assert.IsNotNull(result.Data.First(x => x.Id == inv1.Id).LastPeriod);
            Assert.AreEqual(period1.Id, result.Data.First(x => x.Id == inv1.Id).LastPeriod.Id);
            Assert.AreEqual(period1.Number, result.Data.First(x => x.Id == inv1.Id).LastPeriod.Number);
            Assert.AreEqual(period1.Status, result.Data.First(x => x.Id == inv1.Id).LastPeriod.Status);
            Assert.AreEqual(inv2.Period, result.Data.First(x => x.Id == inv2.Id).Period);
            Assert.AreEqual(inv2.DateTo, result.Data.First(x => x.Id == inv2.Id).DateTo);
            Assert.AreEqual(inv2.ManagerAccount.Login, result.Data.First(x => x.Id == inv2.Id).Login);
            Assert.AreEqual(inv1.ManagerAccount.IpfsHash, result.Data.First(x => x.Id == inv1.Id).IpfsHash);
        }
Exemple #6
0
        public void Init()
        {
            var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>();

            optionsBuilder.UseInMemoryDatabase("databaseTrustManagementService");
            context = new ApplicationDbContext(optionsBuilder.Options);

            user = new ApplicationUser
            {
                Id        = Guid.NewGuid(),
                IsEnabled = true,
                Wallets   = new List <Wallets> {
                    new Wallets {
                        Amount = 100000, Currency = Currency.GVT
                    }
                },
            };
            managerAccount = new ManagerAccounts
            {
                Id          = Guid.NewGuid(),
                IsConfirmed = true,
                UserId      = user.Id
            };
            investmentProgram = new InvestmentPrograms
            {
                Id               = Guid.NewGuid(),
                DateFrom         = DateTime.UtcNow.AddYears(-1),
                FeeEntrance      = 100m,
                FeeSuccess       = 120m,
                FeeManagement    = 10m,
                Description      = "Test inv",
                IsEnabled        = true,
                Period           = 10,
                InvestMinAmount  = 500,
                InvestMaxAmount  = 1500,
                ManagerAccountId = managerAccount.Id,
                Token            = new ManagerTokens
                {
                    TokenName   = "Token",
                    TokenSymbol = "TST"
                }
            };
            broker = new BrokersAccounts
            {
                Id               = Guid.NewGuid(),
                UserId           = user.Id,
                Description      = string.Empty,
                IsEnabled        = true,
                Name             = "Broker #1",
                RegistrationDate = DateTime.UtcNow
            };
            brokerTradeServer = new BrokerTradeServers
            {
                Id               = Guid.NewGuid(),
                Name             = "Server #1",
                IsEnabled        = true,
                Host             = string.Empty,
                RegistrationDate = DateTime.UtcNow,
                Type             = BrokerTradeServerType.MetaTrader4,
                BrokerId         = broker.Id
            };
            context.Add(user);
            context.Add(managerAccount);
            context.Add(investmentProgram);
            context.Add(broker);
            context.Add(brokerTradeServer);
            context.SaveChanges();

            smartContractService = new Mock <ISmartContractService>();
            ipfsService          = new Mock <IIpfsService>();
            statisticService     = new Mock <IStatisticService>();
            rateService          = new Mock <IRateService>();

            trustManagementService = new TrustManagementService(context,
                                                                ipfsService.Object,
                                                                smartContractService.Object,
                                                                statisticService.Object,
                                                                rateService.Object,
                                                                Substitute.For <ILogger <ITrustManagementService> >());
        }
Exemple #7
0
 public static void SetManagerAccount(ManagerAccounts managerAccounts)
 {
     _managerAccount = managerAccounts;
 }
Exemple #8
0
        public OperationResult <Guid> CreateInvestmentProgram(NewManager request)
        {
            return(InvokeOperations.InvokeOperation(() =>
            {
                var managerRequest = context.ManagerRequests.First(x => x.Id == request.RequestId && x.Status == ManagerRequestStatus.Created);
                managerRequest.TradePlatformPassword = null;
                managerRequest.Status = ManagerRequestStatus.Processed;

                var manager = new ManagerAccounts
                {
                    Id = Guid.NewGuid(),
                    BrokerTradeServerId = managerRequest.BrokerTradeServerId,
                    UserId = managerRequest.UserId,
                    RegistrationDate = DateTime.UtcNow,
                    Login = request.Login,
                    Currency = managerRequest.TradePlatformCurrency,
                    IsConfirmed = false,
                    IpfsHash = string.Empty
                };
                var token = new ManagerTokens
                {
                    Id = Guid.NewGuid(),
                    TokenAddress = string.Empty,
                    TokenName = managerRequest.TokenName,
                    TokenSymbol = managerRequest.TokenSymbol,
                    InitialPrice = 1,
                    FreeTokens = 1000
                };
                var inv = new InvestmentPrograms
                {
                    Id = Guid.NewGuid(),
                    DateFrom = managerRequest.DateFrom,
                    DateTo = managerRequest.DateTo,
                    Description = managerRequest.Description,
                    Title = managerRequest.Title,
                    FeeEntrance = managerRequest.FeeEntrance,
                    FeeManagement = managerRequest.FeeManagement,
                    FeeSuccess = managerRequest.FeeSuccess,
                    InvestMaxAmount = managerRequest.InvestMaxAmount,
                    InvestMinAmount = managerRequest.InvestMinAmount,
                    IsEnabled = true,
                    ManagerAccountId = manager.Id,
                    Period = managerRequest.Period,
                    ManagerTokenId = token.Id,
                    Logo = managerRequest.Logo,
                    Rating = 0,
                };
                var firstPeriod = new Periods
                {
                    Id = Guid.NewGuid(),
                    DateFrom = inv.DateFrom,
                    DateTo = Constants.IsPeriodInMinutes
                                          ? inv.DateFrom.AddMinutes(inv.Period)
                                          : inv.DateFrom.AddDays(inv.Period),
                    Status = PeriodStatus.InProccess,
                    InvestmentProgramId = inv.Id,
                    Number = 1,
                    StartBalance = managerRequest.DepositInUsd,
                    ManagerStartBalance = managerRequest.DepositInUsd,
                    ManagerStartShare = 1
                };
                if (!inv.DateTo.HasValue || inv.DateTo > inv.DateFrom.AddDays(inv.Period))
                {
                    var plannedPeriod = new Periods
                    {
                        Id = Guid.NewGuid(),
                        DateFrom = firstPeriod.DateTo,
                        DateTo = Constants.IsPeriodInMinutes
                                                ? firstPeriod.DateTo.AddMinutes(inv.Period)
                                                : firstPeriod.DateTo.AddDays(inv.Period),
                        Status = PeriodStatus.Planned,
                        InvestmentProgramId = inv.Id,
                        Number = 2
                    };
                    context.Add(plannedPeriod);
                }

                context.Add(manager);
                context.Add(token);
                context.Add(inv);
                context.Add(firstPeriod);
                context.SaveChanges();

                var blockchainUpdate = smartContractService.RegisterManager(token.TokenName, token.TokenSymbol,
                                                                            manager.Id.ToString(), manager.Login,
                                                                            manager.BrokerTradeServerId.ToString(), inv.FeeManagement, inv.FeeSuccess);

                if (blockchainUpdate.IsSuccess)
                {
                    manager.IsConfirmed = true;
                    context.SaveChanges();

                    var ipfsUpdate = UpdateInvestmentInIpfs(inv.Id);
                    if (ipfsUpdate.IsSuccess)
                    {
                        manager.IpfsHash = ipfsUpdate.Data;
                        context.SaveChanges();
                    }
                }

                return manager.Id;
            }));
        }