Esempio n. 1
0
        public async Task <ActionResult> CollectionDetails(Guid id)
        {
            HttpRequestMessage apiRequest = CreateRequestToService(HttpMethod.Get, $"Collections/{id}");

            HttpResponseMessage apiResponse;

            try
            {
                apiResponse = await HttpClient.SendAsync(apiRequest);
            }
            catch
            {
                return(RedirectToAction("MyCollections"));
            }

            if (!apiResponse.IsSuccessStatusCode)
            {
                return(RedirectToAction("MyCollections"));
            }

            CollectionViewModel collection = await apiResponse.Content.ReadAsAsync <CollectionViewModel>();

            await collection.InitBookmarksAsync();

            PassCookiesToClient(apiResponse);

            var user = await WhoAmI();

            if (collection.Private && (user == null || collection.OwnerId != user.Id))
            {
                TempData["Message"] = "Please log in.";
                return(RedirectToAction("Login", "Accounts"));
            }

            if (user == null)
            {
                return(View(collection));
            }

            if (collection.OwnerId == user.Id)
            {
                return(View("MyCollectionDetails", collection));
            }
            else
            {
                return(View(collection));
            }
        }