Пример #1
0
        public int RemoveFromBook(Accom accom)
        {
            var bookingItem =
                _appDbContext.BookingItems.SingleOrDefault(
                    b => b.Accom.Id == accom.Id && b.BookingId == BookingId); //Check ID can be found

            var localAmount = 0;

            if (bookingItem != null)
            {
                if (bookingItem.Amount > 1)
                {
                    bookingItem.Amount--;
                    localAmount = bookingItem.Amount;
                }
                else
                {
                    _appDbContext.BookingItems.Remove(bookingItem);
                }
            }

            return(localAmount);
        }
Пример #2
0
        public void AddToBook(Accom accom, int amount)
        {
            var bookingItem =
                _appDbContext.BookingItems.SingleOrDefault(
                    b => b.Accom.Id == accom.Id && b.BookingId == BookingId); //Check ID can be found

            if (bookingItem == null)                                          // if not add to booking
            {
                bookingItem = new BookingItem
                {
                    BookingId = BookingId,
                    Accom     = accom,
                    Amount    = 1
                };

                _appDbContext.BookingItems.Add(bookingItem);
            }
            else
            {
                bookingItem.Amount++;
            }

            _appDbContext.SaveChanges(); // add to database
        }
Пример #3
0
 public void CreateAccom(Accom accom)
 {
     _appDbContext.Accoms.Add(accom);
     _appDbContext.SaveChanges();
 }
Пример #4
0
 public void UpdateAccom(Accom accom)
 {
     _appDbContext.Accoms.Update(accom);
     _appDbContext.SaveChanges();
 }