Ejemplo n.º 1
0
        public ActionResult Post([FromBody] CarPostModel post)
        {
            var existingCar = db.FindCar(post.Registration);

            if (existingCar != default)
            {
                return(Conflict($"Sorry - the car with registration {post.Registration} is already listed!"));
            }
            var model = db.Models.FirstOrDefault(m => m.Uri == post.Model);

            if (model == default)
            {
                return(BadRequest("We don't recognise that car model - sorry!"));
            }
            var car = new Autobarn.Data.Entities.Car {
                Registration = post.Registration,
                Color        = post.Color,
                Year         = post.Year,
                CarModel     = model
            };

            db.AddCar(car);
            var message = CreateMessage(car);

            bus.PubSub.Publish(message);
            return(Created($"/api/cars/{car.Registration}", car));
        }
Ejemplo n.º 2
0
        public IActionResult Add(AddCarModel data)
        {
            if (ModelState.IsValid)
            {
                var carModel = database.Models.FirstOrDefault(m => m.Code == data.CarModel);
                var car      = new Car {
                    CarModel     = carModel,
                    Registration = data.Registration,
                    Color        = data.Color,
                    Year         = data.Year
                };
                database.AddCar(car);
                return(RedirectToAction("Index"));
            }

            data.Models = ListModels;
            return(View(data));
        }