/// <summary> /// Syn avata from facebook site to phochungkhoan site /// </summary> /// <param name="idFacebook"></param> /// <returns></returns> public async static Task <bool> AvatarSyn(string idFacebook) { using (db = new testEntities()) { var getUserFacebook = await db.UserLogins.FirstOrDefaultAsync(u => u.IdFacebook == idFacebook); // facebok url to get avartar of user //https://graph.facebook.com/v2.3/1435015210144873/picture?type=large string urlFacebookAvatar = "https://graph.facebook.com/v2.3/" + idFacebook + "/picture?type=large"; WebClient webClient = new WebClient(); var uploadDir = "~/" + ImageURLAvata; #region delete old avata image string fullPath = HttpContext.Current.Server.MapPath(uploadDir) + getUserFacebook.AvataImage; if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } #endregion string NameFiletimeupload = getUserFacebook.KeyLogin + DateTime.Now.ToString("HHmmss") + "_avata"; //string JsonResult = webClient.DownloadString(urlFacebookAvatar); //JObject jsonUserInfo = JObject.Parse(JsonResult); //var urlData = jsonUserInfo.Value<dynamic>("data"); //string urlAvarta = urlData.Value<string>("url"); //Uri myURI4 = new Uri(urlAvarta); //var fi = new FileInfo(myURI4.AbsolutePath); //var ext = fi.Extension; var imagePath = Path.Combine(HttpContext.Current.Server.MapPath(uploadDir), NameFiletimeupload + ".jpg"); try // download and save facebook image of user into database { webClient.DownloadFile(urlFacebookAvatar, imagePath); getUserFacebook.AvataImage = NameFiletimeupload + ".jpg"; db.Entry(getUserFacebook).State = EntityState.Modified; await db.SaveChangesAsync(); } catch (Exception) { } return(true); } }
private void getListFilterFromDatabase(object state) { using (testEntities db = new testEntities()) { var listtemp = (from f in db.FilterKeyWords.ToList() select new { Word = f.KeyWord }).ToList(); if (listtemp.Count > 0) { listFilter.Clear(); listtemp.ForEach(t => listFilter.Add(t.Word)); } } //var listtemp = }
public static void Update(NotificationMessege notificationMessege) { using (db = new testEntities()) { notificationMessege.NumNoti += 1; notificationMessege.XemYN = true; notificationMessege.CreateDate = DateTime.Now; try { db.Entry(notificationMessege).State = EntityState.Modified; db.SaveChanges(); } catch (Exception) { } } }
public static List <string> GetListHotStock() { #region WebCache HotPrice List <string> result = WebCache.Get("HotPrice") as List <string>; if (result == null) { using (db = new testEntities()) { var resultCache = (from hoststock in db.TickerHots // danh sach co phieu nong trong db select hoststock.THName).ToListAsync(); result = resultCache.Result; WebCache.Set("HotPrice", result, 30, true); } } return(result); #endregion }
/// <summary> /// Create NotificationMessege /// </summary> /// <param name="userlogin"></param> user's Logging /// <param name="userReciver"></param> user reciver messege /// <param name="postedBy"></param> post id public static void Create(int userlogin, int userReciver, long postedBy) { using (db = new testEntities()) { NotificationMessege notificationMessege = new NotificationMessege(); notificationMessege.UserPost = userlogin; notificationMessege.UserReciver = userReciver; notificationMessege.PostId = postedBy; // default value of new notification notificationMessege.NumNoti = 1; notificationMessege.TypeNoti = "R"; notificationMessege.CreateDate = DateTime.Now; notificationMessege.XemYN = true; db.NotificationMesseges.Add(notificationMessege); try { db.SaveChanges(); } catch (Exception) { } } }