示例#1
0
        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);
        }
示例#2
0
        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;
            }

        }
示例#3
0
 public UsersViewModel( UserDTO user )
 {
     _user = user;
 }