Example #1
0
        /// <summary>
        /// GET show profile
        /// </summary>
        /// <param name="userId">Userid to show</param>
        /// <returns>Action</returns>
        public ActionResult ShowProfile(string userId = null)
        {
            User userFromId = null;
            IList<Deal> deals = new List<Deal>();

            try
            {
                deals = dealDataAccess.GetAllDeals();

                if (userId != null)
                {
                    userFromId = memberDataAccess.GetUser(userId);
                }
            }
            catch (MemberDatabaseException)
            {
                log.Warn("Attempted to load profile for a non existant user {0}", userId);

                return this.PartialView("UserDoesNotExist");
            }
            catch (DealDatabaseException e)
            {
                log.Warn(e, "Could not load deals from the database");
            }

            if (string.IsNullOrEmpty(userName) && userId == null)
            {
                return PartialView("LogOn");
            }

            string notNullUser = userFromId == null ? userName : userFromId.UserName;

            List<Deal> userDeals = deals.Where(a => a.UserName.Equals(notNullUser, StringComparison.InvariantCultureIgnoreCase)).ToList();
            bool currentUser = notNullUser.Equals(userName, StringComparison.InvariantCultureIgnoreCase);

            log.Trace("Returning {0} deals for user {1} and current user is {2}", userDeals.Count, notNullUser, currentUser);

            UserDeals deal = new UserDeals
            {
                User = memberDataAccess.GetUser(notNullUser),
                Deals = userDeals.OrderByDescending(a => a.Date),
                IsCurrentUser = currentUser
            };

            return View(deal);
        }
Example #2
0
        /// <summary>
        /// GET profile summary
        /// </summary>
        /// <param name="userId">Userid to show</param>
        /// <returns>Action</returns>
        public ActionResult DealProfile(string userId = null)
        {
            User userFromId = null;

            if (userId != null)
            {
                try
                {
                    userFromId = memberDataAccess.GetUser(userId);
                }
                catch (MemberDatabaseException)
                {
                    log.Debug("Could not load user profile for requested user {0}", userId);
                }
            }

            if (string.IsNullOrEmpty(userName) && userFromId == null)
            {
                return View("DealProfileUserControl");
            }

            IList<Deal> userDeals = new List<Deal>();

            try
            {
                userDeals = dealDataAccess.GetAllDeals();
            }
            catch (DealDatabaseException)
            {
                log.Warn("Could not get list of deals for user profile");
            }

            string notNullUser = userFromId == null ? this.userName : userFromId.UserName;

            UserDeals deal = new UserDeals
                {
                    User = memberDataAccess.GetUser(notNullUser),
                    Deals = userDeals.Where(a => a.UserName.Equals(notNullUser)).OrderByDescending(a => a.Date),
                    IsCurrentUser = notNullUser.Equals(userName)
                };

            return PartialView(deal);
        }