Esempio n. 1
0
        public void CreatePortfolio(string cmdString)
        {
            CreatePortfolioCommand cmd = Newtonsoft.Json.JsonConvert.DeserializeObject <CreatePortfolioCommand>(cmdString);

            Models.ViewModel.OptimalPortoliosViewModel vm = new Models.ViewModel.OptimalPortoliosViewModel();
            string userName = "";

            try
            {
                var  userId = WebApiApplication.hubUsers.FirstOrDefault(x => x.Value == Context.ConnectionId).Key;
                User user   = _userService.GetUser(userId).User;
                userName = user.Username;
                vm       = _service.CreatePortfolio(user, cmd);
            }
            catch (Exception e)
            {
                vm.Messages.Add(new Models.App.Message {
                    Text = e.Message, LogLevel = Models.App.LogLevel.Error
                });
            }
            if (!string.IsNullOrEmpty(userName) && vm.Messages.Count == 0)
            {
                CacheHelper.Delete(userName + "portfolio");
            }
            Clients.Caller.update(Newtonsoft.Json.JsonConvert.SerializeObject(vm));
        }
Esempio n. 2
0
        public async Task <PortfolioService.SharesViewModel> CreateShare(CreateShareViewModel viewModel)
        {
            PortfolioService.PortfolioViewModel portfolio = null;

            // Check if portfolioId is correct
            if (viewModel.PortfolioId != null && viewModel.PortfolioId != Guid.Empty)
            {
                portfolio = await _portfolioService.GetPortfolio(viewModel.PortfolioId);

                if (portfolio == null)
                {
                    throw new ArgumentException("PortfolioId doesn't match any existing portfolios");
                }
            }
            else
            {
                portfolio = await _portfolioService.GetPortfolioByUser(viewModel.UserId);

                if (portfolio == null)
                {
                    portfolio = await _portfolioService.CreatePortfolio(viewModel.UserId);
                }
                viewModel.PortfolioId = portfolio.PortfolioId;
            }

            var share = await _portfolioService.CreateShare(viewModel.PortfolioId, viewModel.Name, viewModel.TotalValue, viewModel.Count);

            if (share == null)
            {
                throw new ArgumentException("Couldn't create share");
            }

            return(share);
        }
Esempio n. 3
0
        public async Task <OperationResult> CreatePortfolio([CurrentUserIdGlobalState] int userId,
                                                            [Service] IPortfolioService portfolioService, string name)
        {
            var result = await portfolioService.CreatePortfolio(name, userId);

            return(result);
        }
Esempio n. 4
0
        public async Task <User> Register(string username, string password)
        {
            var userServiceModel = await _usersService.RegisterUser(username.ToLower()) ?? await _usersService.GetUser(username.ToLower());

            if (userServiceModel == null)
            {
                return(null);
            }

            if (!await _portfolioService.CreatePortfolio(userServiceModel.UserId))
            {
                return(null);
            }
            if (!await _bankService.CreateBankAndAccount(userServiceModel.UserId))
            {
                return(null);
            }

            var cipher = CryptoProvider.Encrypt(new CryptoProvider.Plain {
                Password = password
            });
            var user = new User
            {
                UserId   = userServiceModel.UserId,
                Username = userServiceModel.Email,
                Hash     = cipher.Hash,
                Salt     = cipher.Salt
            };

            _unitOfWork.AuthenticationRepository.Register(user);
            await _unitOfWork.CommitAsync();

            return(user);
        }
        public ActionResult CreatePortfolio(Portfolio portfolio)
        {
            portfolio.UserId = UserId;

            var addRes      = _portfolioService.CreatePortfolio(portfolio);
            var dbPortfolio = _portfolioService.GetPortfolio(p => p.UserId == UserId);

            return(Ok(new PortfolioModel(dbPortfolio)));
        }
        public async Task <ActionResult <Portfolio> > PostPortfolio(PortfolioCreateDto portfolio)
        {
            string userId       = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
            var    newPortfolio = _mapper.Map <Portfolio>(portfolio);

            var data = await _portfolioService.CreatePortfolio(newPortfolio, userId);

            return(CreatedAtAction("GetPortfolio", new { id = data.Id }, data));
        }
Esempio n. 7
0
        public ActionResult CreatePortfolio(Portfolio portfolio)
        {
            var user = User.GetUserDetails();

            portfolio.UserId = user.UserId;

            var addRes      = _portfolioService.CreatePortfolio(portfolio);
            var dbPortfolio = _portfolioService.GetPortfolio(user.UserId);

            return(Ok(new PortfolioModel(dbPortfolio)));
        }
        public async Task <IActionResult> Create([Bind("Name,Id,CreatedDate,UpdatedDate")] Portfolio portfolio)
        {
            if (ModelState.IsValid)
            {
                var username = User.Identity.Name;
                await _context.CreatePortfolio(portfolio, username);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(portfolio));
        }
Esempio n. 9
0
        private void GetAsyncResponse(User user, CreatePortfolioCommand cmd, HttpContext context)
        {
            HttpContext.Current = new HttpContext(context.Request, context.Response);

            service = WebApiApplication.Container.Resolve <IPortfolioService>();
            var vm = service.CreatePortfolio(user, cmd);

            WebApiApplication.Container.Release(service);
            //CacheHelper.Delete(user.Username + "portfolio");
            this.Hub.Clients.Client(WebApiApplication.hubUsers[user.UserID]).update(Newtonsoft.Json.JsonConvert.SerializeObject(vm));
        }
Esempio n. 10
0
        public async Task <IActionResult> CreatePortfolio([FromBody] CreatePortfolioViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var portfolio = await _portfolioService.CreatePortfolio(model.UserId);

            if (portfolio == null)
            {
                return(NotFound("User doesn't exist"));
            }
            return(CreatedAtAction(nameof(GetByPortfolio), new { portfolio.PortfolioId }, portfolio));
        }
        public async Task <ActionResult> Post(CreatePortfolioDto portfolioDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(portfolioDto));
            }

            var result = await _portfolioService.CreatePortfolio(portfolioDto);

            if (result > 0)
            {
                return(Ok(new { portfolioId = result }));
            }

            return(BadRequest());
        }
Esempio n. 12
0
 public IHttpActionResult Post([FromBody] PortfolioModel portfolio)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         portfolioService.CreatePortfolio(Mapper.Map <PortfolioModel, PortfolioDTO>(portfolio), RequestContext.Principal.Identity.GetUserId());
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex.Message);
         logger.Error(ex.ToString());
         return(BadRequest(ex.ToString()));
     }
     return(Ok());
 }
Esempio n. 13
0
        public IActionResult CreatePortfolio()
        {
            var portfolio = _portfolioService.CreatePortfolio(UserId);

            return(Ok(portfolio));
        }