public async Task <bool> SaveBooking(BikeBookingViewModel model)
        {
            if (model != null)
            {
                var booking = new BicycleBooking
                {
                    RentalId         = model.RentalId,
                    RentedDate       = model.RentedDate,
                    BicycleInventory = await _context.BicycleInventories.FindAsync(model.SelectedBikeId),
                    Customer         = await _context.Customers.FindAsync(model.SelectedCustomerId)
                };

                _context.BicycleRentals.Add(booking);
                await _context.SaveChangesAsync();

                return(true);
            }

            return(false);
        }
        public async Task <bool> SaveCustomer(CustomerViewModel model)
        {
            if (model != null)
            {
                var customer = new Customer
                {
                    CustomerId = model.CustomerId,
                    FirstName  = model.FirstName,
                    LastName   = model.LastName,
                    Address    = model.Address,
                    Status     = model.Status,
                    BirthDate  = model.BirthDate
                };

                _context.Customers.Add(customer);
                await _context.SaveChangesAsync();

                return(true);
            }

            return(false);
        }
Example #3
0
        public async Task <bool> UpdateBike(BikeViewModel model)
        {
            if (model != null)
            {
                var bike = new BicycleInventory
                {
                    BikeId      = model.BikeId,
                    ModelNo     = model.ModelNo,
                    Brand       = model.Brand,
                    Status      = model.Status,
                    BicycleType = await _context.BicycleTypes.FindAsync(model.SelectBikeTypeId)
                };

                var current = await _context.BicycleInventories.FindAsync(model.BikeId);

                _context.Entry(current).CurrentValues.SetValues(bike);
                await _context.SaveChangesAsync();

                return(true);
            }

            return(false);
        }