Пример #1
0
        public async Task <IActionResult> PutOwners([FromRoute] int id, [FromBody] Owner owner)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PutCar(Dato car)
        {
            var c = new Car {
                CarID = int.Parse(car.CarID), FloorID = int.Parse(car.FloorID), LicensePlate = car.LicensePlate, Owner = car.Owner, PlaceID = int.Parse(car.PlaceID)
            };

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
            }

            return(NoContent());
        }
Пример #3
0
        public async Task <ActionResult <Dato> > PostDato(Dato dato)
        {
            //Gets an instance of a place
            var p = _parkingDbContext.Places.Where(pos => pos.PlaceNumber == dato.Pos).First();

            _parkingDbContext.Cars.Add(new Car {
                LicensePlate = dato.LicensePlate, Input = DateTime.Now, PlaceId = p.PlaceId
            });
            p.State = dato.State;
            _parkingDbContext.Entry(p).State = EntityState.Modified;
            await _parkingDbContext.SaveChangesAsync();

            return(CreatedAtAction("GetDato", new { id = dato.ID }, dato));
        }
Пример #4
0
 public DatosController(TempDbContext context, ParkingDbContext parkingDbContext)
 {
     _context          = context;
     _parkingDbContext = parkingDbContext;
     if (_parkingDbContext.Places.Any())
     {
         return;
     }
     for (int i = 0; i < 32; i++)
     {
         floors[i] = new Place {
             PlaceId = i + 1, PlaceNumber = i + 1, State = false
         };
     }
     foreach (var item in floors)
     {
         _parkingDbContext.Places.Add(item);
     }
     _parkingDbContext.SaveChangesAsync();
 }
 public Contact CreateContact(Contact contact)
 {
     _dbContext.Add(contact);
     _dbContext.SaveChangesAsync();
     return(contact);
 }
Пример #6
0
 public CarsController(ParkingDbContext context)
 {
     _context = context;
     if (!_context.Cars.Any())
     {
         _context.Cars.Add(new Car {
             FloorID = 1, PlaceID = 1, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 1, PlaceID = 2, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 1, PlaceID = 3, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 1, PlaceID = 4, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 1, PlaceID = 5, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 1, PlaceID = 6, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 1, PlaceID = 7, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 1, PlaceID = 8, LicensePlate = "N/A", Owner = "N/A"
         });
         //Piso2
         _context.Cars.Add(new Car {
             FloorID = 2, PlaceID = 1, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 2, PlaceID = 2, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 2, PlaceID = 3, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 2, PlaceID = 4, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 2, PlaceID = 5, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 2, PlaceID = 6, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 2, PlaceID = 7, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 2, PlaceID = 8, LicensePlate = "N/A", Owner = "N/A"
         });
         //Piso3
         _context.Cars.Add(new Car {
             FloorID = 3, PlaceID = 1, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 3, PlaceID = 3, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 3, PlaceID = 4, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 3, PlaceID = 5, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 3, PlaceID = 6, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 3, PlaceID = 7, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 3, PlaceID = 7, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 3, PlaceID = 8, LicensePlate = "N/A", Owner = "N/A"
         });
         //Piso4
         _context.Cars.Add(new Car {
             FloorID = 4, PlaceID = 1, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 4, PlaceID = 3, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 4, PlaceID = 4, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 4, PlaceID = 5, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 4, PlaceID = 6, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 4, PlaceID = 7, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 4, PlaceID = 7, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.Cars.Add(new Car {
             FloorID = 4, PlaceID = 8, LicensePlate = "N/A", Owner = "N/A"
         });
         _context.SaveChangesAsync();
     }
 }