public async Task <IActionResult> PutCustomer(int id, Customer customer)
        {
            if (id != customer.ID)
            {
                return(BadRequest());
            }

            _context.Entry(customer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #2
0
        public async Task <IActionResult> PutBikesReserved(int id, BikesReserved bikesReserved)
        {
            if (id != bikesReserved.Id)
            {
                return(BadRequest());
            }

            _context.Entry(bikesReserved).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BikesReservedExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> EndRental(int id, Rental rental)
        {
            if (id != rental.RentalId)
            {
                return(BadRequest());
            }

            _context.Entry(rental).State = EntityState.Modified;

            try
            {
                rental.RentalEnd = DateTime.Now;
                rental.TotalCost = CalcTotalCost(rental);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RentalExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #4
0
        public async Task <IActionResult> PutRental(int id, Rental rental)
        {
            if (id != rental.ID)
            {
                return(BadRequest());
            }

            _context.Entry(rental).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RentalExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #5
0
        public async Task <IActionResult> PutShop(int id, Shop shop)
        {
            if (id != shop.ShopId)
            {
                return(BadRequest());
            }

            _context.Entry(shop).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ShopExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutEmployee(int id, [FromBody] Employee employee)
        {
            if (id != employee.Id)
            {
                return(BadRequest());
            }

            _context.Entry(employee).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #7
0
        public async Task <IActionResult> EndRental(int id)
        {
            var rental = _context.Rentals.Where(r => r.Id == id).First();

            if (id != rental.Id)
            {
                return(BadRequest());
            }

            _context.Entry(rental).State = EntityState.Modified;

            try
            {
                CostCalculator costCalculator = new CostCalculator();
                rental.RentalEnd = DateTime.Now;
                rental.TotalCost = costCalculator.CalculateTotalCosts(rental);
                rental.Paid      = false;
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RentalExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #8
0
        public async Task <IActionResult> PutPaymentStatus(int id, PaymentStatus paymentStatus)
        {
            if (id != paymentStatus.PaymentStatusId)
            {
                return(BadRequest());
            }

            _context.Entry(paymentStatus).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PaymentStatusExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #9
0
        public async Task <IActionResult> PutAccessories(int id, Accessories accessories)
        {
            if (id != accessories.Id)
            {
                return(BadRequest());
            }

            _context.Entry(accessories).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccessoriesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #10
0
        private static async Task AsyncTest()
        {
            var task1 = CalculateAsync();
            var task2 = CalculateAsync();
            await Task.WhenAll(task1, task2);

            Console.WriteLine(task1.Result + task2.Result);

            using (var context = new BikeRentalContext())
            {
                var user = await context.Users.FirstAsync();

                user.FirstName = "Johnny2";
                await context.SaveChangesAsync();
            }

            Console.WriteLine("Saved Johnny2");
        }
Example #11
0
        public async Task <int> AddCustomer(Customer customer)
        {
            if (db != null)
            {
                await db.Customers.AddAsync(customer);

                await db.SaveChangesAsync();

                return(customer.Id);
            }

            return(0);
        }
        public async Task <int> AddBike(Bikes bike)
        {
            if (db != null)
            {
                await db.Bikes.AddAsync(bike);

                await db.SaveChangesAsync();

                return(bike.Id);
            }

            return(0);
        }
Example #13
0
        public async Task <ActionResult <BikeResponse> > AddBike([FromBody] AddBikeRequest request)
        {
            var bike = new Bike
            {
                FrameNumber = request.FrameNumber,
                BikeTypeId  = request.BikeTypeId
            };

            _context.Bikes.Add(bike);
            await _context.SaveChangesAsync();

            var bikeResponse = new BikeResponse
            {
                FrameNumber = bike.FrameNumber,
                BikeId      = bike.BikeId,
                BikeTypeId  = bike.BikeTypeId
            };

            return(CreatedAtRoute(nameof(GetBike), new { bikeId = bikeResponse.BikeId }, bikeResponse));
        }
Example #14
0
        public async Task <ActionResult <BikeTypeResponse> > AddBikeType([FromBody] AddBikeTypeRequest request)
        {
            var bikeType = new BikeType
            {
                BikeTypeName        = request.BikeTypeName,
                BikeTypePrice       = request.BikeTypePrice,
                BikeTypeDescription = request.BikeTypeDescription,
                BikeTypeImage       = request.BikeTypeImage
            };

            _context.BikeTypes.Add(bikeType);
            await _context.SaveChangesAsync();

            var bikeTypeResponse = new BikeTypeResponse
            {
                Id                  = bikeType.Id,
                BikeTypeName        = bikeType.BikeTypeName,
                BikeTypePrice       = bikeType.BikeTypePrice,
                BikeTypeDescription = bikeType.BikeTypeDescription,
                BikeTypeImage       = bikeType.BikeTypeImage
            };

            return(CreatedAtAction(nameof(AddBikeType), new { bikeTypeId = bikeTypeResponse.Id }, bikeTypeResponse));
        }