Exemplo n.º 1
0
        public async Task <ActionResult> Create(TorrentVM torrent)
        {
            if (!ModelState.IsValid)
            {
                return(View(torrent));
            }

            torrent.Uploader   = GetLoggedUserAsVM();
            torrent.Catalog    = new CatalogVM();
            torrent.Catalog.Id = torrent.CatalogId;
            torrent.SybType    = new SubtypeVM();
            torrent.SybType.Id = torrent.SubtypeId;

            try
            {
                using (var client = new HttpClient())
                {
                    var token = Base64Encode(HttpContext.Session.GetCurrentUserCredentials("loggedUser"));
                    client.DefaultRequestHeaders.Add(AUTHORIZATION_HEADER_NAME, token);

                    var serializedContent = JsonConvert.SerializeObject(torrent);
                    var stringContent     = new StringContent(serializedContent, Encoding.UTF8, JSON_MEDIA_TYPE);

                    HttpResponseMessage response = await client.PostAsync(torrentUri, stringContent);

                    if (!response.IsSuccessStatusCode)
                    {
                        return(RedirectToAction(nameof(HomeController.Error), "Home"));
                    }

                    if (GetLoggedUser() != null && GetLoggedUser().isAdmin)
                    {
                        return(RedirectToAction(nameof(Index)));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }
            catch
            {
                return(RedirectToAction(nameof(HomeController.Error), "Home"));
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Edit2(int id, TorrentVM torrent)
        {
            ViewBag.Subtypes = await GetSubtypeDropdownItemsAsync(torrent.CatalogId);

            return(View(torrent));
        }