/// <summary> /// Set if shows have been seen or set as favorite /// </summary> /// <param name="shows">All shows to compute</param> public async Task SyncShowHistoryAsync(IEnumerable<IShow> shows) { var watch = Stopwatch.StartNew(); try { User = await GetUser().ConfigureAwait(false); foreach (var show in shows) { var updatedShow = User.ShowHistory.FirstOrDefault(p => p.ImdbId == show.ImdbId); if (updatedShow == null) continue; show.IsFavorite = updatedShow.Favorite; } } catch (Exception exception) { Logger.Error( $"SyncShowHistoryAsync: {exception.Message}"); } finally { watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Logger.Debug( $"SyncShowHistoryAsync in {elapsedMs} milliseconds."); } }
public bool UpdateUser(Models.User.User user) { bool isUpdate = true; using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString)) { SqlCommand command = new SqlCommand(StoreProcedure.UPDATEUSER, connection); command.CommandType = CommandType.StoredProcedure; foreach (var users in user.GetType().GetProperties()) { string name = users.Name; var value = users.GetValue(user, null); command.Parameters.Add(new SqlParameter("@" + name, value == null ? DBNull.Value : value)); } try { connection.Open(); command.ExecuteNonQuery(); } catch (Exception e) { isUpdate = false; throw new Exception("Exception Updating Data." + e.Message); } finally { connection.Close(); } } return isUpdate; }
/// <summary> /// Set if movies have been seen or set as favorite /// </summary> /// <param name="movies">All movies to compute</param> public async Task SyncMovieHistoryAsync(IEnumerable<IMovie> movies) { var watch = Stopwatch.StartNew(); try { User = await GetUser().ConfigureAwait(false); foreach (var movie in movies) { var updatedMovie = User.MovieHistory.FirstOrDefault(p => p.ImdbId == movie.ImdbCode); if (updatedMovie == null) continue; movie.IsFavorite = updatedMovie.Favorite; movie.HasBeenSeen = updatedMovie.Seen; } } catch (Exception exception) { Logger.Error( $"SyncMovieHistoryAsync: {exception.Message}"); } finally { watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Logger.Debug( $"SyncMovieHistoryAsync in {elapsedMs} milliseconds."); } }
public Models.User.User GetUserById(long userID) { using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString)) { SqlCommand command = new SqlCommand(StoreProcedure.GETUSERBYID, connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@UserID", userID)); try { connection.Open(); SqlDataReader reader = command.ExecuteReader(); Models.User.User user = new Models.User.User(); user = UtilityManager.DataReaderMap<Models.User.User>(reader); return user; } catch (Exception e) { throw new Exception("Exception retrieving reviews. " + e.Message); } finally { connection.Close(); } } }
public async Task <CreateUserResponse> CreateUser(GoogleSignInRequest request) { var newUser = new Models.User.User(); newUser.Name = request.DisplayName; newUser.PhoneNumber = "0833611023"; newUser.PinnedUserIds = new List <int>(); newUser.UserImgUrl = request.GoogleImgUrl; newUser.UserDescription = "No Description..."; newUser.IsAdmin = false; newUser.EmployeeLevel = 0; newUser.UserRole = UserRoles.Unassigned; newUser.OfficeLocation = OfficeLocation.Unassigned; _users.Users.Add(newUser); await _users.SaveChanges(); var newEmail = new UserEmails(request.Email, newUser.UserId); _users.UserEmail.Add(newEmail); await _users.SaveChanges(); return(new CreateUserResponse("User Successfully Created")); }
private async Task<Models.User.User> GetUser() { var user = new Models.User.User { Language = new Language() }; try { user = await BlobCache.UserAccount.GetObject<Models.User.User>("user"); if (user.Language == null) { user.Language = new Language(); } if (user.MovieHistory == null) { user.MovieHistory = new List<MovieHistory>(); } if (user.ShowHistory == null) { user.ShowHistory = new List<ShowHistory>(); } } catch (Exception) { } return user; }
/// <summary> /// get other user info /// </summary> /// <param name="userid">other user id</param> /// <param name="accesstoken">access token of other user</param> /// <returns>other user info</returns> public async Task <Models.User.User> User_GetInfo(long userid, string accesstoken) { Models.User.User basicinfo = new Models.User.User(); try { _ResponseMessage = await _HttpClient.GetAsync(_HttpClient.BaseAddress.AbsoluteUri + "users/" + userid.ToString() + "/?access_token=" + accesstoken); if (_ResponseMessage.IsSuccessStatusCode) { string responsestring = await _ResponseMessage.Content.ReadAsStringAsync(); basicinfo = JsonConvert.DeserializeObject <Models.User.User>(responsestring); } else { basicinfo.meta.code = int.Parse(_ResponseMessage.StatusCode.ToString()); } return(basicinfo); } catch (Exception ex) { if (_Telemetryclient != null) { _Telemetryclient.TrackException(ex); } basicinfo.meta.code = int.Parse(_ResponseMessage.StatusCode.ToString()); } return(basicinfo); }
public Models.User.User GetUserByUserNameNPassword(string username, string password) { using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString)) { SqlCommand command = new SqlCommand(StoreProcedure.GET_USER_BY_USERNAME_PASSWORD, connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@Username", username)); command.Parameters.Add(new SqlParameter("@Password", password)); try { connection.Open(); SqlDataReader reader = command.ExecuteReader(); Models.User.User user = new Models.User.User(); user = UtilityManager.DataReaderMap<Models.User.User>(reader); return user; } catch (Exception e) { throw new Exception("Exception retrieving reviews. " + e.Message); } finally { connection.Close(); } } }
public async Task <string> AddUser(AddUserDto model) { try { var user = new Models.User.User { FirstName = model.FirstName, LastName = model.LastName, Gender = model.Gender, Identity = model.Identity, BirthDate = model.BirthDate, CityId = model.CityId, Phones = new List <Phone>() }; await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); if (model.Image != null) { var path = Path.Combine(_env.WebRootPath, "files", "images", $"{user.Id}"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } using (var stream = new FileStream(Path.Combine(path, model.Image.FileName.Split('\\').Last()), FileMode.Create)) { model.Image.CopyTo(stream); user.Image = $"/files/images/{user.Id}/{model.Image.FileName.Split('\\').Last()}"; } } else { user.Image = "http://inyogo.com/img/image_not_available.png"; } var phone = new Phone { Number = model.PhoneNumber, Type = model.PhoneType, UserId = user.Id }; await _context.Phones.AddAsync(phone); _context.Users.Update(user); return(Statuses.Success); } catch { return(Statuses.Error); } }
private void HandleTransaction(object state) { lock (_syncLock) { _transactions.TryDequeue(out var transaction); if (transaction == null) { return; } var ownerId = transaction.OwnerId; var accountId = transaction.AccountId; var transactionType = transaction.Type; var amount = transaction.Amount; var dbManager = DbManager.GetInstance(); _user = dbManager.GetUserDataBase().Get(ownerId); _account = dbManager.GetAccountDatabase().Get(accountId); TransactionStatus status; try { MakeTransaction(transactionType, amount); status = TransactionStatus.Success; } catch (NotEnoughMoneyException e) { status = TransactionStatus.Error; transaction.ErrorMessage = e.Message; } catch (UnknowTransactionException e) { status = TransactionStatus.Error; transaction.ErrorMessage = e.Message; } catch (Exception) { status = TransactionStatus.Error; transaction.ErrorMessage = "Unknown error"; } transaction.Status = status; transaction.Time = GetCurrentTime(); transaction.TransactionId = GenerateId(); SessionUtils.RegisterTransaction(_account.Id, transaction); OnTransactionFinished?.Invoke(transaction); } }
/// <summary> /// Set default HD quality /// </summary> /// <returns></returns> public async Task<bool> GetDefaultHdQuality() { try { User = await GetUser().ConfigureAwait(false); return User.DefaultHdQuality; } catch (Exception ex) { Logger.Error(ex); return false; } }
/// <summary> /// Set default subtitle language /// </summary> /// <param name="englishName"></param> /// <returns></returns> public async Task SetDefaultSubtitleLanguage(string englishName) { try { User = await GetUser().ConfigureAwait(false); User.DefaultSubtitleLanguage = englishName; await UpdateUser(User).ConfigureAwait(false); } catch (Exception ex) { Logger.Error(ex); } }
// Service that add requested user. public string AddRequestedUser(Models.User.User user) { string message; user.IsActive = false; user.ID = Guid.NewGuid().ToString(); user.Status = Models.User.Status.Pending; user.CreatedBy = _userID; user.CreatedOn = DateTime.Now; user.Type = Models.User.UserType.Customer; message = _dataProvider.AddObject <Models.User.User>(user); return(message); }
/// <summary> /// Set the upload rate /// </summary> /// <param name="limit"></param> /// <returns></returns> public async Task SetUploadLimit(int limit) { try { User = await GetUser().ConfigureAwait(false); User.UploadLimit = limit; await UpdateUser(User).ConfigureAwait(false); } catch (Exception ex) { Logger.Error(ex); } }
/// <summary> /// Set default HD quality /// </summary> /// <param name="hd"></param> /// <returns></returns> public async Task SetDefaultHdQuality(bool hd) { try { User = await GetUser().ConfigureAwait(false); User.DefaultHdQuality = hd; await UpdateUser(User).ConfigureAwait(false); } catch (Exception ex) { Logger.Error(ex); } }
/// <summary> /// Get the upload rate /// </summary> /// <returns>Upload rate</returns> public async Task<int> GetUploadLimit() { try { User = await GetUser().ConfigureAwait(false); return User.UploadLimit; } catch (Exception ex) { Logger.Error(ex); return 0; } }
// Service that add new user. public string AddUser(Models.User.User user) { string message; user.ID = Guid.NewGuid().ToString(); user.Password = _MdfHash.GetMD5Hash(user.Password); user.Status = Models.User.Status.Accepted; user.Type = Models.User.UserType.Customer; user.IsActive = true; user.CreatedOn = DateTime.Now; message = _dataProvider.AddObject <Models.User.User>(user); return(message); }
/// <summary> /// Get default subtitle language /// </summary> /// <returns></returns> public async Task<string> GetDefaultSubtitleLanguage() { try { User = await GetUser().ConfigureAwait(false); return User.DefaultSubtitleLanguage; } catch (Exception ex) { Logger.Error(ex); return "en"; } }
protected override void OnNavigatedTo(NavigationEventArgs e) { CreatorFrameParams input = e.Parameter as CreatorFrameParams; httpClient = input.httpClient; http_client_semaphore = input.http_client_semaphore; user = input.user; id = input.id; if (id == null) { FollowButton.IsEnabled = false; } else { if (user.is_following) { FollowButton.Content = "Unfollow"; } isfollowing = user.is_following; } CoverImage.Source = new BitmapImage(new Uri(user.cover_url)); UserIdImage.ImageSource = new BitmapImage(new Uri(user.avatar_url)); VidmeUser.Text = user.displayname == null ? "" : user.displayname; VidmeViewCount.Text = user.follower_count + " followers"; UserText.Text = user.bio == null ? "" : user.bio; GridViewUserVideos.ItemsSource = new IncrementalLoadingVideoList(Config.VidmeUrlClass.UserVideoURL(user.user_id), http_client_semaphore, httpClient); GridViewUpvotedVideos.ItemsSource = new IncrementalLoadingVideoList(Config.VidmeUrlClass.LikedVideosUserURL(user.user_id), http_client_semaphore, httpClient); FollowingView.ItemsSource = new IncrementalLoadingUserList(Config.VidmeUrlClass.FollowingUserURL(user.user_id) + "?", http_client_semaphore, httpClient); FollowersView.ItemsSource = new IncrementalLoadingUserList(Config.VidmeUrlClass.FollowersUserURL(user.user_id) + "?", http_client_semaphore, httpClient); AlbumView.ItemsSource = new IncrementalLoadingAlbumList(Config.VidmeUrlClass.UserAlbumsURL(user.user_id), http_client_semaphore, httpClient); CommentsView.ItemsSource = new IncrementalLoadingCommentList(Config.VidmeUrlClass.UserCommentsURL(user.user_id), http_client_semaphore, httpClient); base.OnNavigatedTo(e); if (onLoaded != null) { onLoaded(); } }
private void UserClicked_Handler(object sender, ItemClickEventArgs e) { Models.User.User user = e.ClickedItem as Models.User.User; CreatorFrameParams item = new CreatorFrameParams() { id = id, httpClient = httpClient, http_client_semaphore = http_client_semaphore, user = user }; ((Window.Current.Content as Frame).Content as MainPage).CreatorNavigate(typeof(CreatorFrame), item); }
private async Task SyncUser() { User = new Models.User.User(); try { var user = await BlobCache.UserAccount.GetObject <Models.User.User>("user"); if (user != null) { User = user; } } catch (Exception) { } if (User.Language == null) { User.Language = new Language(); } if (User.MovieHistory == null) { User.MovieHistory = new List <MovieHistory>(); } if (User.ShowHistory == null) { User.ShowHistory = new List <ShowHistory>(); } if (User.CacheLocation == null) { User.CacheLocation = Path.GetTempPath() + @"Popcorn"; } if (User.DefaultSubtitleSize == null) { User.DefaultSubtitleSize = new SubtitleSize { Size = 26, Label = LocalizationProviderHelper.GetLocalizedValue <string>("Normal") }; } if (string.IsNullOrEmpty(User.DefaultSubtitleColor)) { User.DefaultSubtitleColor = "#FFFFFF"; } }
public GetUserResponse getUser(GetUserRequest request) { //TODO: implement GetUSerResponse to use the jwt token from google login API //JsonWebToken token = request.getToken(); //String email = token.getEmail(); String name = request.getName(); //search for user Models.User.User user = _userRepository.GetUser(name).Result[0]; GetUserResponse response = new GetUserResponse(user, name, user.EmployeeLevel, user.IsAdmin, user.UserDescription, user.UserId, user.PhoneNumber, user.UserRole, user.UserImgUrl, user.OfficeLocation, user.PinnedUserIds); return(response); }
// Creating new account. private void CreateUser() { Models.User.User user = new Models.User.User(); string ID; string accountID; bool IsEMailAvailable; bool IsEMailValid; _UIBuffer.Write(" Enter Name of the user: "******" Enter Password of the user: "******" Enter Mobile number of the user: "******" Enter email of the customer: "); user.EMail = _UIBuffer.ReadLine(); IsEMailValid = _dataValidations.IsEMailValid(user.EMail); if (IsEMailValid) { break; } _UIStyling.ChangeForegroundForErrorMessage(); _UIBuffer.WriteLine(" Enter a valid EMail"); _UIStyling.RestoreForegroundColor(); } while (true); IsEMailAvailable = _userService.CheckEMailAvailbility(user.EMail, _bankID); if (IsEMailAvailable) { user.BankID = _bankID; ID = _userService.AddUser(user); _UIBuffer.WriteLine(" " + ID + " is new userID\n"); accountID = _accountService.AddAccount(ID); _UIBuffer.WriteLine(" " + accountID + " is the default account opened for the customer"); break; } else { _UIStyling.ChangeForegroundForErrorMessage(); _UIBuffer.WriteLine(" Email is not available.Please enter another EMail ID"); _UIStyling.RestoreForegroundColor(); } } }
/// <summary> /// </summary> /// <param name="atm"></param> /// <param name="accountId"></param> /// <exception cref="IllegalStateException"></exception> public Session(Models.Atm atm, int accountId) { _atm = atm; _account = _dbManager.GetAccountDatabase().Get(accountId); if (_account == null) { throw new IllegalStateException("Account not found"); } _user = _dbManager.GetUserDataBase().Get(_account.OwnerId); if (_user == null) { throw new IllegalStateException("User not found"); } _transactionManager = TransactionManager.GetInstance(); }
// Send request to join into the bank. public void SignUpRequest(string bankID, string JsonFilePath) { Models.User.User user = new Models.User.User(); bool IsEMailAvailable; string ID; _UIBuffer.WriteLine(); _UIBuffer.Write(" Enter your name: "); user.Name = _UIBuffer.ReadLine(); _UIBuffer.WriteLine(); _UIBuffer.Write(" Enter Password: "******" Enter phone number: "); user.MobileNumber = _UIBuffer.ReadLine(); _UIBuffer.WriteLine(); while (true) { do { _UIBuffer.Write(" Enter EmailID: "); user.EMail = _UIBuffer.ReadLine(); if (_dataValidations.IsEMailValid(user.EMail)) { break; } _UIStyling.ChangeForegroundForErrorMessage(); _UIBuffer.WriteLine(" Enter valid Email ID"); _UIStyling.RestoreForegroundColor(); } while (true); IsEMailAvailable = _userService.CheckEMailAvailbility(user.EMail, _bankID); if (IsEMailAvailable) { user.BankID = _bankID; ID = _userService.AddRequestedUser(user); _UIBuffer.WriteLine(ID + " is your Request-ID"); break; } else { _UIStyling.ChangeForegroundForErrorMessage(); _UIBuffer.WriteLine(" Email is not available.Please enter another EMail ID"); _UIStyling.RestoreForegroundColor(); } } }
// Delete user. public string DeleteUserByID(string ID) { Models.User.User user = _dataProvider.GetObjectByID <Models.User.User>(ID); user.IsActive = false; user.ModifiedBy = _userID; user.ModifiedOn = DateTime.Now; if (_dataProvider.UpdateObject <Models.User.User>(user)) { return("Deleted successfully"); } else { return("Deletion Failed"); } }
public GetUserResponse(Models.User.User user, String name, int emplvl, bool isadmin, String desc, int userid, string number, UserRoles role, String image, OfficeLocation office, List <int> pinnedids) { this.description = desc; this.UserRole = role; this.name = name; this.empLevel = emplvl; this.isAdmin = isadmin; this.userID = userid; this.phoneNumber = number; this.userImage = image; this.OfficeLocation = office; for (int i = 0; i < pinnedids.Count; i++) { this.pinnedIDs[i] = pinnedids[i]; } this.user = user; }
/// <summary> /// Set the current language of the application /// </summary> /// <param name="language">Language</param> public async Task SetCurrentLanguageAsync(Language language) { try { var watch = Stopwatch.StartNew(); User = await GetUser().ConfigureAwait(false); User.Language.Culture = language.Culture; ChangeLanguage(User.Language); await UpdateUser(User).ConfigureAwait(false); watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Logger.Debug( $"SetCurrentLanguageAsync ({User.Language.Name}) in {elapsedMs} milliseconds."); } catch (Exception ex) { Logger.Error(ex); } }
GetFavoritesShows(int page) { try { User = await GetUser().ConfigureAwait(false); var shows = User.ShowHistory.Where(a => a.Favorite).Select(a => a.ImdbId).ToList(); var skip = (page - 1) * Constants.MaxShowsPerPage; if (shows.Count <= Constants.MaxShowsPerPage) { skip = 0; } return (shows.Skip(skip).Take(Constants.MaxShowsPerPage), shows, shows.Count); } catch (Exception ex) { Logger.Error(ex); return (new List<string>(), new List<string>(), 0); } }
/// <summary> /// Get seen shows /// </summary> /// <param name="page">Pagination</param> /// <returns>List of ImdbId</returns> public async Task<(IEnumerable<string> shows, IEnumerable<string> allShows, int nbShows)> GetSeenShows(int page) { try { User = await GetUser().ConfigureAwait(false); var shows = User.ShowHistory.Where(a => a.Seen).Select(a => a.ImdbId).ToList(); var skip = (page - 1) * Constants.MaxShowsPerPage; if (shows.Count <= Constants.MaxShowsPerPage) { skip = 0; } return (shows.Skip(skip).Take(Constants.MaxShowsPerPage), shows, shows.Count); } catch (Exception ex) { Logger.Error(ex); return (new List<string>(), new List<string>(), 0); } }