public async Task AddUserAsync(UserDTO user) { if (_userStorageContainer == null) { _userStorageContainer = new UserStorageContainer(); } if ( user.Id == 0 ) { var lastUser = _userStorageContainer.Users.OrderBy(x => x.Id).LastOrDefault() ?? new UserDTO(); user.Id = lastUser.Id + 1; if ( user.ImageBytes == null || !user.ImageBytes.Any()) { user.ImageBytes = await GetGuestSilhouetteImageBytesAsync(); } _userStorageContainer.Users.Add(user); } else { var foundUser = _userStorageContainer.Users.FirstOrDefault(x => x.Id == user.Id); if (foundUser == null ) { _userStorageContainer.Users.Add(user); } else { var index = _userStorageContainer.Users.IndexOf(foundUser); _userStorageContainer.Users[index] = user; } } _usersStorageHelper.SaveASync(_userStorageContainer, UsersStorageFileName); }
private async Task CreateNewGuestSilhouetteAsync() { try { var bytes = await GetGuestSilhouetteImageBytesAsync(); var guestUser = new UserDTO { Id = 1, UserName = UserConstants.GuestSilhouetteUserName, ImageName = UserConstants.GuestSilhouetteImageName, ImageBytes = bytes }; AddUserAsync(guestUser); } catch (Exception e) { var m = e.Message; throw; } }
public UsersViewModel( UserDTO user ) { _user = user; }