コード例 #1
0
 public function getByUserId()
 {
     if (Auth::user() != null) {
         $userId = Auth::user()->id;
         $rep = new PortfoliosRepository();
         return response()->json($rep->GetByUserId($userId));
     } else {
         return response()->json(null);
     }
 }
コード例 #2
0
 public function joinLeague($code)
 {
     $leagueRep = new LeaguesRepository();
     $portfolioRep = new PortfoliosRepository();
     $user = Auth::user();
     $league = $leagueRep->GetLeagueByCode($code);
     if ($league == null) {
         return array('success' => false, 'message' => 'connot find a league for code: ' . $code);
     }
     if ($portfolioRep->DoesLeaguePortfolioExist($user->id, $league->id)) {
         return array('success' => false, 'message' => 'You already belong to this league');
     }
     $leagueRep->AddUserToLeague($user->id, $league->id, $league->initial_balance);
     return array('success' => true, 'id' => $league->id);
 }
コード例 #3
0
 public function CompleteTrade()
 {
     $userRep = new UsersRepository();
     $portfolioRep = new PortfoliosRepository();
     $id = Input::get('id');
     $user = Auth::user();
     if ($user) {
         $trade = Trade::find($id);
         $portfolio = Portfolio::find($trade->portfolio_id);
         if ($portfolio->user_id == Auth::user()->id && $trade->is_active) {
             $profile = Profile::find($trade->profile_id);
             $trade->is_active = false;
             $trade->price_sold = $profile->current_price;
             $trade->save();
             $price = $profile->current_price * $trade->shares_taken;
             $portfolioRep->IncreaseBalance($portfolio, $price);
             return response()->json(array('success' => true, 'portfolioId' => $portfolio->id, 'price' => $price));
         }
     }
     return response()->json(array('success' => false));
 }