Ejemplo n.º 1
0
        // GET:/Dashboard
        public ActionResult Index()
        {
            var userId = User.Identifier();

            this.GetCookie(userId);

            var dashboard = profileCore.Load <MyProfile>(userId);
            var profile   = profileCore.SearchSingle <MyProfile>(userId, null, userId);

            profile.Badges = badgeCore.Search(userId);

            if (null != profile)
            {
                profile.Items = itemCore.Search(userId, null, null, null, userId);

                var shares = this.borrowCore.Lent(userId);

                profile.PendingRequests = from br in shares
                                          where br.Status == BorrowStatus.Pending
                                          select br;

                profile.Lent = from br in shares
                               where br.Status == BorrowStatus.Accepted
                               select br;

                shares = this.borrowCore.Borrowed(userId);

                profile.BorrowRequests = from br in shares
                                         where br.Status == BorrowStatus.Pending
                                         select br;

                profile.Borrowed = from br in shares
                                   where br.Status == BorrowStatus.Accepted
                                   select br;

                profile.PendingTradeRequests = this.tradeCore.SearchItemTrade(userId);
                profile.TradeRequests        = this.tradeCore.SearchItemTrade(null, userId);

                this.LoadItems(profile.PendingRequests, true);
                this.LoadItems(profile.BorrowRequests);
                this.LoadItems(profile.Lent, true);
                this.LoadItems(profile.Borrowed);

                profile.FreeAsk       = this.LoadItems(freeCore.Search(userId), true) as IEnumerable <ItemFree>;
                profile.FreeRequested = this.LoadItems(freeCore.Search(null, userId)) as IEnumerable <ItemFree>;

                var fulfillments = from f in this.itemRequestCore.SearchFulfill(userId)
                                   where f.Status == RequestStatus.Pending
                                   select f;

                profile.FulfillMine = from f in fulfillments
                                      where f.IsMine
                                      select f;

                profile.FulfillOthers = from f in fulfillments
                                        where !f.IsMine
                                        select f;

                var rent = from r in this.rentCore.Rented(userId)
                           where r.Status != RentalStatus.Rejected &&
                           r.Status != RentalStatus.Returned
                           select r;
                rent = this.LoadItems(rent, true) as IEnumerable <ItemRental>;

                profile.RentAsks = from r in rent
                                   where r.Status == RentalStatus.Pending
                                   select r;

                profile.Renting = from r in rent
                                  where r.Status == RentalStatus.Accepted
                                  select r;

                rent = from r in this.rentCore.Requested(userId)
                       where r.Status != RentalStatus.Rejected &&
                       r.Status != RentalStatus.Returned
                       select r;
                rent = this.LoadItems(rent) as IEnumerable <ItemRental>;

                profile.RentRequests = from r in rent
                                       where r.Status == RentalStatus.Pending
                                       select r;

                profile.Rented = from r in rent
                                 where r.Status == RentalStatus.Accepted
                                 select r;

                dashboard.Info = profile;
            }

            return(View(dashboard));
        }