public DatingBookUserInfo UpsertDatingBookUserInfo(string appName, ObjectId userId, DatingBookUserInfo datingBookUserInfo) { datingBookUserInfo = _userDataProvider.UpsertDatingbookUserInfo(appName, userId, datingBookUserInfo); if (datingBookUserInfo.IsNew) { if (!CheckIfUserPictureExist(appName, datingBookUserInfo)) DownloadUserPicture(appName, datingBookUserInfo); var userEventInfo = new UserEventInfo { UserId = datingBookUserInfo.ObjectId, EventType = 0, DateCreated = DateTime.Now }; _userDataProvider.InsertUserEvent(appName, userEventInfo); datingBookUserInfo.IsNew = false; } datingBookUserInfo.LastVisit = DateTime.Now; datingBookUserInfo = _userDataProvider.UpdateDatingBookLastVisit(appName, datingBookUserInfo); return datingBookUserInfo; }
public static bool CheckIfUserPictureExist(string appName, DatingBookUserInfo userInfo) { if (string.IsNullOrEmpty(userInfo.Picture)) return false; string pictureId = new Uri(userInfo.Picture).Segments[2]; var filePath = string.Format(@"c:\inetpub\wwwroot\images\{0}\{1}\{2}", appName, userInfo.FacebookUserId, pictureId); if (File.Exists(filePath)) return true; return false; }
public static void DownloadUserPicture(string appName, DatingBookUserInfo userInfo) { if (string.IsNullOrEmpty(userInfo.Picture)) return; var client = new RestClient(); var request = new RestRequest(userInfo.Picture, Method.GET); var response = client.Execute(request); var image = Image.FromStream(new MemoryStream(response.RawBytes)); var directoryPath = string.Format(@"c:\inetpub\wwwroot\images\{0}\{1}", appName, userInfo.FacebookUserId); if (!Directory.Exists(directoryPath)) Directory.CreateDirectory(directoryPath); string pictureId = new Uri(userInfo.Picture).Segments[2]; image.Save(Path.Combine(directoryPath, pictureId)); }
public DatingBookUserInfo UpsertDatingBookUserInfo(string appName, ObjectId userId, DatingBookUserInfo datingBookUserInfo) { datingBookUserInfo = _userDataProvider.UpsertDatingbookUserInfo(appName, userId, datingBookUserInfo); if (datingBookUserInfo.IsNew) { if (!CheckIfUserPictureExist(appName, datingBookUserInfo)) DownloadUserPicture(appName, datingBookUserInfo); var userEventInfo = new UserEventInfo { UserId = datingBookUserInfo.ObjectId, EventType = 0, DateCreated = DateTime.Now }; _userDataProvider.InsertUserEvent(appName, userEventInfo); datingBookUserInfo.IsNew = false; } datingBookUserInfo.LastVisit = DateTime.Now; ObjectId visitId = ObjectId.Empty; var whiteList = _userDataProvider.GetUsersWhitelist(appName); if (!whiteList.Exists((usr) => usr == datingBookUserInfo.FacebookId)) { BsonDocument visit = new BsonDocument(); visit.Add("dating_book_id", datingBookUserInfo.ObjectId); visit.Add("entered_at", datingBookUserInfo.LastVisit); visitId = _userDataProvider.InsertVisit(appName, visit); } datingBookUserInfo.LastVisit = DateTime.Now; datingBookUserInfo = _userDataProvider.UpdateDatingBookLastVisit(appName, datingBookUserInfo, visitId); return datingBookUserInfo; }
public static string GenerateUserProfilePictureUrl(string appName, DatingBookUserInfo userInfo, int width, int height) { if (string.IsNullOrEmpty(userInfo.Picture) || HttpContext.Current.Request.UserHostAddress == "127.0.0.1") { switch (userInfo.Gender) { case "girl": return string.Format(@"/images/local/empty_f.png?width={0}&height={1}&mode=crop&anchor=topcenter", width, height); case "boy": return string.Format(@"/images/local/empty_m.png?width={0}&height={1}&mode=crop&anchor=topcenter", width, height); default: return string.Format(@"/images/local/empty_m.png?width={0}&height={1}&mode=crop&anchor=topcenter", width, height); } } string imageProccessorUrlPattern = @"/images/local/{0}/{1}/{2}?width={3}&height={4}&mode=crop&anchor=topcenter"; string pictureId = new Uri(userInfo.Picture).Segments[2]; string imageUrl = string.Format(imageProccessorUrlPattern, appName, userInfo.FacebookUserId, pictureId, width, height); return imageUrl; }
public DatingBookUserInfo UpsertDatingbookUserInfo(string appName, ObjectId userId, DatingBookUserInfo datingBookUserInfo) { datingBookUserInfo.FacebookUserId = userId; datingBookUserInfo.DateModified = DateTime.Now; var dataBase = _serverWrapper.ServerConnection.GetDatabase(appName); var collection = dataBase.GetCollection<DatingBookUserInfo>(DATING_BOOK_USERS_COLLECTION_NAME); var userInfo = GetDatingBookUserInfoByFacebookId(appName, userId); if (userInfo == null) { datingBookUserInfo.DateCreated = DateTime.Now; datingBookUserInfo.IsNew = true; collection.Insert(datingBookUserInfo); } else { collection.Save(datingBookUserInfo); } return datingBookUserInfo; }
public DatingBookUserInfo UpdateDatingBookLastVisit(string appName, DatingBookUserInfo datingBookUserInfo, ObjectId visitId) { var dataBase = _serverWrapper.ServerConnection.GetDatabase(appName); var collection = dataBase.GetCollection<DatingBookUserInfo>(DATING_BOOK_USERS_COLLECTION_NAME); var selectQuery = Query.EQ("_id", datingBookUserInfo.ObjectId); collection.Update(selectQuery, Update.Set("last_visit", datingBookUserInfo.LastVisit).Set("last_visit_id", visitId)); return datingBookUserInfo; }