Beispiel #1
0
        public async Task <IHttpActionResult> NewLease(LeaseRequest request)
        {
            Car car = Db.Cars.Where(c => c.LicensePlate == request.RegNr).Single();

            foreach (Picture picture in request.Pictures)
            {
                Db.Pictures.Add(picture);
            }

            Parking parking = new Parking
            {
                Location = CreateLocation(request.Lat, request.Lng),
                Pictures = request.Pictures
            };

            Lease lease = new Lease
            {
                Car            = car,
                Status         = LeaseStatus.Available,
                PickupLocation = parking
            };

            Db.Parkings.Add(parking);
            Db.Leases.Add(lease);
            Db.SaveChanges();

            return(Ok(car.Id));
        }
Beispiel #2
0
        public async Task <IHttpActionResult> UpdateLease(LeaseRequest request)
        {
            //var leaser = await UserManager.FindByNameAsync(request.UserId);
            var leaser = await UserManager.FindByEmailAsync("*****@*****.**");

            Lease lease = Db.Leases.Where(l => l.Car.LicensePlate == request.RegNr).ToArray().Last();

            switch (lease.Status)
            {
            case LeaseStatus.Available:
                lease.Status = LeaseStatus.Rented;
                lease.Leaser = leaser;
                break;

            case LeaseStatus.Rented:
                foreach (Picture picture in request.Pictures)
                {
                    Db.Pictures.Add(picture);
                }
                lease.Status           = LeaseStatus.Delivered;
                lease.DeliveryLocation = new Parking
                {
                    Location = CreateLocation(request.Lat, request.Lng),
                    Pictures = request.Pictures
                };
                Db.Parkings.Add(lease.DeliveryLocation);
                break;

            default:
                break;
            }

            Db.Entry(lease).State = EntityState.Modified;
            Db.SaveChanges();

            return(Ok(lease.Id));
        }