//protected virtual IActionResult Portfolio(Guid guid)
        //{
        //    var baseValidation = GetBasicValidation(guid, "GetPortfolio");
        //    if (baseValidation.Return != null)
        //        return baseValidation.Return;

        //    List<Portfolio> portfolios;
        //    try
        //    {
        //        portfolios = PortfolioServices.ListPortfolio(baseValidation.Email);
        //    }
        //    catch (ArgumentException ex)
        //    {
        //        return BadRequest(new { error = ex.Message });
        //    }
        //    return Ok(portfolios.Select(p =>
        //            new
        //            {
        //                id = p.Id,
        //                risk = p.Risk,
        //                projectionValue = p.Projection.ProjectionValue,
        //                pessimisticValue = p.Projection.PessimisticProjection,
        //                optimisticValue = p.Projection.OptimisticProjection,
        //                advisor = new
        //                {
        //                    id = p.AdvisorId,
        //                    name = p.Advisor.Name,
        //                    price = p.Advisor.Detail.Price,
        //                    description = p.Advisor.Detail.Description,
        //                    period = p.Advisor.Detail.Period,
        //                    enabled = p.Advisor.Detail.Enabled
        //                },
        //                distribution = p.Projection.Distribution.Select(d => new
        //                {
        //                    asset = new
        //                    {
        //                        id = d.Asset.Id,
        //                        name = d.Asset.Name,
        //                        code = d.Asset.Code
        //                    },
        //                    percent = d.Percent
        //                })
        //            }));
        //}

        //protected virtual IActionResult AdvisorUpdate(Guid guid, int advisorId, AdvisorDetailRequest advisorDetailRequest)
        //{
        //    if (advisorDetailRequest == null)
        //        return BadRequest();

        //    var baseValidation = GetBasicValidation(guid, "AdvisorUpdate");
        //    if (baseValidation.Return != null)
        //        return baseValidation.Return;

        //    try
        //    {
        //        AdvisorServices.UpdateAdvisor(baseValidation.Email, advisorId, advisorDetailRequest.Description,
        //            advisorDetailRequest.Period, advisorDetailRequest.Price, advisorDetailRequest.Enabled);
        //    }
        //    catch (ArgumentException ex)
        //    {
        //        return BadRequest(new { error = ex.Message });
        //    }
        //    return Ok();
        //}

        //protected virtual IActionResult Portfolio(Guid guid, PortfolioRequest portfolioRequest)
        //{
        //    if (portfolioRequest == null || portfolioRequest.Distribution == null || portfolioRequest.Distribution.Count == 0)
        //        return BadRequest();

        //    var baseValidation = GetBasicValidation(guid, "PostPortfolio");
        //    if (baseValidation.Return != null)
        //        return baseValidation.Return;

        //    Portfolio portfolio;
        //    try
        //    {
        //        portfolio = PortfolioServices.CreatePortfolio(baseValidation.Email, portfolioRequest.AdvisorId, portfolioRequest.Risk,
        //            portfolioRequest.ProjectionValue, portfolioRequest.OptimisticProjection, portfolioRequest.PessimisticProjection,
        //            portfolioRequest.Distribution.ToDictionary(c => c.AssetId, c => c.Percentage));
        //    }
        //    catch (ArgumentException ex)
        //    {
        //        return BadRequest(new { error = ex.Message });
        //    }
        //    return Ok(new { id = portfolio.Id });
        //}

        protected virtual IActionResult Projection(Guid guid, int portfolioId, ProjectionRequest projectionRequest)
        {
            return(new StatusCodeResult(405));

            if (projectionRequest == null || projectionRequest.Distribution == null || projectionRequest.Distribution.Count == 0)
            {
                return(BadRequest());
            }

            var baseValidation = GetBasicValidation(guid, "PostProjection");

            if (baseValidation.Return != null)
            {
                return(baseValidation.Return);
            }

            try
            {
                PortfolioServices.CreateProjection(baseValidation.Email, portfolioId, projectionRequest.ProjectionValue,
                                                   projectionRequest.Risk, projectionRequest.OptimisticProjection, projectionRequest.PessimisticProjection,
                                                   projectionRequest.Distribution.ToDictionary(c => c.AssetId, c => c.Percentage));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(new { error = ex.Message }));
            }
            return(Ok());
        }
 protected virtual IActionResult GetDistribution(int portfolioId)
 {
     try
     {
         var distribution = PortfolioServices.ListPortfolioDistribution(GetUser(), portfolioId);
         return(Ok(distribution));
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(new { error = ex.Message }));
     }
 }
 protected virtual IActionResult DisablePortfolio(int portfolioId)
 {
     try
     {
         PortfolioServices.DisablePortfolio(GetUser(), portfolioId);
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(new { error = ex.Message }));
     }
     return(Ok());
 }
 protected virtual IActionResult GetPortfolio(int portfolioId)
 {
     try
     {
         var portfolio = PortfolioServices.GetPortfolio(GetUser(), portfolioId);
         return(Ok(portfolio));
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(new { error = ex.Message }));
     }
 }
        protected virtual IActionResult ListPurchasedPortfolios()
        {
            List <Auctus.Model.Portfolio> portfolios;

            try
            {
                portfolios = PortfolioServices.ListPurchasedPortfolios(GetUser());
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(new { error = ex.Message }));
            }
            return(Ok(portfolios));
        }
        protected virtual IActionResult Distribution(int portfolioId, List <DistributionRequest> newDistributionRequest)
        {
            if (newDistributionRequest == null || newDistributionRequest.Count == 0)
            {
                return(BadRequest());
            }

            try
            {
                PortfolioServices.CreateDistribution(GetUser(), portfolioId, newDistributionRequest.ToDictionary(c => c.AssetId, c => c.Percentage));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(new { error = ex.Message }));
            }
            return(Ok());
        }
        public void ShouldThrowExcepIfSellerDontHasNShares()
        {
            var portfolioTableRepository = Substitute.For <IPortfolioTableRepository>();
            PortfolioServices portfolio  = new PortfolioServices(portfolioTableRepository);
            var user = new UserEntity()
            {
                UsersShares = new List <PortfolioEntity>()
                {
                    new PortfolioEntity()
                    {
                        ShareId = 1,
                        Amount  = 1
                    }
                }
            };

            portfolio.ChangeAmountOfShares(user.UsersShares.Where(us => us.ShareId == 1).First(), -10);
        }
        protected virtual IActionResult UpdatePortfolioAndDistribution(int portfolioId, UpdatePortfolioWithDistributionRequest updatePortfolioRequest)
        {
            if (updatePortfolioRequest == null || updatePortfolioRequest.Distribution == null || updatePortfolioRequest.Distribution.Count == 0)
            {
                return(BadRequest());
            }

            try
            {
                PortfolioServices.UpdatePortfolioAndDistribution(GetUser(), portfolioId, updatePortfolioRequest.Price, updatePortfolioRequest.Name,
                                                                 updatePortfolioRequest.Description, updatePortfolioRequest.Distribution.ToDictionary(c => c.AssetId, c => c.Percentage));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(new { error = ex.Message }));
            }
            return(Ok());
        }
        protected virtual IActionResult UpdatePortfolio(int portfolioId, UpdatePortfolioRequest updatePortfolioRequest)
        {
            if (updatePortfolioRequest == null)
            {
                return(BadRequest());
            }

            try
            {
                PortfolioServices.UpdatePortfolio(GetUser(), portfolioId, updatePortfolioRequest.Price,
                                                  updatePortfolioRequest.Name, updatePortfolioRequest.Description);
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(new { error = ex.Message }));
            }
            return(Ok());
        }
        public void ShouldChangeAmountOfShareByUser()
        {
            var portfolioTableRepository = Substitute.For <IPortfolioTableRepository>();
            PortfolioServices portfolio  = new PortfolioServices(portfolioTableRepository);
            PortfolioEntity   args       = new PortfolioEntity()
            {
                UserEntityId = 1,
                ShareId      = 1,
                Amount       = 50
            };

            portfolio.ChangeAmountOfShares(args, -10);

            portfolioTableRepository.Contains(Arg.Is <PortfolioEntity>(
                                                  u => u.UserEntityId == args.UserEntityId &&
                                                  u.ShareId == args.ShareId &&
                                                  u.Amount == args.Amount - 10)).Returns(true);
            portfolioTableRepository.Received(1).SaveChanges();
        }
        public void ShouldAddNewUsersShares()
        {
            var portfolioTableRepository = Substitute.For <IPortfolioTableRepository>();
            PortfolioServices portfolio  = new PortfolioServices(portfolioTableRepository);
            PortfolioInfo     args       = new PortfolioInfo()
            {
                UserId  = 1,
                ShareId = 1,
                Amount  = 50
            };

            portfolio.AddNewUsersShares(args);

            portfolioTableRepository.AddNewUsersShares(Arg.Is <PortfolioEntity>(
                                                           us => us.UserEntityId == args.UserId &&
                                                           us.ShareId == args.ShareId &&
                                                           us.Amount == args.Amount));
            portfolioTableRepository.Received(1).SaveChanges();
        }
        protected virtual IActionResult Portfolio(PortfolioRequest portfolioRequest)
        {
            if (portfolioRequest == null || portfolioRequest.Distribution == null)
            {
                return(BadRequest());
            }

            Auctus.DomainObjects.Portfolio.Portfolio portfolio;
            try
            {
                portfolio = PortfolioServices.CreatePortfolio(GetUser(), portfolioRequest.AdvisorId, portfolioRequest.Price, portfolioRequest.Name,
                                                              portfolioRequest.Description, portfolioRequest.ProjectionValue, portfolioRequest.OptimisticProjection, portfolioRequest.PessimisticProjection,
                                                              portfolioRequest.Distribution.ToDictionary(c => c.AssetId, c => c.Percentage));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(new { error = ex.Message }));
            }
            return(Ok(new { id = portfolio.Id }));
        }
        protected virtual IActionResult Distribution(Guid guid, int portfolioId, List <DistributionRequest> newDistributionRequest)
        {
            if (newDistributionRequest == null || newDistributionRequest.Count == 0)
            {
                return(BadRequest());
            }

            var baseValidation = GetBasicValidation(guid, "PostDistribution");

            if (baseValidation.Return != null)
            {
                return(baseValidation.Return);
            }

            try
            {
                PortfolioServices.CreateDistribution(baseValidation.Email, portfolioId, newDistributionRequest.ToDictionary(c => c.AssetId, c => c.Percentage));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(new { error = ex.Message }));
            }
            return(Ok());
        }
Exemple #14
0
 public PortfolioProxy(PortfolioServices portfolioServices)
 {
     this.portfolioServices = portfolioServices;
 }