Exemplo n.º 1
0
        public async Task <IActionResult> PutCar(string id, Car car)
        {
            if (id != car.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("CountryId,CountryName")] Country country)
        {
            if (ModelState.IsValid)
            {
                _context.Add(country);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(country));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("SellerId,SellerName,CityId")] Seller seller)
        {
            if (ModelState.IsValid)
            {
                _context.Add(seller);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CityId"] = new SelectList(_context.Cities, "CityId", "CityName", seller.CityId);
            return(View(seller));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("BrandId,BrandName,CountryId")] Brand brand)
        {
            if (ModelState.IsValid)
            {
                _context.Add(brand);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryId"] = new SelectList(_context.Countries, "CountryId", "CountryName", brand.CountryId);
            return(View(brand));
        }
Exemplo n.º 5
0
        public async Task CreateCar(CarEntry car)
        {
            if (car == null)
            {
                throw new ArgumentNullException(nameof(car));
            }

            car.CreateDate = DateTimeOffset.UtcNow;

            _context.CarEntries.Add(car);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("CarSaleId,CustomerId,SellerId,CarId,Price")] CarSale carSale)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carSale);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarId"]      = new SelectList(_context.Cars, "CarId", "Model", carSale.CarId);
            ViewData["CustomerId"] = new SelectList(_context.Customers, "CustomerId", "CustomerName", carSale.CustomerId);
            ViewData["SellerId"]   = new SelectList(_context.Sellers, "SellerId", "SellerName", carSale.SellerId);
            return(View(carSale));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create(int countryId, [Bind("CityId,CountryId,CityName")] City city)
        {
            city.CountryId = countryId;
            if (ModelState.IsValid)
            {
                _context.Add(city);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                return(RedirectToAction("Index", "Cities", new { id = countryId, name = _context.Countries.Where(c => c.CountryId == countryId).FirstOrDefault().CountryName }));
            }
            //ViewData["CountryId"] = new SelectList(_context.Countries, "CountryId", "CountryName", city.CountryId);
            //return View(city);
            return(RedirectToAction("Index", "Cities", new { id = countryId, name = _context.Countries.Where(c => c.CountryId == countryId).FirstOrDefault().CountryName }));
        }
        public async Task Execute(CreateVehicleOtherPropertyModel model)
        {
            var entity = new VehicleOtherProperty
            {
                VehicleId             = model.VehicleId,
                VehicleTypePropertyId = model.VehicleTypePropertyId,
                PropertyValue         = model.PropertyValue,
                DateCreated           = DateTime.UtcNow,
            };

            _context.VehicleOtherProperties.Add(entity);

            await _context.SaveChangesAsync();

            model.VehicleOtherPropertyId = entity.VehicleOtherPropertyId;
        }
        public async Task Execute(CreateVehicleModel model)
        {
            var entity = new Vehicle
            {
                VehicleTypeId = model.VehicleTypeId,
                Make          = model.Make,
                Model         = model.Model,
                DateCreated   = DateTime.UtcNow,
            };

            _context.Vehicles.Add(entity);

            await _context.SaveChangesAsync();

            model.VehicleId = entity.VehicleId;
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Create([Bind("CarId,BrandId,CarYear,BodyId,Vin,Model,ColorId")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BodyId"]  = new SelectList(_context.Bodies, "BodyId", "BodyName", car.BodyId);
            ViewData["BrandId"] = new SelectList(_context.Brands, "BrandId", "BrandName", car.BrandId);
            ViewData["ColorId"] = new SelectList(_context.Colors, "ColorId", "ColorName", car.ColorId);
            return(View(car));
        }
Exemplo n.º 11
0
 public async Task <int> CreateCar(Car newCar)
 {
     _context.Cars.Add(newCar);
     return(await _context.SaveChangesAsync());
 }