Esempio n. 1
0
 protected void AuctionGrid1_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         PortfolioShare share = new PortfolioShare(Convert.ToInt32(e.Row.Cells[0].Text));
         e.Row.Cells[1].Text = share.Product.Name;
         e.Row.Cells[2].Text = share.Shares.ToString();
         e.Row.Cells[3].Text = ((Decimal)share.Shares * 100 / (Decimal)share.Product.TotalShares).ToString("F4") + "%";
     }
 }
Esempio n. 2
0
        public IActionResult PayShare(int ShareId, int UserId)
        {
            if (ShareId == 0 || UserId == 0)
            {
                return(BadRequest());
            }
            var comment = "";

            using (var db = new BrokerContext())
            {
                var user      = db.Users.FirstOrDefault(x => x.Id == UserId);
                var share     = db.Shares.FirstOrDefault(x => x.Id == ShareId);
                var portfolio = db.Portfolios.FirstOrDefault(x => x.UserId == UserId);
                if (user != null)
                {
                    if (portfolio == null)
                    {
                        var newPortfolio = new Portfolio()
                        {
                            UserId = user.Id
                        };
                        db.Portfolios.Add(newPortfolio);
                        db.SaveChanges();
                        portfolio = db.Portfolios.FirstOrDefault(x => x.UserId == user.Id);
                    }
                    if (user.Balance < share.CurrentPrice)
                    {
                        comment = "Недостаточно средств";
                    }
                    else
                    {
                        user.Balance -= share.CurrentPrice;
                        var shareAndPortfolio = new PortfolioShare()
                        {
                            BuyPrice = share.CurrentPrice, PortfolioId = portfolio.Id, ShareId = share.Id
                        };
                        db.Users.Update(user);
                        db.PortfolioShares.Add(shareAndPortfolio);
                        db.SaveChanges();
                        comment = $"Операция прошла успешна. Ваш текущий баланс {user.Balance}";
                    }
                }
                else
                {
                    comment = "Произошла ошибка данный пользователь не найден!!!";
                }
            }
            return(Ok(comment));
        }
Esempio n. 3
0
        public static int CreatePortfolioShare(string description)
        {
            using (var scope = ApplicationContext.Container.BeginLifetimeScope())
            {
                using (var context = scope.Resolve <DbContext>())
                {
                    var entity = new PortfolioShare()
                    {
                        Description = description,
                    };

                    context.Add(entity);
                    context.SaveChanges();
                    return(entity.Id);
                }
            }
        }
Esempio n. 4
0
    protected void BidButton_Click(object sender, EventArgs e)
    {
        ErrPanel.Visible = false;
        SucPanel.Visible = false;

        try
        {
            PortfolioShare share = new PortfolioShare(Convert.ToInt32(ddlOptions.SelectedValue));

            if (share.OwnerUsername == Member.CurrentName) //Anti-fraud check
            {
                Money Amount;

                if (!Money.TryParse(Price.Text, out Amount))
                {
                    throw new MsgException(U3500.ILLEGALCHARS);
                }

                int Units = Convert.ToInt32(UnitsBox.Text);

                Amount = Units * Amount;

                //Availability check
                if (Units > SharesMarketManager.GetSharesAvailableForSale(share))
                {
                    throw new MsgException(U4000.NOTENOUGHUNITS);
                }

                //Sell
                SharesMarketManager.AddShareToMarket(share, Units, Amount);

                SucPanel.Visible = true;
                SucMess.Text     = L1.OP_SUCCESS;
            }
        }
        catch (MsgException ex)
        {
            ErrPanel.Visible = true;
            ErrMess.Text     = ex.Message;
        }
        catch (Exception ex)
        {
            ErrorLogger.Log(ex);
        }
    }
Esempio n. 5
0
        internal static void InitializeDataBase()
        {
            using (var scope = ApplicationContext.Container.BeginLifetimeScope("ExecutionPipeline"))
            {
                using (var context = scope.Resolve <DbContext>())
                {
                    //context.Database.EnsureDeleted();

                    if ((context.GetService <IDatabaseCreator>() as RelationalDatabaseCreator).Exists())
                    {
                        return;
                    }

                    context.Database.EnsureDeleted();
                    context.Database.EnsureCreated();
                    //context.Database.Migrate();

                    var organization = new EntityOrganization()
                    {
                        Name = "Default", CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now
                    };

                    var adminRole = new AuthorizationRole()
                    {
                        Id = 1, Name = "Administrator", EntityOrganization = organization
                    };
                    var agentRole = new AuthorizationRole()
                    {
                        Id = 2, Name = "Agent", EntityOrganization = organization
                    };
                    var advisoryRole = new AuthorizationRole()
                    {
                        Id = 3, Name = "Advisor", EntityOrganization = organization
                    };
                    var workflowRole = new AuthorizationRole()
                    {
                        Id = 4, Name = "Workflow", EntityOrganization = organization
                    };

                    var applicationUser = new ApplicationUser()
                    {
                        Name        = "Default", Email = "*****@*****.**",
                        Password    = "******",
                        CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now
                    };
                    var workflowUser = new ApplicationUser()
                    {
                        Name        = "Workflow", Email = "*****@*****.**",
                        Password    = "******",
                        CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now
                    };
                    var schedulerFlowUser = new ApplicationUser()
                    {
                        Name        = "Scheduler", Email = "*****@*****.**",
                        Password    = "******",
                        CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now
                    };

                    var currentAdviser = new CurrentAdvisor()
                    {
                        Id = 1, Description = "Advisor A", EntityOrganization = organization
                    };
                    var gender = new Gender()
                    {
                        Id = 1, Description = "Male", EntityOrganization = organization
                    };
                    var occupation = new Occupation()
                    {
                        Id = 1, Description = "Unemployed", EntityOrganization = organization
                    };
                    var addressType = new AddressType()
                    {
                        Id = 1, Description = "Complex", EntityOrganization = organization
                    };
                    var phoneCallActivityType = new LeadScheduledActivityType()
                    {
                        Id = 1, Description = "Phone Call", EntityOrganization = organization
                    };
                    var meetingActivityType = new LeadScheduledActivityType()
                    {
                        Id = 2, Description = "Meeting", EntityOrganization = organization
                    };

                    var authorizationGroupA = new AuthorizationGroup()
                    {
                        Id = 1, Name = "Group A", EntityOrganization = organization
                    };
                    var authorizationGroupB = new AuthorizationGroup()
                    {
                        Id = 2, Name = "Group B", EntityOrganization = organization
                    };


                    var portfolioTransactionTypeOpen = new PortfolioTransactionType()
                    {
                        Id          = 1,
                        Description = "Open",
                    };

                    var portfolioTransactionTypeClose = new PortfolioTransactionType()
                    {
                        Id          = 2,
                        Description = "Close",
                    };

                    var portfolioShareA = new PortfolioShare()
                    {
                        Description = "ABC short",
                        Code        = "ABC"
                    };
                    var portfolioShareB = new PortfolioShare()
                    {
                        Description = "XYZ short",
                        Code        = "XXZ"
                    };


                    context.Add(portfolioTransactionTypeClose);
                    context.Add(portfolioTransactionTypeOpen);

                    var portfolios = new List <Portfolio>()
                    {
                        new Portfolio()
                        {
                            OpenDate = DateTime.Now, Name = "Test A"
                        },
                        new Portfolio()
                        {
                            OpenDate = DateTime.Now, Name = "Test B"
                        },
                        new Portfolio()
                        {
                            OpenDate = DateTime.Now, Name = "Test C"
                        },
                        new Portfolio()
                        {
                            OpenDate = DateTime.Now, Name = "Test D"
                        },
                    };

                    foreach (var portfolio in portfolios)
                    {
                        var summaryDate = DateTime.Now;
                        for (int i = 0; i < 10; i++)
                        {
                            var summary = new PortfolioTransactionsSummary()
                            {
                                CloseAmount = (decimal) new Random(i).NextDouble() *
                                              ((decimal) new Random(i).NextDouble() * 10),
                                OpenAmount =
                                    (decimal) new Random(i).NextDouble() * ((decimal) new Random(i).NextDouble() * 10),
                                CloseDate = summaryDate,
                                OpenDate  = summaryDate.AddDays(-30),
                                Portfolio = portfolio
                            };

                            context.Add(summary);
                            summaryDate = summaryDate.AddDays(-30);
                        }

                        var transactionDate = DateTime.Now;
                        for (int i = 0; i < 10; i++)
                        {
                            var transaction = new PortfolioTransaction()
                            {
                                Total = (decimal) new Random(i).NextDouble() * 10,
                                Price = (decimal) new Random(i).NextDouble() *
                                        ((decimal) new Random(i).NextDouble() * 10),
                                Quantity                 = Math.Abs(new Random(i).Next()),
                                Date                     = transactionDate,
                                Portfolio                = portfolio,
                                PortfolioShare           = portfolioShareA,
                                PortfolioTransactionType = portfolioTransactionTypeClose
                            };

                            context.Add(transaction);
                            transactionDate = transactionDate.AddDays(-1);
                        }

                        context.Add(portfolio);
                    }

                    applicationUser.AddEntityOrganization(organization);
                    applicationUser.ActiveEntityOrganizationId = 1;
                    applicationUser.AddAuthorizationGroup(authorizationGroupA);
                    applicationUser.AuthorizationRole = adminRole;

                    context.Add(organization);
                    context.Add(adminRole);
                    context.Add(advisoryRole);
                    context.Add(agentRole);
                    context.Add(workflowRole);
                    context.Add(applicationUser);
                    context.Add(workflowUser);
                    context.Add(schedulerFlowUser);
                    context.Add(currentAdviser);
                    context.Add(gender);
                    context.Add(occupation);
                    context.Add(addressType);
                    context.Add(phoneCallActivityType);
                    context.Add(meetingActivityType);
                    context.Add(authorizationGroupA);
                    //context.Add(authorizationGroupB);

                    for (int i = 0; i < 1000; i++)
                    {
                        var user = new ApplicationUser()
                        {
                            Name        = "Default", Email = $"testB@test{i}.com",
                            Password    = "******",
                            CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now
                        };
                        user.AddEntityOrganization(organization);
                        user.ActiveEntityOrganizationId = 1;
                        user.AddAuthorizationGroup(authorizationGroupA);
                        user.AuthorizationRole = adminRole;
                        context.Add(user);
                    }

                    context.SaveChanges();
                }
            }
        }