public async Task<UserDto> AddNewUser(NewUserCommandDto newUserCommandDto)
        {
            using (var context = new PicturesDbContext())
            {
                var newUser = new User
                {
                    FirstName = newUserCommandDto.FirstName,
                    LastName = newUserCommandDto.LastName,
                    PhotoRec = newUserCommandDto.PhotoRec,
                    Email = newUserCommandDto.Email
                };

                if (!newUserCommandDto.IsLocalUser)
                {
                    var login = new Login
                    {
                        LoginType = newUserCommandDto.LoginType,
                        ExternalUserId = newUserCommandDto.ExternalLoginId,
                        User = newUser
                    };

                    context.Logins.Add(login);
                }
                else
                {
                    newUser.Login = newUserCommandDto.Login;
                    newUser.Password = newUserCommandDto.Password;
                }

                context.Users.Add(newUser);

                await context.SaveChangesAsync();

                if (newUserCommandDto.IsLocalUser)
                {
                    var user = context.Users.Include(i => i.Logins).First(i => i.Login == newUserCommandDto.Login);
                    return user.CreateUserDto(user.Logins);
                }

                var user1 = context.Logins.Include(i => i.User).First(
                    i =>
                        i.LoginType == newUserCommandDto.LoginType &&
                        i.ExternalUserId == newUserCommandDto.ExternalLoginId).User;
                return user1.CreateUserDto(user1.Logins);
            }
        }
        public async Task Save(SavePictureDto savePictureDto)
        {
            using (var context = new PicturesDbContext())
            {
                if (savePictureDto.Id == 0)
                {
                    context.Pictures.Add(new Picture
                    {
                        Name = savePictureDto.Name,
                        PainterId = savePictureDto.PainterId,
                        StyleId = savePictureDto.StyleId,
                        Year = savePictureDto.Year,
                        Guid = savePictureDto.Guid,
                        ImageUrl = savePictureDto.ImageUrl,
                    });
                }
                else
                {
                    var existedPicture = new Picture {Id = savePictureDto.Id};
                    context.Pictures.Attach(existedPicture);

                    existedPicture.Name = savePictureDto.Name;
                    existedPicture.PainterId = savePictureDto.PainterId;
                    existedPicture.StyleId = savePictureDto.StyleId;
                    existedPicture.Year = savePictureDto.Year;
                    existedPicture.Guid = savePictureDto.Guid;
                    existedPicture.ImageUrl = savePictureDto.ImageUrl;

                    context.Entry(existedPicture).State = EntityState.Modified;
                }

                await context.SaveChangesAsync();
            }
        }
        public async Task Delete(long id)
        {
            using (var context = new PicturesDbContext())
            {
                var picture = new Picture() {Id = id};

                context.Pictures.Attach(picture);
                context.Entry(picture).State = EntityState.Deleted;

                await context.SaveChangesAsync();
            }
        }
        public async Task SaveGameResult(long userId, int gameQuestions, int gameRightAnswers)
        {
            using (var context = new PicturesDbContext())
            {
                var user = await context.Users.FirstOrDefaultAsync(i => i.Id == userId);

                context.UsersScores.Add(new UserScores
                {
                    UserId = user.Id,
                    GameQuestions = gameQuestions,
                    GameRightAnswers = gameRightAnswers
                });

                await context.SaveChangesAsync();
            }
        }
        public async Task UpdateUserInfo(long id, string firstName, string lastName)
        {
            using (var context = new PicturesDbContext())
            {
                var userEntity = new User {Id = id};
                var entity = context.Users.Attach(userEntity);

                entity.FirstName = firstName;
                entity.LastName = lastName;

                context.Entry(entity).Property(item => item.FirstName).IsModified = true;
                context.Entry(entity).Property(item => item.LastName).IsModified = true;

                await context.SaveChangesAsync();
            }
        }