public void GetAdImages(HttpContext context) { var files = (from o in GetDataContext2.Ads orderby o.Priority select new { o.ID, o.Priority, o.Name, o.Image_Height, o.Image_Width, o.Url, cats = (from o1 in o.CategoryAdsMapping select new { o1.Category.Name, o1.Category.ID }) }).AsEnumerable().Select((o, i) => new { index = i, o.Priority, o.ID, title = o.Name, height = Math.Ceiling(190.00 * (Convert.ToDouble(o.Image_Height) / Convert.ToDouble(o.Image_Width))), file = Common.UploadedImageRelPath + o.Url, o.cats }); context.WriteJsonP(Newtonsoft.Json.JsonConvert.SerializeObject(files, Formatting.Indented, Common.JsonSerializerSettings)); }
public void GetCategories(HttpContext context) { var categories = (from o in all where o.ParentID == null select new Category { ID = o.ID, Name = o.Name, ParentID = o.ParentID }).AsEnumerable().Select((o, i) => new Category { index = i, ID = o.ID, Name = o.Name, SubCategories = SubCategories(o, all) }); context.WriteJsonP(JsonConvert.SerializeObject(categories, Formatting.Indented, Common.JsonSerializerSettings)); }
private void Default(HttpContext context) { List<object> files = new List<object>(); string cat = context.Request.QueryString["cat"]; string q = context.Request.QueryString["q"]; int p = int.Parse(context.Request.QueryString["p"]); string style = context.Request.QueryString["style"]; int ps = Common.PageSize; if (cat != null) { List<int> cats = new List<int>(); Action<IEnumerable<Category>> addSubCats = null; addSubCats = (subcats) => { foreach (var category in subcats) { cats.Add(category.ID); if (all.Any(o => o.ParentID == category.ID)) addSubCats(all.Where(o => o.ParentID == category.ID)); } }; addSubCats(all.Where(o => o.Name == cat)); if (cats.Any()) { var catimgs = Common.Compiled.CategoryImages(GetDataContext2, p, ps, string.Join(",", cats.ToArray()), style).Select((o, i) => new { o.ID, editable = false, o.BoardID, title = o.Image_Title, height = o.Image_Height, PinID = o.PinID.ToString(), imgsource = o.Source, width = o.Image_Width, comments = Common.XmlToJArray(o.Comments), bimid = o.BIMID, source = Common.GetAbsoluteUri(o.Source), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }); context.WriteJsonP(JsonConvert.SerializeObject(catimgs, Formatting.Indented, Common.JsonSerializerSettings)); } else context.WriteJsonP("[]"); return; } if (q != null) { var _q = Common.Compiled.Query(this.GetDataContext2, p, ps, q).Select((o, i) => new { o.ID, editable = false, o.BoardID, title = o.Image_Title, source = Common.GetAbsoluteUri(o.Source), imgsource = o.Source, width = o.Image_Width, comments = Common.XmlToJArray(o.Comments), o.BIMID, height = o.Image_Height, PinID = o.PinID.ToString(), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }); context.WriteJsonP(JsonConvert.SerializeObject(_q, Formatting.Indented, Common.JsonSerializerSettings)); return; } if (style != null) { context.WriteJsonP(JsonConvert.SerializeObject(Common.Compiled.ImagesStyle(this.GetDataContext2, style, p, ps).Select((o, i) => new { o.ID, editable = false, title = o.Image_Title, o.liked, o.BoardID, imgsource = o.Source, comments = Common.XmlToJArray(o.Comments), o.BIMID, width = o.Image_Width, source = Common.GetAbsoluteUri(o.Source), height = o.Image_Height, PinID = o.PinID.ToString(), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }).Randomize(), Formatting.Indented, Common.JsonSerializerSettings)); return; } context.WriteJsonP(JsonConvert.SerializeObject(Common.Compiled.Images(this.GetDataContext2, p, ps).Randomize().Select((o, i) => new { o.ID, editable = false, title = o.Image_Title, o.liked, o.BoardID, imgsource = o.Source, comments = Common.XmlToJArray(o.Comments), o.BIMID, width = o.Image_Width, source = Common.GetAbsoluteUri(o.Source), height = o.Image_Height, PinID = o.PinID.ToString(), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() //url = Common.GetBase64Image(Uri.UnescapeDataString(Path.Combine(Common.ImagePath, o.RelativeImage_Path.Replace("/", "\\"))), (short)(190.00 * o.Image_Height / o.Image_Width)) }), Formatting.Indented, Common.JsonSerializerSettings)); }
private void User(HttpContext context) { int? userId = Common.UserID; int? vuserid = Common.VUserID; List<object> files = new List<object>(); string cat = context.Request.QueryString["cat"]; string q = context.Request.QueryString["q"]; string filter = context.Request.QueryString["filter"]; string style = context.Request.QueryString["style"]; string board = context.Request.QueryString["board"]; int p = int.Parse(context.Request.QueryString["p"]); int ps = Common.PageSize; int adFreq = Common.AdFreq; int adps = ps / adFreq; int count, tmp = 0; if (board != null) { var imgs = Common.Compiled.BoardImages(this.GetDataContext2, p, ps, userId, board, vuserid.HasValue).Select((o, i) => new { title = o.Image_Title, editable = (!vuserid.HasValue) && (o.UserID == userId), o.ID, o.BoardID, height = o.Image_Height, PinID = o.PinID.ToString(), o.liked, width = o.Image_Width, imgsource = o.Source, comments = Common.XmlToJArray(o.Comments), o.BIMID, source = Common.GetAbsoluteUri(o.Source), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }); context.WriteJsonP(JsonConvert.SerializeObject(imgs, Formatting.Indented, Common.JsonSerializerSettings)); return; } if (filter != null) { if (filter == "likes") { var imgs = Common.Compiled.Likes(this.GetDataContext2, p, ps, userId, vuserid).Select((o, i) => new { title = o.Image_Title, editable = (!vuserid.HasValue) && (o.UserID == userId), o.ID, o.BoardID, height = o.Image_Height, PinID = o.PinID.ToString(), o.liked, width = o.Image_Width, imgsource = o.Source, comments = Common.XmlToJArray(o.Comments), o.BIMID, source = Common.GetAbsoluteUri(o.Source), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }); context.WriteJsonP(JsonConvert.SerializeObject(imgs, Formatting.Indented, Common.JsonSerializerSettings)); return; } if (filter == "pins") { var imgs = Common.Compiled.Pins(this.GetDataContext2, p, ps, userId, vuserid).Select((o, i) => new { title = o.Image_Title, editable = (!vuserid.HasValue) && (o.UserID == userId), o.ID, o.BoardID, width = o.Image_Width, height = o.Image_Height, PinID = o.PinID.ToString(), o.liked, imgsource = o.Source, comments = Common.XmlToJArray(o.Comments), o.BIMID, source = Common.GetAbsoluteUri(o.Source), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }); context.WriteJsonP(JsonConvert.SerializeObject(imgs, Formatting.Indented, Common.JsonSerializerSettings)); return; } } if (cat != null) { List<int> cats = new List<int>(); Action<IEnumerable<Category>> addSubCats = null; addSubCats = (subcats) => { foreach (var category in subcats) { cats.Add(category.ID); if (all.Any(o => o.ParentID == category.ID)) addSubCats(all.Where(o => o.ParentID == category.ID)); } }; addSubCats(all.Where(o => o.Name == cat)); if (cats.Any()) { var catimgs = Common.Compiled.CategoryImagesUser(GetDataContext2, p, ps, userId, string.Join(",", cats.ToArray()), style).Select((o, i) => new { title = o.Image_Title, editable = (!vuserid.HasValue) && (o.UserID == userId), o.ID, o.BoardID, height = o.Image_Height, PinID = o.PinID.ToString(), o.liked, width = o.Image_Width, imgsource = o.Source, comments = Common.XmlToJArray(o.Comments), o.BIMID, source = Common.GetAbsoluteUri(o.Source), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }).ToList<object>(); count = catimgs.Count; var catads = (from o in GetDataContext2.Ads join o1 in GetDataContext2.CategoryAdsMapping on o.ID equals o1.AdID where cats.Contains(o1.CategoryID) select new { height = o.Image_Height, width = o.Image_Width, title = o.Name, url = Common.UploadedImageRelPath + o.Url }).Skip(p * adps).Take(adps); var catadsEnumerator = catads.GetEnumerator(); while (tmp < count) { if ((++tmp) % adFreq != 0) continue; if (catadsEnumerator.MoveNext()) { catimgs.Insert(tmp, catadsEnumerator.Current); adFreq = Common.AdFreq; } } context.WriteJsonP(JsonConvert.SerializeObject(catimgs, Formatting.Indented, Common.JsonSerializerSettings)); } else context.WriteJsonP("[]"); return; } if (q != null) { var _q = Common.Compiled.QueryUser(this.GetDataContext2, p, ps, userId, q).Select((o, i) => new { o.ID, editable = (!vuserid.HasValue) && (o.UserID == userId), o.BoardID, o.liked, title = o.Image_Title, source = Common.GetAbsoluteUri(o.Source), imgsource = o.Source, width = o.Image_Width, comments = Common.XmlToJArray(o.Comments), o.BIMID, height = o.Image_Height, PinID = o.PinID.ToString(), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }); context.WriteJsonP(JsonConvert.SerializeObject(_q, Formatting.Indented, Common.JsonSerializerSettings)); return; } if (style != null) { context.WriteJsonP(JsonConvert.SerializeObject(Common.Compiled.ImagesStyle(this.GetDataContext2, style, p, ps).Select((o, i) => new { o.ID, editable = false, title = o.Image_Title, o.liked, o.BoardID, imgsource = o.Source, comments = Common.XmlToJArray(o.Comments), o.BIMID, width = o.Image_Width, source = Common.GetAbsoluteUri(o.Source), height = o.Image_Height, PinID = o.PinID.ToString(), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }).Randomize(), Formatting.Indented, Common.JsonSerializerSettings)); return; } var coll = Common.Compiled.Images(this.GetDataContext2, p, ps).Randomize().Select((o, i) => new { o.ID, editable = false, title = o.Image_Title, o.liked, o.BoardID, imgsource = o.Source, comments = Common.XmlToJArray(o.Comments), o.BIMID, width = o.Image_Width, source = Common.GetAbsoluteUri(o.Source), height = o.Image_Height, PinID = o.PinID.ToString(), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() //url = Common.GetBase64Image(Uri.UnescapeDataString(Path.Combine(Common.ImagePath, o.RelativeImage_Path.Replace("/", "\\"))), (short)(190.00 * o.Image_Height / o.Image_Width)) }).ToList<object>(); count = coll.Count; var ads = (from o in GetDataContext2.Ads orderby o.Priority select new { height = o.Image_Height, width = o.Image_Width, title = o.Name, url = Common.UploadedImageRelPath + o.Url }).Skip(p * adps).Take(adps); var adsEnumerator = ads.GetEnumerator(); while (tmp < count) { if ((++tmp) % adFreq != 0) continue; if (adsEnumerator.MoveNext()) { coll.Insert(tmp, adsEnumerator.Current); adFreq = Common.AdFreq; } } context.WriteJsonP(JsonConvert.SerializeObject(coll, Formatting.Indented, Common.JsonSerializerSettings)); }
private void GetQPeople(HttpContext context) { string name = context.Request.QueryString["name"]; Func<JObject, JObject> proc = o1 => { string path = Common.ContentUrl + (string)o1["RelativeImage_Path"]; o1["RelativeImage_Path"] = path; return o1; }; int cur_user = Convert.ToInt32(Common.UserID) > 0 ? Convert.ToInt32(Common.UserID) : 0; var FgUsers = (from f in GetDataContext2.Vw_User where f.Name.StartsWith(name) && (f.ID != cur_user) select new { F_FullName = f.FirstName, F_ID = f.ID, F_UserName = f.Name, F_Avatar = Common.FixAvatar(f.Avatar), Fg_Count = f.Following_Count, Fr_Count = f.Follower_Count, F_Pin = Common.XmlToJArray(GetDataContext2.ForXML_vw_UserPins(f.ID), proc), F_Status = GetDataContext2.FollowStatus(Common.UserID, f.ID) }); context.WriteJsonP(JsonConvert.SerializeObject(FgUsers, Formatting.Indented, Common.JsonSerializerSettings)); }
private void GetPin(HttpContext context) { string pin = context.Request.Params["pin"]; int? userID = Common.UserID; if (userID.HasValue) context.WriteJsonP(JsonConvert.SerializeObject((from o in GetDataContext2.Vw_Pin where o.PinID.Value.ToString() == pin select new { editable = o.UserID.HasValue && (o.UserID == userID), title = o.Image_Title, source = Common.GetAbsoluteUri(o.Source), imgsource = o.Source, Comments = Common.XmlToJArray(GetDataContext2.ForXML_vw_UserComments(o.BIMID)), o.BIMID, Contacts = Common.XmlToJArray(o.Contacts), width = o.Image_Width, height = o.Image_Height, url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }).First(), Formatting.Indented, Common.JsonSerializerSettings)); else context.WriteJsonP(JsonConvert.SerializeObject((from o in GetDataContext2.Vw_Pin where o.PinID.Value.ToString() == pin select new { title = o.Image_Title, source = Common.GetAbsoluteUri(o.Source), imgsource = o.Source, Comments = Common.XmlToJArray(GetDataContext2.ForXML_vw_UserComments(o.BIMID)), o.BIMID, Contacts = Common.XmlToJArray(o.Contacts), width = o.Image_Width, height = o.Image_Height, url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }).First(), Formatting.Indented, Common.JsonSerializerSettings)); }
private void GetImagesinUrl1(HttpContext context) { string url = context.Request.QueryString["url"]; Regex img = new Regex("<img.+?src=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase); Regex src = new Regex(@"src=(?:(['""])(?<src>(?:(?!\1).)*)\1|(?<src>[^\s>]+))", RegexOptions.IgnoreCase | RegexOptions.Singleline); WebClient source = new WebClient(); string value = source.DownloadString(new Uri(url)); if (!string.IsNullOrEmpty(value)) { MatchCollection matches = img.Matches(value); if (matches.Count > 0) { string rpath = Common.RelTemp + Common.UserID; string path = Common.Temp + Common.UserID; if (!Directory.Exists(path)) Directory.CreateDirectory(path); else { string[] files = Directory.GetFiles(path); foreach (string file in files) { File.Delete(file); } } int i = 0; Dictionary<int, bool> _dict = new Dictionary<int, bool>(); List<string> paths = new List<string>(); AsyncCompletedEventHandler callback = (sender, e) => { dynamic dyn = (dynamic)e.UserState; _dict[dyn.i] = true; string rfn = rpath + dyn.i + ".jpg"; paths.Add(rfn); }; foreach (Match match in matches) { string imgUrl = match.Groups[1].Value; WebClient client = new WebClient(); client.DownloadFileCompleted += callback; string fn = path + "\\" + i + ".jpg"; dynamic dyn = new ExpandoObject(); dyn.fn = fn; dyn.i = i; client.DownloadFileAsync(new Uri(imgUrl), fn, dyn); _dict.Add(i, false); i++; } while (_dict.ContainsValue(false)) Thread.Sleep(500); context.WriteJsonP(JsonConvert.SerializeObject(paths, Formatting.Indented, Common.JsonSerializerSettings)); } } }
private void GetFollowing(HttpContext context) { Func<JObject, JObject> proc = o1 => { string path = Common.ContentUrl + (string)o1["RelativeImage_Path"]; o1["RelativeImage_Path"] = path; return o1; }; var FgUsers = (from f in GetDataContext2.Vw_FollowingUser where f.UserID == (Common.VUserID ?? Common.UserID) select new { F_FullName = f.FullName, F_ID = f.FollowingID, F_UserName = f.UserName, F_Avatar = Common.FixAvatar(f.Avatar), Fg_Count = f.Following_Count, Fr_Count = f.Follower_Count, F_Pin = Common.XmlToJArray(f.Pins_XML, proc), F_Status = GetDataContext2.FollowStatus(Common.UserID, f.FollowingID), }); context.WriteJsonP(JsonConvert.SerializeObject(FgUsers, Formatting.Indented, Common.JsonSerializerSettings)); }
private void ValidateContributor(HttpContext context) { string contributor = context.Request.Params["contributor"]; Data.dbml.AppUsers user = this.GetDataContext2.AppUsers.FirstOrDefault(o => o.Email == contributor || o.Name == contributor); if (user != null) { if (user.ID == Common.UserID) context.Response.WriteError(strings.Contributor_Warn); else { context.WriteJsonP(JsonConvert.SerializeObject(new { user.Email, user.Avatar, Name = string.IsNullOrEmpty(user.FirstName) ? user.Name : user.FirstName, UN = user.Name })); } } else context.Response.WriteError(strings.User_Not_Exist); }
private void Upload1(HttpContext context) { string tpath = Common.Temp; if (!Directory.Exists(tpath)) Directory.CreateDirectory(tpath); HttpPostedFile file = context.Request.Files[0]; string nfn = Guid.NewGuid().ToString() + "." + file.FileName.Split('.')[1]; string fp = Common.RelTemp + "/" + nfn; file.SaveAs(tpath + "\\" + nfn); context.WriteJsonP(JsonConvert.SerializeObject(new { file = fp, fn = nfn })); }
private void User(HttpContext context, int userId) { List<object> files = new List<object>(); string cat = context.Request.QueryString["cat"]; string q = context.Request.QueryString["q"]; string filter = context.Request.QueryString["filter"]; string board = context.Request.QueryString["board"]; int p = int.Parse(context.Request.QueryString["p"]); int ps = Common.PageSize; PetaPoco.Sql sql; if (board != null) { var imgs = Common.Compiled.BoardImages(this.GetHairStyleContext2, p, ps, userId, board).Select((o, i) => new { title = o.Image_Title, editable = o.UserID == userId, o.ID, o.BoardID, height = o.Image_Height, PinID = o.PinID.ToString(), o.liked, width = o.Image_Width, imgsource = o.Source, cats = Common.XmlToJArray(o.Cats), comments = Common.XmlToJArray(o.Comments), o.BIMID, source = Common.GetAbsoluteUri(o.Source), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }); context.WriteJsonP(JsonConvert.SerializeObject(imgs, Formatting.Indented, Common.JsonSerializerSettings)); return; } if (filter != null) { if (filter == "likes") { var imgs = Common.Compiled.Likes(this.GetHairStyleContext2, p, ps, userId).Select((o, i) => new { title = o.Image_Title, editable = o.UserID == userId, o.ID, o.BoardID, height = o.Image_Height, PinID = o.PinID.ToString(), o.liked, width = o.Image_Width, imgsource = o.Source, cats = Common.XmlToJArray(o.Cats), comments = Common.XmlToJArray(o.Comments), o.BIMID, source = Common.GetAbsoluteUri(o.Source), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }); context.WriteJsonP(JsonConvert.SerializeObject(imgs, Formatting.Indented, Common.JsonSerializerSettings)); return; } if (filter == "pins") { var imgs = Common.Compiled.Pins(this.GetHairStyleContext2, p, ps, userId).Select((o, i) => new { title = o.Image_Title, editable = o.UserID == userId, o.ID, o.BoardID, width = o.Image_Width, height = o.Image_Height, PinID = o.PinID.ToString(), o.liked, imgsource = o.Source, cats = Common.XmlToJArray(o.Cats), comments = Common.XmlToJArray(o.Comments), o.BIMID, source = Common.GetAbsoluteUri(o.Source), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }); context.WriteJsonP(JsonConvert.SerializeObject(imgs, Formatting.Indented, Common.JsonSerializerSettings)); return; } } if (cat != null) { var catimgs = Common.Compiled.CategoryImagesUser(GetHairStyleContext2, p, ps, userId, cat).Select((o, i) => new { title = o.Image_Title, editable = o.UserID == userId, o.ID, o.BoardID, height = o.Image_Height, PinID = o.PinID.ToString(), o.liked, width = o.Image_Width, imgsource = o.Source, cats = Common.XmlToJArray(o.Cats), comments = Common.XmlToJArray(o.Comments), o.BIMID, source = Common.GetAbsoluteUri(o.Source), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }); context.WriteJsonP(JsonConvert.SerializeObject(catimgs, Formatting.Indented, Common.JsonSerializerSettings)); return; } if (q != null) { var _q = Common.Compiled.QueryUser(this.GetHairStyleContext2, p, ps, userId, q).Select((o, i) => new { o.ID, editable = o.UserID == userId, o.BoardID, o.liked, title = o.Image_Title, source = Common.GetAbsoluteUri(o.Source), imgsource = o.Source, width = o.Image_Width, cats = Common.XmlToJArray(o.Cats), comments = Common.XmlToJArray(o.Comments), o.BIMID, height = o.Image_Height, PinID = o.PinID.ToString(), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }); context.WriteJsonP(JsonConvert.SerializeObject(_q, Formatting.Indented, Common.JsonSerializerSettings)); return; } context.WriteJsonP(JsonConvert.SerializeObject(Common.Compiled.ImagesUsers(this.GetHairStyleContext2, p, ps , userId).Select((o, i) => new { o.ID, editable = false, title = o.Image_Title, o.liked, o.BoardID, imgsource = o.Source, cats = Common.XmlToJArray(o.Cats), comments = Common.XmlToJArray(o.Comments), o.BIMID, width = o.Image_Width, source = Common.GetAbsoluteUri(o.Source), height = o.Image_Height, PinID = o.PinID.ToString(), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }).Randomize(), Formatting.Indented, Common.JsonSerializerSettings)); }
private void GetPin(HttpContext context) { string pin = context.Request.Params["pin"]; var imageUrl = (from o in GetHairStyleContext2.Vw_Images where o.PinID.Value.ToString() == pin select new { o.ID, o.BoardID, title = o.Image_Title, source = Common.GetAbsoluteUri(o.Source), imgsource = o.Source, cats = Common.XmlToJArray(o.Cats), comments = Common.XmlToJArray(o.Comments), o.BIMID, width = o.Image_Width, url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }).First(); context.WriteJsonP(JsonConvert.SerializeObject(imageUrl, Formatting.Indented, Common.JsonSerializerSettings)); }
private void GetCategoriesandBoards(HttpContext context) { var categories = (from o in all where o.ParentID == null select o).AsEnumerable().Select((o, i) => new { index = i, ID = o.ID, Name = o.Name, SubCategories = SubCategories(o, all) }); //List<object> boards = new List<object>(); var boards = (from o in GetHairStyleContext2.Boards where o.UserID == Common.UserID || (from o1 in this.GetHairStyleContext2.BoardContributor where o1.ContributorID == Common.UserID select o1.BoardID).Contains(o.ID) select new { o.ID, o.Name }).Distinct(); int points = GetHairStyleContext2.AppUsers.Single(o => o.ID == Common.UserID).Points ?? 0; context.WriteJsonP(JsonConvert.SerializeObject(new { categories, boards, points }, Formatting.Indented, Common.JsonSerializerSettings)); }
private void Default(HttpContext context) { List<object> files = new List<object>(); string cat = context.Request.QueryString["cat"]; string q = context.Request.QueryString["q"]; int p = int.Parse(context.Request.QueryString["p"]); int ps = Common.PageSize; if (cat != null) { var catimgs = Common.Compiled.CategoryImages(GetHairStyleContext2, p, ps, cat).Select((o, i) => new { o.ID, editable = false, o.BoardID, title = o.Image_Title, height = o.Image_Height, PinID = o.PinID.ToString(), imgsource = o.Source, width = o.Image_Width, cats = Common.XmlToJArray(o.Cats), comments = Common.XmlToJArray(o.Comments), bimid = o.BIMID, source = Common.GetAbsoluteUri(o.Source), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }); context.WriteJsonP(JsonConvert.SerializeObject(catimgs, Formatting.Indented, Common.JsonSerializerSettings)); return; } if (q != null) { var _q = Common.Compiled.Query(this.GetHairStyleContext2, p, ps, q).Select((o, i) => new { o.ID, editable = false, o.BoardID, title = o.Image_Title, source = Common.GetAbsoluteUri(o.Source), imgsource = o.Source, width = o.Image_Width, cats = Common.XmlToJArray(o.Cats), comments = Common.XmlToJArray(o.Comments), o.BIMID, height = o.Image_Height, PinID = o.PinID.ToString(), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }); context.WriteJsonP(JsonConvert.SerializeObject(_q, Formatting.Indented, Common.JsonSerializerSettings)); return; } //CachedMashups(context, ps, p); context.WriteJsonP(JsonConvert.SerializeObject(Common.Compiled.Images(this.GetHairStyleContext2, p, ps ).Select((o, i) => new { o.ID, editable = false, title = o.Image_Title, o.liked, o.BoardID, imgsource = o.Source, cats = Common.XmlToJArray(o.Cats), comments = Common.XmlToJArray(o.Comments), o.BIMID, width = o.Image_Width, source = Common.GetAbsoluteUri(o.Source), height = o.Image_Height, PinID = o.PinID.ToString(), url = ((o.Uploaded ?? false) ? Common.UploadedImageRelPath : Common.ContentUrl) + o.RelativeImage_Path.Trim() }).Randomize(), Formatting.Indented, Common.JsonSerializerSettings)); }
private void AddComment(HttpContext context) { string comments = context.Request.Params["comments"]; int id = int.Parse(context.Request.Params["id"]); Data.dbml.Comments c = new Data.dbml.Comments(); c.Comment = comments; c.BoardsImagesMappingID = id; c.UserID = Common.UserID.Value; Data.dbml.AppUsers user = this.GetDataContext2.AppUsers.Single(o => o.ID == Common.UserID); this.GetDataContext2.Comments.InsertOnSubmit(c); this.GetDataContext2.SubmitChanges(); context.WriteJsonP(JsonConvert.SerializeObject(new { Comment = comments, Name = user.FirstName, Avatar = user.Avatar, UN = user.Name })); }
private void GetBoards(HttpContext context) { var boards = Common.Compiled.Boards(GetDataContext2, (Common.VUserID ?? Common.UserID)); context.WriteJsonP(JsonConvert.SerializeObject(boards, Formatting.Indented, Common.JsonSerializerSettings)); }
private void Review(HttpContext context) { string answer = context.Request.Params["ans"]; string question = context.Request.Params["ques"]; int bimid = int.Parse(context.Request.Params["bimid"]); Data.dbml.Review review = GetDataContext2.Review.FirstOrDefault(o => o.BIMID == bimid && (o.UserID == Common.UserID || o.SessionID == Common.SessionID)); if (review == null) { review = new Data.dbml.Review(); review.Answer = answer; review.BIMID = bimid; review.Question = question; review.UserID = Common.UserID; review.SessionID = Common.SessionID; GetDataContext2.Review.InsertOnSubmit(review); if (Common.UserID.HasValue) { GetDataContext1.Update(new Data.POCOS.AppUser() { ID = Common.UserID.Value, Points = Common.Points }, new[] { "Points" }); } } else { review.Answer = answer; review.Question = question; } GetDataContext2.SubmitChanges(); var q = from o in GetDataContext2.Review where (o.UserID == Common.UserID || o.SessionID == Common.SessionID) select o.BIMID; context.WriteJsonP(JsonConvert.SerializeObject(q)); }
private void GetFollowStatus(HttpContext context) { var Flst = (bool)GetDataContext2.FollowStatus(Common.UserID, Common.VUserID); context.WriteJsonP(JsonConvert.SerializeObject(Flst, Formatting.Indented, Common.JsonSerializerSettings)); }
private void SaveAddedPin(HttpContext context) { int board = int.Parse(context.Request.Params["board"]); string desc = context.Request.Params["desc"]; string img = context.Request.Params["img"]; string destRel = Common.UploadedImageRelPath + Common.UserID; string dest = Common.UploadedImagePath + Common.UserID; string destFileName = Guid.NewGuid().ToString() + ".jpg"; string destFileFullPath = Path.Combine(dest, destFileName); WebClient client = new WebClient(); MemoryStream ms = new MemoryStream(client.DownloadData(img)); using (Image image = Image.FromStream(ms)) { if (!Directory.Exists(dest)) Directory.CreateDirectory(dest); image.Save(destFileFullPath, ImageFormat.Jpeg); } string relPath = Common.UserID + "/" + destFileName; byte[] _d = File.ReadAllBytes(destFileFullPath); ulong _crc64; ulong _murmur2; ulong _fnv1a; short height, width; int imageID = 0; CalcHash(_d, out _crc64, out _murmur2, out _fnv1a, out height, out width); using (TransactionScope scope = new TransactionScope()) { try { Data.dbml.DataContext _context = this.GetDataContext2; var imgtb = _context.Images.Where(o => o.FNV1a == _fnv1a).FirstOrDefault(); var theboard = _context.Boards.Where(o => o.ID == board).Single(); if (imgtb == null) //only one image entry can exists { Data.dbml.Images i = new Data.dbml.Images(); i.CRC64 = _crc64; i.MURMUR2 = _murmur2; i.Tagged = true; i.FNV1a = _fnv1a; i.Image_Height = height; i.Image_Width = width; i.Uploaded = true; i.RelativeImage_Path = relPath; _context.Images.InsertOnSubmit(i); _context.SubmitChanges(); imageID = i.ID; } else { imageID = imgtb.ID; } Data.dbml.BoardsImagesMapping bim = new Data.dbml.BoardsImagesMapping(); bim.BoardID = board; bim.ImageID = imageID; bim.Image_Title = desc; bim.Source = img; bim.UserID = Common.UserID.Value; _context.BoardsImagesMapping.InsertOnSubmit(bim); Data.dbml.CategoryImagesMapping cim = new Data.dbml.CategoryImagesMapping(); cim.CategoryID = theboard.CatID; cim.ImageID = imageID; _context.CategoryImagesMapping.InsertOnSubmit(cim); UpdatePoints(Common.PointsNewPin); _context.SubmitChanges(); UpdateUPCount(); scope.Complete(); context.WriteJsonP(JsonConvert.SerializeObject(new { PinID = (_crc64 + (ulong)bim.ID).ToString() })); } catch (Exception e) { throw; } finally { scope.Dispose(); } } }
private void GetImagesinUrl2(HttpContext context) { string url = context.Request.QueryString["url"]; WebRequest source = WebRequest.Create(url); WebResponse res = source.GetResponse(); byte[] data = Common.ReadFully(res.GetResponseStream(), 0); string value = Encoding.UTF8.GetString(data); if (!string.IsNullOrEmpty(value)) { if (res.ContentType.Contains("text/html")) { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(value); var NoAltElements = doc.DocumentNode.SelectNodes("//img"); int i = 0; List<string> paths = new List<string>(); if (NoAltElements != null) { foreach (HtmlNode HN in NoAltElements) { string imgUrl = HN.GetAttributeValue("src", ""); if (imgUrl != "") paths.Add(Common.MakeAbsoluteUri(url, imgUrl)); } context.WriteJsonP(JsonConvert.SerializeObject(paths, Formatting.Indented, Common.JsonSerializerSettings)); } } else context.WriteJsonP(JsonConvert.SerializeObject(new string[] { url }, Formatting.Indented, Common.JsonSerializerSettings)); } }
private void SaveCreatedBoard(HttpContext context) { string name = context.Request.Params["name"].Trim(); Data.dbml.Boards b = this.GetDataContext2.Boards.FirstOrDefault(o => o.Name == name && o.UserID == Common.UserID); if (b != null) context.Response.WriteError(strings.ErrSameBoardName); else { int catid = int.Parse(context.Request.Params["catid"]); string contributors = context.Request.Params["contributors[]"]; Data.dbml.Boards board = new Data.dbml.Boards() { Name = name, CatID = catid, UserID = Common.UserID.Value }; this.GetDataContext2.Boards.InsertOnSubmit(board); this.GetDataContext2.SubmitChanges(); if (!string.IsNullOrEmpty(contributors)) { string[] acontributors = contributors.Split(','); foreach (string contributor in acontributors) { this.GetDataContext2.BoardContributor.InsertOnSubmit(new Data.dbml.BoardContributor() { BoardID = board.ID, ContributorID = GetDataContext2.AppUsers.First(o => o.Email == contributor).ID }); } this.GetDataContext2.SubmitChanges(); } UpdatePoints(Common.PointsNewBoard); this.GetDataContext2.SubmitChanges(); UpdateUPCount(); context.WriteJsonP(JsonConvert.SerializeObject(new { boards = (from o in GetDataContext2.Boards where o.UserID == Common.UserID || (from o1 in this.GetDataContext2.BoardContributor where o1.ContributorID == Common.UserID select o1.BoardID).Contains(o.ID) select new { o.ID, o.Name }).Distinct() })); } }
private void GetLoggedinLoadData(HttpContext context) { //List<object> boards = new List<object>(); var boards = (from o in GetDataContext2.Boards where o.UserID == Common.UserID || (from o1 in this.GetDataContext2.BoardContributor where o1.ContributorID == Common.UserID select o1.BoardID).Contains(o.ID) select new { o.ID, o.Name }).Distinct(); string about = (from o in GetDataContext2.AppUsers where o.ID == Common.UserID select o.About).First(); context.WriteJsonP(JsonConvert.SerializeObject(new { boards, about }, Formatting.Indented, Common.JsonSerializerSettings)); }
private void SaveUploadedPin(HttpContext context) { int board = int.Parse(context.Request.Params["board"]); string desc = context.Request.Params["desc"]; string img = context.Request.Params["img"]; IHash fnv1a = HashFactory.Hash64.CreateFNV1a(); IHash crc64 = HashFactory.Checksum.CreateCRC64b(); IHash murmur2 = HashFactory.Hash64.CreateMurmur2(); Uri url = new Uri(img); string image = url.Segments.Last(); string fp = Path.Combine(Common.Temp, Common.UserID.ToString(), image); FileInfo fInfo = new FileInfo(fp); string destRel = Common.UploadedImageRelPath + Common.UserID; string dest = Common.UploadedImagePath + Common.UserID; string destFileName = Common.MoveAndRenameFileIfExists(fInfo, dest); string relPath = Common.UserID + "/" + destFileName; byte[] _d = File.ReadAllBytes(Path.Combine(dest, destFileName)); ulong _crc64; ulong _murmur2; ulong _fnv1a; short height, width; int imageID = 0; CalcHash(_d, out _crc64, out _murmur2, out _fnv1a, out height, out width); using (TransactionScope scope = new TransactionScope()) { try { Data.dbml.DataContext _context = this.GetDataContext2; var imgtb = _context.Images.Where(o => o.FNV1a == _fnv1a && o.CRC64 == _crc64 && o.MURMUR2 == _murmur2).FirstOrDefault(); var theboard = _context.Boards.Where(o => o.ID == board).Single(); if (imgtb == null) //only one image entry can exists { Data.dbml.Images i = new Data.dbml.Images(); i.CRC64 = _crc64; i.MURMUR2 = _murmur2; i.FNV1a = _fnv1a; i.Image_Height = height; i.Image_Width = width; i.Uploaded = true; i.Tagged = true; i.RelativeImage_Path = relPath; _context.Images.InsertOnSubmit(i); _context.SubmitChanges(); imageID = i.ID; } else { imageID = imgtb.ID; } Data.dbml.BoardsImagesMapping bim = new Data.dbml.BoardsImagesMapping(); bim.BoardID = board; bim.ImageID = imageID; bim.Image_Title = desc; bim.UserID = Common.UserID; _context.BoardsImagesMapping.InsertOnSubmit(bim); Data.dbml.CategoryImagesMapping cim = new Data.dbml.CategoryImagesMapping(); cim.CategoryID = theboard.CatID; cim.ImageID = imageID; _context.CategoryImagesMapping.InsertOnSubmit(cim); UpdatePoints(Common.PointsNewPin); _context.SubmitChanges(); UpdateUPCount(); scope.Complete(); context.WriteJsonP(JsonConvert.SerializeObject(new { PinID = ((ulong)bim.ID + _crc64).ToString() })); } catch (Exception e) { throw; } finally { scope.Dispose(); } } }
private void GetQBoards(HttpContext context) { string name = context.Request.QueryString["name"]; var boards = Common.Compiled.QBoards(GetDataContext2, name); context.WriteJsonP(JsonConvert.SerializeObject(boards, Formatting.Indented, Common.JsonSerializerSettings)); }
private void UpdatePrize(HttpContext context) { Random rnd = new Random(); double angle = rnd.Next(45, 360); var prize = (from r in GetDataContext2.Roulette join p in GetDataContext2.Prize on r.PrizeID equals p.ID where (r.End_Angle >= angle && r.Start_Angle <= angle) select new { r.PrizeID, p.Prize_Name, p.User_Alert }).First(); var user = GetDataContext2.AppUsers.First(o => o.ID == Common.UserID); int user_points = Convert.ToInt32(user.Points); int rwpointded = Common.RWPointsDed; if (user_points >= rwpointded) { user_points = user_points - rwpointded; Common.WriteValue(Common.InfoCookie, JObject.FromObject(new { points = user_points })); user.Points = user_points + PrizeValue(prize.Prize_Name); GetDataContext2.SubmitChanges(); GetDataContext2.PrizeHistory.InsertOnSubmit(new Data.dbml.PrizeHistory() { PrizeID = prize.PrizeID, UserID = Common.UserID.Value, Create_date = DateTime.Now }); GetDataContext2.SubmitChanges(); context.WriteJsonP(JsonConvert.SerializeObject(new { angle = angle, alert = prize.User_Alert, points = user.Points }, Formatting.Indented, Common.JsonSerializerSettings)); } else { context.Response.WriteError(string.Format(misc.NoPointsAlert, rwpointded)); } }
private void GetStores(HttpContext context) { int p = int.Parse(context.Request.QueryString["p"]); int ps = Common.PageSize; var _q = (from o in this.GetDataContext2.Stores select new { o.ID, o.RelImagePath, o.Title, o.Url, o.Image_Height, o.Image_Width }).OrderByDescending(o => o.ID).Skip(p * ps).Take(ps).AsEnumerable().Select((o, i) => new { url = Common.ContentUrl + o.RelImagePath, title = o.Title, source = o.Url, height = Math.Ceiling(190.00 * (Convert.ToDouble(o.Image_Height) / Convert.ToDouble(o.Image_Width))) }); context.WriteJsonP(JsonConvert.SerializeObject(_q, Formatting.Indented, Common.JsonSerializerSettings)); }
public void GetPages(HttpContext context) { int count; string s = context.Request.QueryString["s"]; if (string.IsNullOrEmpty(s)) { string q; count = (from o in this.GetDataContext2.Vw_Images4Tagging where o.UserID == Common.UserID select new { o.ID, o.Image_Height, o.Image_Width, o.RelativeImage_Path }).Distinct().Count(); q = string.Format("Select TOP 1 SlNO from (Select distinct Row_Number() over (order by Tagged desc,ID) as SlNO,Tagged from vw_Images4Tagging where UserID={0}) as tmp where (tmp.Tagged IS NULL or tmp.Tagged=0)", Common.UserID); long? index = (long?)SqlHelper.ExecuteScalar(Common.DataConnectionString, CommandType.Text, q); int ps = int.Parse(context.Request.QueryString["ps"]); var categories = (from o in this.GetDataContext2.Category where o.ParentID == null select new Category { ID = o.ID, Name = o.Name, ParentID = o.ParentID }).AsEnumerable().Select((o, i) => new { index = i, ID = o.ID, Name = o.Name, SubCategories = SubCategories(o, all) }); context.WriteJsonP(JsonConvert.SerializeObject(new { categories = categories, pages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(count) / Convert.ToDouble(ps))), currentpage = index.HasValue && index > ps ? (Math.Floor((Convert.ToDouble(index) / Convert.ToDouble(ps)))) + 1 : 1 }, Formatting.Indented, Common.JsonSerializerSettings)); } else { s = Common.MakeRelativeUri(Common.ContentUrl, Uri.UnescapeDataString(s)).TrimStart('/'); string q; count = (from o in this.GetDataContext2.Vw_Images4Tagging where o.UserID == Common.UserID && o.RelativeImage_Path == s select new { o.ID, o.Image_Height, o.Image_Width, o.RelativeImage_Path }).Distinct().Count(); q = string.Format("Select TOP 1 SlNO from (Select distinct Row_Number() over (order by Tagged desc,ID) as SlNO,Tagged from vw_Images4Tagging where UserID={0} and RelativeImage_Path = '{1}') as tmp where (tmp.Tagged IS NULL or tmp.Tagged=0)", Common.UserID, s); long? index = (long?)SqlHelper.ExecuteScalar(Common.DataConnectionString, CommandType.Text, q); int ps = int.Parse(context.Request.QueryString["ps"]); var categories = (from o in this.GetDataContext2.Category where o.ParentID == null select new Category { ID = o.ID, Name = o.Name, ParentID = o.ParentID }).AsEnumerable().Select((o, i) => new Category { index = i, ID = o.ID, Name = o.Name, SubCategories = SubCategories(o, all) }); context.WriteJsonP(JsonConvert.SerializeObject(new { categories = categories, pages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(count) / Convert.ToDouble(ps))), currentpage = index.HasValue && index > ps ? (Math.Floor((Convert.ToDouble(index) / Convert.ToDouble(ps)))) + 1 : 1 }, Formatting.Indented, Common.JsonSerializerSettings)); } }
public void GetImagesAndCategoriesPaged(HttpContext context) { string cat = context.Request.QueryString["cat"]; int start = int.Parse(context.Request.QueryString["start"]); int page = int.Parse(context.Request.QueryString["page"]); object files = null; string s = context.Request.QueryString["s"]; if (!string.IsNullOrEmpty(s)) { s = Common.MakeRelativeUri(Common.ContentUrl, Uri.UnescapeDataString(s)).TrimStart('/'); files = (from o in this.GetDataContext2.Vw_Images4Tagging where o.UserID == Common.UserID && o.RelativeImage_Path == s orderby o.Rating descending select new { o.ID, o.Tagged, o.Image_Height, o.Image_Title, o.Image_Width, o.RelativeImage_Path }).Distinct().Skip(start).Take(page).AsEnumerable().Select((o, i) => new { index = i, ID = o.ID, title = o.Image_Title, height = Math.Ceiling(190.00 * (Convert.ToDouble(o.Image_Height) / Convert.ToDouble(o.Image_Width))), file = o.RelativeImage_Path, contenturl = Common.ContentUrl, cat = (from o1 in this.GetDataContext2.Vw_ImgCategory where o1.ID == o.ID select o1).AsEnumerable().Select((o2, i1) => new { index = i1, o2.CategoryID, o2.Name }) }); context.WriteJsonP(Newtonsoft.Json.JsonConvert.SerializeObject(files, Formatting.Indented, Common.JsonSerializerSettings)); return; } if (!string.IsNullOrEmpty(cat)) { cat = Uri.UnescapeDataString(cat); files = (from o in this.GetDataContext2.Vw_Images4Tagging where o.UserID == Common.UserID && o.CategoryName == cat orderby o.Rating descending select new { o.ID, o.Tagged, o.Image_Title, o.Image_Height, o.Image_Width, o.RelativeImage_Path }).Skip(start).Take(page).AsEnumerable().Select((o, i) => new { index = i, ID = o.ID, title = o.Image_Title, height = Math.Ceiling(190.00 * (Convert.ToDouble(o.Image_Height) / Convert.ToDouble(o.Image_Width))), file = o.RelativeImage_Path, contenturl = Common.ContentUrl, cat = (from o1 in this.GetDataContext2.Vw_ImgCategory where o1.ID == o.ID select o1).AsEnumerable().Select((o2, i1) => new { index = i1, o2.CategoryID, o2.Name }) }); context.WriteJsonP(Newtonsoft.Json.JsonConvert.SerializeObject(files, Formatting.Indented, Common.JsonSerializerSettings)); return; } files = (from o in this.GetDataContext2.Vw_Images4Tagging where o.UserID == Common.UserID orderby o.Rating descending select new { o.ID, o.Tagged, o.Image_Title, o.Image_Height, o.Image_Width, o.RelativeImage_Path }).Skip(start).Take(page).AsEnumerable().Select((o, i) => new { index = i, ID = o.ID, title = o.Image_Title, height = Math.Ceiling(190.00 * (Convert.ToDouble(o.Image_Height) / Convert.ToDouble(o.Image_Width))), file = o.RelativeImage_Path, contenturl = Common.ContentUrl, cat = (from o1 in this.GetDataContext2.Vw_ImgCategory where o1.ID == o.ID select o1).AsEnumerable().Select((o2, i1) => new { index = i1, o2.CategoryID, o2.Name }) }); context.WriteJsonP(Newtonsoft.Json.JsonConvert.SerializeObject(files, Formatting.Indented, Common.JsonSerializerSettings)); }
private void GetArticles(HttpContext context) { string cat = context.Request.QueryString["cat"]; string q = context.Request.QueryString["q"]; int p = int.Parse(context.Request.QueryString["p"]); int ps = Common.PageSize; var _q = (from o in this.GetPindexProdContext2.Articles select new { o.ID, o.Description, o.ArticleContent, o.RelImagePath, o.Title, o.Url, o.Image_Height, o.Image_Width }).OrderByDescending(o => o.ID).Skip(p * ps).Take(ps).AsEnumerable().Select((o, i) => new { url = Common.ContentUrl + o.RelImagePath, title = o.Title, content = o.ArticleContent, desc = o.Description, source = o.Url, height = Math.Ceiling(380.00 * (Convert.ToDouble(o.Image_Height) / Convert.ToDouble(o.Image_Width))) }); context.WriteJsonP(JsonConvert.SerializeObject(_q, Formatting.Indented, Common.JsonSerializerSettings)); }