Ejemplo n.º 1
0
 public IActionResult Profile(string username = "")
 {
     if (HttpContext.Session.GetString("Username") != null)
     {
         try
         {
             if (HttpContext.Session.GetString("Username") == username)
             {
                 ViewBag.User = userRepository.GetUser(username);
                 return(View(collectionRepository.GetLists(ViewBag.User.ID)));
             }
             foreach (string friend in userRepository.GetUserFriendUsernames(HttpContext.Session.GetString("Username")))
             {
                 if (friend == username)
                 {
                     ViewBag.User = userRepository.GetUser(username);
                     return(View(collectionRepository.GetLists(ViewBag.User.ID)));
                 }
             }
             return(RedirectToAction("Profile", new { username = HttpContext.Session.GetString("Username") }));
         }
         catch (Exception e)
         {
             string message = e.Message;
             return(View("Error", "Database"));
         }
     }
     return(RedirectToAction("Login", "User"));
 }
        public IActionResult Index(string sortOrder)
        {
            ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            if (HttpContext.Session.Get("Username") != null)
            {
                userID = Convert.ToInt32(HttpContext.Session.GetInt32("UserID"));
                try
                {
                    IEnumerable <List> lists = new List <List>(collectionRepository.GetLists(userID));
                    switch (sortOrder)
                    {
                    case "name_desc":
                        lists = lists.OrderByDescending(s => s.Name);
                        break;

                    default:
                        lists = lists.OrderBy(s => s.Name);
                        break;
                    }

                    return(View(lists));
                }
                catch (Exception e)
                {
                    string message = e.Message;
                    return(View("Error", "Database"));
                }
            }
            return(RedirectToAction("Login", "User"));
        }
Ejemplo n.º 3
0
 public IActionResult Collection()
 {
     if (HttpContext.Session.Get("Username") != null)
     {
         ViewBag.Username = HttpContext.Session.GetString("Username");
         userID           = Convert.ToInt32(HttpContext.Session.GetInt32("UserID"));
         try
         {
             return(View(collectionRepository.GetLists(userID).OrderBy(s => s.Name)));
         }
         catch (Exception e)
         {
             string message = e.Message;
             return(View("Error", "Database"));
         }
     }
     return(RedirectToAction("Login", "User"));
 }