public void PopulateTable() { try { string[] booksData = _reader.LoadData(ReaderType.Book); var selected = booksData.Select(x => x.Split(';')); IEnumerable <Book> books = selected .Select(x => new Book { ISBN = x[0], Title = x[1], Authors = x[2], PublicationYear = x[3], Publisher = x[4], ImageUrlS = x[5], ImageUrlM = x[6], ImageUrlL = x[7] }); _dbContext.Book.AddRange(books); _dbContext.SaveChanges(); _mongoDbContext.Books.InsertMany(books); } catch (Exception e) { //Create logger } }
public void PopulateTable() { try { string[] usersData = _reader.LoadData(ReaderType.Users); var selected = usersData.Select(x => x.Split(';')); IEnumerable <User> users = selected .Select(x => new User { BsonId = new Guid(), Location = x[1], Age = x[2] }); _dbContext.User.AddRange(users); _dbContext.SaveChanges(); _mongoDbContext.Users.InsertMany(users); } catch (Exception e) { //Create logger } }
public void PopulateTable() { try { string[] ratingData = _reader.LoadData(ReaderType.Rating); var selected = ratingData.Select(x => x.Split(';')); List <Rating> newRatings = new List <Rating>(); IEnumerable <Rating> ratings = selected .Select(x => new Rating { UserId = Int32.Parse(x[0]), ISBN = x[1], BookRating = Int32.Parse(x[2]), }); _dbContext.Rating.AddRange(ratings); _dbContext.SaveChanges(); _mongoDbContext.Ratings.InsertMany(ratings); } catch (Exception e) { //Create logger } }
public async Task <UserModel> Handle(UpdateUserCommand request, CancellationToken cancellationToken) { User currentUser = _buyBookContext.User.Find(request.Id); if (currentUser != null) { currentUser.Location = request.Location; currentUser.Age = request.Age; if (_buyBookContext.SaveChanges() == 1) { return(new UserModel { Id = currentUser.Id, Age = currentUser.Age, Location = currentUser.Location }); } } return(null); }
public async Task <UserModel> Handle(CreateUserCommand request, CancellationToken cancellationToken) { User user = new User { Age = request.Age, Location = request.Location }; //Create Mapper _buyBookContext.User.Add(user); if (_buyBookContext.SaveChanges() == 1) { return(new UserModel { Id = user.Id, Age = user.Age, Location = user.Location }); } return(null); }
public async Task <UserModel> Handle(DeleteUserCommand request, CancellationToken cancellationToken) { User currentUser = _buyBookContext.User.Find(request.Id); UserModel returnUser; if (currentUser != null) { returnUser = new UserModel { Id = currentUser.Id, Age = currentUser.Age, Location = currentUser.Location }; _buyBookContext.User.Remove(currentUser); if (_buyBookContext.SaveChanges() == 1) { return(returnUser); } } return(null); }