Beispiel #1
0
        public async Task <ReturnBook> CreateAsync(ReturnBook model)
        {
            var data = _context.ReturnBooks.Add(model);
            await _context.SaveChangesAsync();

            return(data);
        }
Beispiel #2
0
        public async Task <LatePayment> CreateAsync(LatePayment model)
        {
            var data = _context.LatePayments.Add(model);
            await _context.SaveChangesAsync();

            return(data);
        }
Beispiel #3
0
        public async Task <SystemOption> CreateAsync(SystemOption model)
        {
            var data = _context.SystemOptions.Add(model);
            await _context.SaveChangesAsync();

            return(data);
        }
        public async Task <Group> CreateAsync(Group item)
        {
            var result = await _context.Groups.AddAsync(item);

            await _context.SaveChangesAsync();

            return(result.Entity);
        }
Beispiel #5
0
        public async Task <Question> CreateAsync(Question item)
        {
            var result = await _context.Questions.AddAsync(item);

            await _context.SaveChangesAsync();

            return(result.Entity);
        }
Beispiel #6
0
        public async Task <Answer> CreateAsync(Answer item)
        {
            var result = await _context.Answers.AddAsync(item);

            await _context.SaveChangesAsync();

            return(result.Entity);
        }
Beispiel #7
0
        public async Task <Page> CreateAsync(Page item)
        {
            var result = await _context.Pages.AddAsync(item);

            await _context.SaveChangesAsync();

            return(result.Entity);
        }
Beispiel #8
0
        public async Task <Administration> CreateAsync(Administration item)
        {
            var result = await _context.Administration.AddAsync(item);

            await _context.SaveChangesAsync();

            return(result.Entity);
        }
Beispiel #9
0
        private async Task <Book> AddBook(Book book)
        {
            await _context.Books.AddAsync(book).ConfigureAwait(false);

            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(book);
        }
        public async Task <BlockType> CreateAsync(BlockType item)
        {
            var result = await _context.BlockTypes.AddAsync(item);

            await _context.SaveChangesAsync();

            return(result.Entity);
        }
Beispiel #11
0
        public async Task <Course> CreateAsync(Course item)
        {
            if (item.LoadImg != null)
            {
                item.Img = await _loader.LoadImg(item.LoadImg, "files");
            }
            var result = await _context.Courses.AddAsync(item);

            await _context.SaveChangesAsync();

            return(result.Entity);
        }
Beispiel #12
0
        public async Task <Direction> CreateAsync(Direction item)
        {
            if (item.LoadImg != null)
            {
                item.Img = await _loader.LoadImg(item.LoadImg, "files");
            }
            var result = await _context.Directions.AddAsync(item);

            await _context.SaveChangesAsync();

            return(result.Entity);
        }
Beispiel #13
0
        public async Task <Member> CreateAsync(Member model)
        {
            try
            {
                var data = _context.Members.Add(model);
                await _context.SaveChangesAsync();

                return(data);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Beispiel #14
0
        public async Task <BorrowBook> CreateAsync(BorrowBook model)
        {
            try
            {
                var data = _context.BorrowBooks.Add(model);
                await _context.SaveChangesAsync();

                return(data);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        private async Task <SubjectCategory> AddSubjectAsync(SubjectCategory subject)
        {
            await _context.SubjectCategories.AddAsync(subject).ConfigureAwait(false);

            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(subject);
        }
Beispiel #16
0
        private async Task <Author> AddAuthorAsync(Author author)
        {
            await _context.Authors.AddAsync(author).ConfigureAwait(false);

            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(author);
        }
        public async Task <Notification> CreateNotificationAsync(string description, string username)
        {
            var admin = await _userService.GetAdmin().ConfigureAwait(false);

            var notification = new Notification
            {
                UserId      = admin.Id,
                Description = description,
                EventDate   = DateTime.Now,
                Username    = username,
            };

            _context.Notifications.Add(notification);
            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(notification);
        }
Beispiel #18
0
 public async Task <List <ReserveBook> > UpdateAsync(List <ReserveBook> model)
 {
     foreach (var item in model)
     {
         _context.Entry(item).State = EntityState.Modified;
         await _context.SaveChangesAsync();
     }
     return(model);
 }
        public async Task <ReserveBook> CheckIfBookExistInReservations(string bookId)
        {
            var book = await _context.Books.FindAsync(bookId).ConfigureAwait(false);

            ReserveBook reservation = null;

            if (await CheckIfBookWithThisTitleExist(book.Title).ConfigureAwait(false))
            {
                var bookInReservations     = _context.ReservedBooks.Where(b => b.BookTitle == book.Title);
                var dateOfFirstReservation = await bookInReservations.MinAsync(d => d.ReservationDate).ConfigureAwait(false);

                reservation = await _context.ReservedBooks.FirstAsync(d => d.ReservationDate == dateOfFirstReservation).ConfigureAwait(false);
                await GiveBookToFirstReservation(reservation.BookId, reservation.UserId).ConfigureAwait(false);

                _context.ReservedBooks.Remove(reservation);
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            return(reservation);
        }
Beispiel #20
0
        public async Task <BanRecord> AddBan(BanDto banDto)
        {
            var ban = new BanRecord
            {
                UserId         = banDto?.UserId,
                Description    = banDto.Description,
                ExpirationDate = banDto.ExpirationDate,
            };
            await _context.BanRecords.AddAsync(ban).ConfigureAwait(false);

            await _context.SaveChangesAsync().ConfigureAwait(false);

            var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == ban.UserId).ConfigureAwait(false);

            user.BanRecordId = ban.Id;
            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(ban);
        }
        public async Task <User> MakeMember(string username)
        {
            var user = await _userservice.FindUserByUsernameAsync(username).ConfigureAwait(false);

            await _userMng.AddToRoleAsync(user, "Member").ConfigureAwait(false);

            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(user);
        }
Beispiel #22
0
        public async Task SetUserCancelationStatusAsync(string id)
        {
            var user = await FindUserByIdAsync(id).ConfigureAwait(false);

            //await DeleteAllNotificationsOfUser(id).ConfigureAwait(false);
            await DeleteAllReservationsOfUser(id).ConfigureAwait(false);

            user.IsCancelled = true;
            await _context.SaveChangesAsync().ConfigureAwait(false);
        }
        public async Task CreateReviewAsync(string userId, decimal grade, string description, string bookId)
        {
            var bookTitle = await _bookService.GetBookTitleAsync(bookId).ConfigureAwait(false);

            var allBooksWithSameTitle = await _bookService.GetAllSameBooks(bookId).ConfigureAwait(false);

            //BookRating item.BookRating = _context.BookRating.Where(br => br.BookId == bookId);
            foreach (var item in allBooksWithSameTitle)
            {
                if (item.BookRating != null)
                {
                    item.BookRating.Rating = grade;
                    _context.Update(item);
                    await _context.SaveChangesAsync().ConfigureAwait(false);
                }
                else
                {
                    var bookRating = new BookRating
                    {
                        BookId = bookId,
                        Rating = grade
                    };
                    _context.BookRating.Add(bookRating);
                    await _context.SaveChangesAsync().ConfigureAwait(false);

                    item.BookRatingId = bookRating.Id;
                    _context.Update(item);
                    await _context.SaveChangesAsync().ConfigureAwait(false);
                }

                var review = new Review
                {
                    BookRatingId = item.BookRating.Id,
                    Description  = description,
                    Grade        = grade,
                    UserId       = userId,
                    BookTitle    = bookTitle
                };
                _context.Review.Add(review);
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
        }
Beispiel #24
0
        public async Task <Book> CreateAsync(Book model)
        {
            var             bookCategories = _context.Categories.ToList <Category>();;
            List <Category> Categories     = new List <Category>();

            foreach (Category Category in model.Categories)
            {
                var InBookCategory = bookCategories.Where(c => c.Name == Category.Name).FirstOrDefault();
                if (InBookCategory != null)
                {
                    Categories.Add(InBookCategory);
                }
                else
                {
                    Categories.Add(Category);
                }
            }
            model.Categories = Categories;
            var           bookAuthors = _context.Authors.ToList <Author>();
            List <Author> Authors     = new List <Author>();

            foreach (Author Author in model.Authors)
            {
                var InBookAuthor = bookAuthors.Where(c => c.Name == Author.Name).FirstOrDefault();
                if (InBookAuthor != null)
                {
                    Authors.Add(InBookAuthor);
                }
                else
                {
                    Authors.Add(Author);
                }
            }
            model.Authors = Authors;

            var data = _context.Books.Add(model);
            await _context.SaveChangesAsync();

            return(data);
        }
        public async Task <HistoryRegistry> CheckoutBookAsync(string bookId, string userId)
        {
            if (bookId == null)
            {
                throw new ArgumentException("Invalid checkout parameters: book id cannot be null.");
            }
            if (userId == null)
            {
                throw new ArgumentException("Invalid checkout parameters: user id cannot be null.");
            }

            var historyRegistry = new HistoryRegistry()
            {
                BookId       = bookId,
                UserId       = userId,
                CheckOutDate = DateTime.Now.ToShortDateString(),
                ReturnDate   = DateTime.Now.AddDays(10)
            };

            if (historyRegistry == null)
            {
                throw new ArgumentException("Invalid operation: history registry cannot be null.");
            }

            _context.HistoryRegistries.Add(historyRegistry);

            var book = await _context.Books.FirstAsync(x => x.Id == bookId).ConfigureAwait(false);

            book.IsCheckedOut = true;
            //avlb. copies prop. of this book decr. with 1 in each book
            await _context.Books.Where(b => b.Title == book.Title && b.Author.Name == book.Author.Name && b.Language == book.Language).ForEachAsync(bc => bc.Copies--).ConfigureAwait(false);

            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(historyRegistry);
        }
Beispiel #26
0
        public async Task Add(Course entity, CancellationToken cancellationToken)
        {
            await _context.Courses.AddAsync(entity);

            await _context.SaveChangesAsync(cancellationToken);
        }
 public async Task <int> Save()
 {
     return(await _context.SaveChangesAsync());
 }