コード例 #1
0
ファイル: PortfolioTests.cs プロジェクト: MihA-aa/Invest-site
        public void CanGetPortfolioById()
        {
            portfolioRepository.Setup(c => c.Get(It.IsAny <int>()))
            .Returns((int i) => ListPortfolios.FirstOrDefault(c => c.Id == i));
            UnitOfWork.Setup(m => m.Portfolios).Returns(portfolioRepository.Object);
            portfolioService = new PortfolioService(UnitOfWork.Object, validateService, customerService.Object, map, positionService.Object);

            PortfolioDTO portfolio1 = portfolioService.GetPortfolio(1);
            PortfolioDTO portfolio2 = portfolioService.GetPortfolio(2);

            Assert.AreEqual(portfolio1.Name, "Strategic Investment Open Portfolio");
            Assert.AreEqual(portfolio2.Name, "Strategic Investment Income Portfolio");
        }
コード例 #2
0
        public async Task <IHttpActionResult> Get()
        {
            PortfolioService portService = CreatePortfolioService();
            var posts = await portService.GetPortfolio();

            return(Ok(posts));
        }
コード例 #3
0
    protected void gvNominees_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        // Retrieve the row being edited.
        int          index          = gvNominees.EditIndex;
        GridViewRow  row            = gvNominees.Rows[index];
        DropDownList ddlEditStatus  = row.FindControl("ddlEditStatus") as DropDownList;
        TextBox      txtEditScore   = row.FindControl("txtEditScore") as TextBox;
        TextBox      txtEditRanking = row.FindControl("txtEditRanking") as TextBox;
        int          id             = Convert.ToInt32(gvNominees.DataKeys[e.RowIndex].Value);
        Portfolio    p = PortfolioService.GetPortfolio(id);

        if (null != p)
        {
            p.Status     = (Status)Enum.Parse(typeof(Status), ddlEditStatus.SelectedValue);
            p.TotalScore = Convert.ToDouble(txtEditScore.Text);
            p.Ranking    = Convert.ToInt32(txtEditRanking.Text);
            PortfolioService.Save(p);
            e.Cancel             = false;
            gvNominees.EditIndex = -1;
        }
        else
        {
            e.Cancel = true;
        }
        LoadNominees();
    }
コード例 #4
0
ファイル: PortfolioTests.cs プロジェクト: MihA-aa/Invest-site
        public void CanNotGetPortfolioByNullId()
        {
            UnitOfWork.Setup(m => m.Portfolios).Returns(portfolioRepository.Object);
            portfolioService = new PortfolioService(UnitOfWork.Object, validateService, customerService.Object, map, positionService.Object);

            portfolioService.GetPortfolio(null);
        }
コード例 #5
0
ファイル: Default.aspx.cs プロジェクト: rjustesen/Sterling
    /// <summary>
    /// Link to page
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvNominees_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int       id        = Convert.ToInt32(gvNominees.DataKeys[0].Values[0]);
        Portfolio portfolio = null;

        if (!"".Equals(e.CommandArgument))
        {
            id        = Convert.ToInt32(e.CommandArgument);
            portfolio = PortfolioService.GetPortfolio(id);
        }
        if ("Select".Equals(e.CommandName))
        {
            Response.Redirect("StudentEdit.aspx?id=" + id.ToString());
        }
        if ("DeleteUser".Equals(e.CommandName))
        {
            if (portfolio != null)
            {
                PortfolioService.Delete(portfolio);
                UserService.DeleteUser(portfolio.User);
                LoadApplications();
            }
        }
        if ("ViewPortfolio".Equals(e.CommandName))
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<script language=JavaScript id='openit'>");
            sb.Append("window.open('../ReportView.aspx?report=profile&id=" + portfolio.Id + "', '', '');");
            sb.Append("</script>");
            if (!ClientScript.IsStartupScriptRegistered("openit"))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "openit", sb.ToString());
            }
        }
        if ("CertifyStudent".Equals(e.CommandName))
        {
            if (portfolio != null)
            {
                Label lblName     = mdlDlgPrincipal.FindControl("lblName") as Label;
                Label lblId       = mdlDlgPrincipal.FindControl("lblId") as Label;
                Label lblSchool   = mdlDlgPrincipal.FindControl("lblSchool") as Label;
                Label lblCategory = mdlDlgPrincipal.FindControl("lblCategory") as Label;
                lblId.Text       = id.ToString();
                lblName.Text     = portfolio.User.FullName;
                lblSchool.Text   = portfolio.School.Name;
                lblCategory.Text = portfolio.Category.Name;
                mdlDlgPrincipal.ShowModal();
            }
        }
        if ("CheckStatus".Equals(e.CommandName))
        {
            if (portfolio.Status == Status.Certified)
            {
                Label lblId = mdlDlgPrincipal.FindControl("lblId") as Label;
                lblId.Text = portfolio.Id.ToString();
                btnReport_Click(null, null);
            }
        }
    }
コード例 #6
0
ファイル: PortfolioTests.cs プロジェクト: MihA-aa/Invest-site
        public void CanNotGetNonexistentPortfolioByPortfolioId()
        {
            portfolioRepository.Setup(c => c.Get(It.IsAny <int>()))
            .Returns((int i) => ListPortfolios.FirstOrDefault(c => c.Id == i));
            UnitOfWork.Setup(m => m.Portfolios).Returns(portfolioRepository.Object);
            portfolioService = new PortfolioService(UnitOfWork.Object, validateService, customerService.Object, map, positionService.Object);

            portfolioService.GetPortfolio(5);
        }
コード例 #7
0
    protected void valTrans_ServerValidate(object source, ServerValidateEventArgs args)
    {
        Portfolio          portfolio   = PortfolioService.GetPortfolio(PortfolioId);
        IList <Attachment> attachments = PortfolioService.GetAttachments(AttachmentType.Portfolio, portfolio.Id);

        if (attachments.FirstOrDefault(x => x.Category == AttachmentCategory.Transcript) == null)
        {
            args.IsValid = false;
        }
    }
コード例 #8
0
    private void SavePortfolio()
    {
        UserInput input = null;
        Portfolio p     = PortfolioService.GetPortfolio(PortfolioId);

        if (null != p)
        {
            input = UserService.GetUserProfile(p.User.Id);
        }
        else
        {
            input = new UserInput();
        }

        input.FullName = txtFullName.Text;
        input.EMail    = txtEmail.Text;
        input.Comment  = txtComment.Text;
        input.Phone    = txtPhone.Text;
        input.Role     = RoleType.Nominee;

        input.School   = GetSchool();
        input.Category = CategoryService.GetCategory(input.School.Area.Region, ddlCategory.SelectedValue);

        MembershipCreateStatus status = UserService.AddNewUser(input);

        if (status == MembershipCreateStatus.Success)
        {
            User      user      = UserService.GetUser(input.EMail);
            Portfolio portfolio = PortfolioService.GetPortfolioByUser(user);
            portfolio.Parents = txtParents.Text;
            portfolio.Address = txtAddress.Text;
            portfolio.City    = txtCity.Text;
            portfolio.Zip     = txtZip.Text;
            portfolio.State   = ddlState.SelectedValue;
            portfolio.Sex     = (Sexes)Enum.Parse(typeof(Sexes), ddlGender.SelectedValue.ToString());

            if (ddlStatus.Enabled)
            {
                portfolio.Status = (Status)Enum.Parse(typeof(Status), ddlStatus.SelectedValue);
            }
            PortfolioService.Save(portfolio);
            SaveTestScores(portfolio);
            if (input.Id <= 0)
            {
                EMailService.SendEmail("Sterling Scholar Registration Request", UserService.FormatTemplate(System.Web.HttpContext.Current.Server.MapPath("~/") + "/assets/NewUserTemplate.html", user), user.EMail, UserService.AdminEmailAddress, null);
            }

            PortfolioId            = portfolio.Id;
            lnkPicture.Visible     = true;
            lnkTransUpload.Visible = true;
        }
    }
コード例 #9
0
ファイル: Default.aspx.cs プロジェクト: rjustesen/Sterling
 protected void btnOk_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         mdlDlgPrincipal.HideModal();
         Label     lblId = mdlDlgPrincipal.FindControl("lblId") as Label;
         Portfolio app   = PortfolioService.GetPortfolio(Convert.ToInt32(lblId.Text));
         app.Status = Status.Certified;
         PortfolioService.Save(app);
         btnReport_Click(null, null);
         LoadApplications();
     }
 }
コード例 #10
0
 protected void btnAdvance_Click(object sender, EventArgs e)
 {
     foreach (GridViewRow row in gvNominees.Rows)
     {
         CheckBox cb = row.FindControl("chkNominee") as CheckBox;
         if (null != cb && cb.Checked)
         {
             int       id  = Convert.ToInt32(gvNominees.DataKeys[row.RowIndex].Value);
             Portfolio app = PortfolioService.GetPortfolio(id);
             ScoreService.AdvanceStatus(app);
         }
     }
     LoadNominees();
 }
コード例 #11
0
    private void ViewScores(int id)
    {
        Label     lblName   = modalDialog.FindControl("lblName") as Label;
        Label     lblFooter = modalDialog.FindControl("lblFooter") as Label;
        ListView  lv        = modalDialog.FindControl("lvScores") as ListView;
        Portfolio p         = PortfolioService.GetPortfolio(id);

        lblName.Text   = p.User.FullName;
        lblFooter.Text = " Overall Average Score: " + p.TotalScore.ToString("F");
        IList <JudgeStatus> list = ScoreService.GetJudgeStatusForPortfolio(p);

        lv.DataSource = list.Where(x => x.Judge.User.Role == Judge.User.Role);
        lv.DataBind();
        modalDialog.ShowModal();
    }
コード例 #12
0
    protected void lnkTrans_Click(object sender, EventArgs e)
    {
        Portfolio portfolio = PortfolioService.GetPortfolio(PortfolioId);

        if (null != portfolio)
        {
            IList <Attachment> attachments = PortfolioService.GetAttachments(AttachmentType.Portfolio, portfolio.Id);
            Attachment         attachment  = attachments.FirstOrDefault(x => x.Category == AttachmentCategory.Transcript);
            if (null == attachment)
            {
                ShowUploadDlg(-1, AttachmentCategory.Transcript, "Upload Transcript", "A certified list of high school grades must be included in your profile. This transcript must be stamped, bearing the offical school seal or principal's signature and MUST include class ranking, cumulative GPA and ACT scores. Proof of ACT scores is required if not on the transcript.");
            }
            else
            {
                ShowUploadDlg(attachment.Id, AttachmentCategory.Transcript, "Upload Transcript", "A certified list of high school grades must be included in your profile. This transcript must be stamped, bearing the offical school seal or principal's signature and MUST include class ranking, cumulative GPA and ACT scores. Proof of ACT scores is required if not on the transcript.");
            }
        }
        else
        {
            ShowUploadDlg(-1, AttachmentCategory.Transcript, "Upload Transcript", "A certified list of high school grades must be included in your profile. This transcript must be stamped, bearing the offical school seal or principal's signature and MUST include class ranking, cumulative GPA and ACT scores. Proof of ACT scores is required if not on the transcript.");
        }
    }
コード例 #13
0
    protected void lnkPicture_Click(object sender, EventArgs e)
    {
        Portfolio portfolio = PortfolioService.GetPortfolio(PortfolioId);

        if (null != portfolio)
        {
            IList <Attachment> attachments = PortfolioService.GetAttachments(AttachmentType.Portfolio, portfolio.Id);
            Attachment         image       = attachments.FirstOrDefault(x => x.Category == AttachmentCategory.PersonalPhoto);
            if (null == image)
            {
                ShowUploadDlg(-1, AttachmentCategory.PersonalPhoto, "Upload Photo", "Personal photos must be in JPG or PNG format and should be no larger than 640 x 480 pixels. Images will be automatically resized to these dimensions but we recommend resizing your images before you upload them to avoid any potential problems.");
            }
            else
            {
                ShowUploadDlg(image.Id, AttachmentCategory.PersonalPhoto, "Upload Photo", "Personal photos must be in JPG or PNG format and should be no larger than 640 x 480 pixels. Images will be automatically resized to these dimensions but we recommend resizing your images before you upload them to avoid any potential problems.");
            }
        }
        else
        {
            ShowUploadDlg(-1, AttachmentCategory.PersonalPhoto, "Upload Photo", "Personal photos must be in JPG or PNG format and should be no larger than 640 x 480 pixels. Images will be automatically resized to these dimensions but we recommend resizing your images before you upload them to avoid any potential problems.");
        }
    }
コード例 #14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string       report = Request["report"];
            MemoryStream stream = null;

            if ("profile".Equals(report))
            {
                string id           = Request["id"];
                String UrlDirectory = Request.Url.GetLeftPart(UriPartial.Path);
                UrlDirectory = UrlDirectory.Substring(0, UrlDirectory.LastIndexOf("/"));
                Portfolio portfolio = PortfolioService.GetPortfolio(Convert.ToInt32(id));
                if (CurrentUser.Role == RoleType.Nominee)
                {
                    if (portfolio.User.Id != CurrentUser.Id)
                    {
                        portfolio = PortfolioService.GetPortfolioByUser(CurrentUser);
                    }
                }
                else if (CurrentUser.Role == RoleType.Coordinator)
                {
                    School school = RegionService.GetSchoolByUser(CurrentUser);
                    if (portfolio.School.Id != school.Id)
                    {
                        portfolio = null;
                    }
                }
                if (null != portfolio)
                {
                    IList <Attachment> list = PortfolioService.GetAttachments(AttachmentCategory.Portfolio, AttachmentType.FinalPortfolio, portfolio.Id);
                    if (list.Count > 0)
                    {
                        stream = new MemoryStream();
                        Attachment attachment = PortfolioService.GetAttachment(list[0].Id);
                        stream.Write(attachment.Data, 0, attachment.Data.Length);
                    }
                    else
                    {
                        stream = ReportService.CreatePortfolioReport(portfolio, UrlDirectory);
                    }
                }
            }
            if ("principal".Equals(report))
            {
                if (CurrentUser.Role == RoleType.Principal || CurrentUser.Role == RoleType.Coordinator)
                {
                    string    id        = Request["id"];
                    Portfolio portfolio = PortfolioService.GetPortfolio(Convert.ToInt32(id));
                    stream = ReportService.CreatePrincipalReport(portfolio);
                }
                else
                {
                    Response.Redirect("~/Default.aspx");
                }
            }
            if ("nominees".Equals(report))
            {
                if (CurrentUser.Role != RoleType.Nominee)
                {
                    string id     = Request["id"];
                    School school = RegionService.GetSchool(Convert.ToInt32(id));
                    stream = ReportService.NomineeReport(school);
                }
                else
                {
                    Response.Redirect("~/Default.aspx");
                }
            }
            Response.Clear();
            Response.ContentType = "application/pdf";

            Response.OutputStream.Write(stream.GetBuffer(), 0, (int)stream.GetBuffer().Length);
            Response.OutputStream.Flush();
            Response.OutputStream.Close();
            Response.End();
        }
    }
コード例 #15
0
        static void Main(string[] args)
        {
            var token = File.ReadAllText("token.txt").Replace("\n", "").Replace("\t", "").Replace(" ", "");

            RestConfiguration = new RestConfiguration
            {
                AccessToken = token,
                BaseUrl     = "https://api-invest.tinkoff.ru/openapi/",
                SandboxMode = false
            };
            MarketService    = new MarketService(RestConfiguration);
            PortfolioService = new PortfolioService(RestConfiguration);
            OperationService = new OperationService(RestConfiguration);

            var result = PortfolioService.GetPortfolio().Result;

            Console.WriteLine("Портфель:");
            Console.WriteLine($"Тикер     \tКол-во   \tСредняя(FIFO)\tСредняя(Норм)\tДоход(FIFO)");
            foreach (var position in result.Positions)
            {
                var operationsOfOpenPosition = new[] { new { OperationType = ExtendedOperationType.BrokerCommission, Trade = new Trade() } }.ToList();
                operationsOfOpenPosition.Clear();
                var filter     = new OperationsFilter();
                filter.Figi     = position.Figi;
                filter.Interval = OperationInterval.Month;
                filter.To       = DateTime.Now;
                filter.From     = DateTime.Now.AddYears(-1);
                var operations = OperationService.Get(filter).Result.Operations;
                var buySellOperations = operations.Where(x => (x.OperationType == ExtendedOperationType.Buy || x.OperationType == ExtendedOperationType.Sell) && x.Status != OperationStatus.Decline)
                                        .SelectMany(x => x.Trades.Select(y => new { x.OperationType, Trade = y })).OrderByDescending(x => x.Trade.Date);

                var balance    = position.Balance;

                foreach (var operation in buySellOperations)
                {
                    balance = operation.OperationType == ExtendedOperationType.Buy ? (balance - operation.Trade.Quantity) : (balance + operation.Trade.Quantity);
                    operationsOfOpenPosition.Add(operation);
                    if (balance == 0)
                    {
                        break;
                    }
                }

                var averageValue      = 0m;
                var qty               = 0;
                var orderedOperations = operationsOfOpenPosition.OrderBy(x => x.Trade.Date);
                foreach (var operation in orderedOperations.OrderBy(x => x.Trade.Date))
                {
                    if (averageValue == 0m)
                    {
                        averageValue = operation.Trade.Price;
                        qty          = operation.Trade.Quantity;
                    }
                    else if (operation.OperationType == ExtendedOperationType.Buy)
                    {
                        averageValue = (averageValue * qty + operation.Trade.Price * operation.Trade.Quantity) / (qty + operation.Trade.Quantity);
                        qty         += operation.Trade.Quantity;
                    }
                    else
                    {
                        averageValue = (averageValue * qty - operation.Trade.Price * operation.Trade.Quantity) / (qty - operation.Trade.Quantity);
                        qty         -= operation.Trade.Quantity;
                    }
                }

                if (position.ExpectedYield.Value > 0)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                Console.WriteLine($"{position.Ticker,-15}\t{position.Balance, -8}\t{position.AveragePositionPrice.Value, -8}\t{averageValue,-8:0.00}\t{position.ExpectedYield?.Value,-8} {position.ExpectedYield?.Currency,-8}");

                //if(position.Ticker == "M")
                //{
                //    foreach(var operation in orderedOperations)
                //    {
                //        Console.WriteLine($"{position.Ticker} {operation.Trade.Date} {operation.OperationType} {operation.Trade.Price}x{operation.Trade.Quantity}={operation.Trade.Price*operation.Trade.Quantity} ");
                //    }
                //}

                //foreach (var operation in operations.Where(x=>x.OperationType != ExtendedOperationType.BrokerCommission && x.Status != OperationStatus.Decline))
                //{
                //   // Console.WriteLine($"{position.Ticker} {operation.Date} {operation.OperationType} {operation.Price} {operation.Quantity} {operation.Payment} {operation.Commission?.Value} {operation.Status}");
                //}
                //var buyOperations = operations.Where(x => x.OperationType == ExtendedOperationType.Buy && x.Status != OperationStatus.Decline).SelectMany(x=>x.Trades);
                //var sellOperations = operations.Where(x => x.OperationType == ExtendedOperationType.Sell && x.Status != OperationStatus.Decline).SelectMany(x => x.Trades);
                //Console.WriteLine($"{position.Ticker} count {buyOperations.Sum(x => x.Quantity) - sellOperations.Sum(x => x.Quantity)}");
            }
        }
コード例 #16
0
    private void LoadApplication()
    {
        Portfolio portfolio = PortfolioService.GetPortfolio(PortfolioId);


        ddlState.DataSource     = StateService.GetStates();
        ddlState.DataValueField = "StateCode";
        ddlState.DataTextField  = "StateName";
        ddlState.DataBind();

        if (null != portfolio)
        {
            ddlCategory.DataMember    = "Id";
            ddlCategory.DataTextField = "Name";
            ddlCategory.DataSource    = CategoryService.GetCategories(portfolio.School.Area.Region);
            ddlCategory.DataBind();


            IList <Attachment> attachments = PortfolioService.GetAttachments(AttachmentType.Portfolio, portfolio.Id);

            Attachment image = attachments.FirstOrDefault(x => x.Category == AttachmentCategory.PersonalPhoto);
            lnkPicture.Visible = true;

            lnkTransUpload.Visible  = (attachments.FirstOrDefault(x => x.Category == AttachmentCategory.Transcript) == null);
            lvTranscript.DataSource = attachments.Where(x => x.Category == AttachmentCategory.Transcript);;
            lvTranscript.DataBind();

            if (null != image)
            {
                picNominee.Visible  = true;
                picNominee.ImageUrl = "~/ImageHandler.ashx?id=" + image.Id;
            }

            LoadTestScores(portfolio);
            ddlStatus.SelectedValue = portfolio.Status.ToString();

            ddlCategory.SelectedValue = portfolio.Category.Name;
            ddlCategory.Enabled       = false;
            txtFullName.Text          = portfolio.User.FullName;
            txtEmail.Text             = portfolio.User.EMail;
            txtComment.Text           = portfolio.User.Comment;
            txtPhone.Text             = portfolio.User.PhoneNumber;
            txtParents.Text           = portfolio.Parents;
            txtAddress.Text           = portfolio.Address;
            txtCity.Text            = portfolio.City;
            ddlState.SelectedValue  = portfolio.State;
            txtZip.Text             = portfolio.Zip;
            ddlGender.SelectedValue = portfolio.Sex.ToString();
            lblStudentName.Text     = "Missing Items for " + portfolio.User.FullName;
            lvItems.DataSource      = PortfolioService.GetMissingItems(portfolio);
            lvItems.DataBind();
        }
        else
        {
            ddlCategory.DataMember    = "Id";
            ddlCategory.DataTextField = "Name";
            ddlCategory.DataSource    = CategoryService.GetCategories(GetSchool().Area.Region);
            ddlCategory.DataBind();

            ddlCategory.Enabled    = true;
            ddlStatus.Enabled      = false;
            txtFullName.Text       = "";
            txtEmail.Text          = "";
            txtComment.Text        = "";
            txtPhone.Text          = "";
            txtParents.Text        = "";
            txtAddress.Text        = "";
            txtCity.Text           = "";
            ddlState.SelectedValue = "UT";
            txtZip.Text            = "";
            lnkPicture.Visible     = false;
            lnkTransUpload.Visible = false;
        }
    }