Пример #1
0
 public static void DecorateURLForYouTube(URL url, YouTube youTube)
 {
     url.Type = "youtube";
     url.Thumbnail = youTube.items[0].snippet.thumbnails["default"].url;
     url.Title = youTube.items[0].snippet.title;
     url.Description = youTube.items[0].snippet.description;
 }
Пример #2
0
        public void ProcessRequest(HttpContext context)
        {
            string json;

            try
            {
                var requestBody = context.Request.Form["RequestBody"];
                var requestParams = API.GetURLRequestParams(requestBody);
                var repo = new Repository();

                if (!repo.OnIgnore(requestParams.Nick, requestParams.ChannelID))
                {
                    URL url = new URL
                    {
                        At = DateTime.UtcNow,
                        Nick = requestParams.Nick,
                        URL1 = requestParams.URL,
                        FKChannelID = requestParams.ChannelID,
                        VoteCount = 0
                    };

                    if (requestParams.YouTube != null)
                    {
                        try
                        {
                            API.DecorateURLForYouTube(url, requestParams.YouTube);
                        }
                        catch (Exception)
                        {
                        }
                    }

                    int urlID = repo.URL(url);

                    json = JsonConvert.SerializeObject(new
                    {
                        success = true,
                        ID = urlID
                    });
                }
                else
                {
                    json = JsonConvert.SerializeObject(new
                    {
                        success = false,
                        error = "Ignored nick"
                    });
                }
            }
            catch (Exception ex)
            {
                json = JsonConvert.SerializeObject(new
                {
                    success = false,
                    error = "There was an exception: " + ex.Message
                });
            }

            SetNoCaching(context);
            context.Response.ContentType = "text/json";
            context.Response.Write(json);
        }
Пример #3
0
        /// <summary>
        /// Add a URL to the table. Calls SaveChanges() and returns the new URLID
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public int URL(URL url)
        {
            _context
                .URLs
                .Add(url);

            SaveChanges();
            AddURLUpdateHistory(url.URLID);
            SaveChanges();

            return url.URLID;
        }