/// <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); } }
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) { } } }