Ejemplo n.º 1
0
        public async Task <IActionResult> AddTypeCar([Bind("NumberOfType,NameOfType")] TypeCar typecar)
        {
            if (ModelState.IsValid)
            {
                _context.Add(typecar);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(TypeCarList)));
            }
            return(View(typecar));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Status")] Brand brand, IFormFile?ful)

        {
            var idd = _context.brands.Count() + 1;

            if (ModelState.IsValid)
            {
                if (ful != null)
                {
                    var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/pro", idd + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]);
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await ful.CopyToAsync(stream);
                    }

                    brand.Logo = idd + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1];
                }
                else
                {
                    brand.Logo = "no-image.png";
                }

                _context.Add(brand);


                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View("Index"));
        }
        public async Task <IActionResult> Create([Bind("Marca,Descripcion,Modelo,Precio,Kilometros,Estado,Foto")] CreateCarViewModel car)
        {
            if (ModelState.IsValid)
            {
                string guidImagen = null;

                if (car.Foto != null)
                {
                    string ficherosImagenes = Path.Combine(hosting.WebRootPath, "img");
                    guidImagen = Guid.NewGuid().ToString() + car.Foto.FileName;
                    string rutaDefinitiva = Path.Combine(ficherosImagenes, guidImagen);
                    using (var fileStream = new FileStream(rutaDefinitiva, FileMode.Create))
                    {
                        car.Foto.CopyTo(fileStream);
                    }
                }

                Car newCar = new Car();
                newCar.Descripcion = car.Descripcion;
                newCar.Modelo      = car.Modelo;
                newCar.Precio      = car.Precio;
                newCar.Estado      = car.Estado;
                newCar.Kilometros  = car.Kilometros;
                newCar.MarcaId     = car.Marca;
                newCar.PathImg     = guidImagen;

                _context.Add(newCar);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,ManufacturerName")] Manufacturer manufacturer)
        {
            // this code checks if there is a manufacturer with the given name in _context
            int createMakerCounter = 0;

            foreach (var checkMaker in _context.Manufacturers)
            {
                if (checkMaker.ManufacturerName == manufacturer.ManufacturerName)
                {
                    createMakerCounter += 1;
                }
            }
            if (createMakerCounter == 0)
            {
                if (ModelState.IsValid)
                {
                    _context.Add(manufacturer);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(manufacturer));
            }
            else
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,CityName")] City city)
        {
            // this code checks if there is a city with the given name in _context
            int createCounter = 0;

            foreach (var checkCity in _context.Cities)
            {
                if (checkCity.CityName == city.CityName)
                {
                    createCounter += 1;
                }
            }
            if (createCounter == 0)
            {
                if (ModelState.IsValid)
                {
                    _context.Add(city);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(city));
            }
            else
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("Id,Name,BrandId,ParentId")] CarModel carModel)
        {
            if (_context.CarModels.FirstOrDefault(cm => cm.Name == carModel.Name) != null)
            {
                ModelState.AddModelError("Name", "This model already exists");
            }
            if (ModelState.IsValid)
            {
                _context.Add(carModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BrandId"]  = new SelectList(_context.Brands, "Id", "Name", carModel.BrandId);
            ViewData["ParentId"] = new SelectList(CreateParentModelsList(), "Id", "Name", carModel.ParentId);
            return(View(carModel));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> AddOrEdit([Bind("IDCar,Mark,Model,Year,Price")] Car car)
        {
            if (ModelState.IsValid)
            {
                if (car.IDCar == 0)
                {
                    _context.Add(car);
                }
                else
                {
                    _context.Update(car);
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("Id,Manufacturer,Model,EngineCapacity,TypeOfTransmition,AdditionalCharacteristics,PriceRatio,NumberOfType,NameOfType,PhotoWay")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Create([Bind("Car_Name,Car_Plate,Car_Image,Car_Status")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
        public async Task <IActionResult> Create([Bind("ID,Make")] Manufacturer manufacturer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(manufacturer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(manufacturer));
        }
        public async Task <IActionResult> Create([Bind("ID,UserName,Password,Name,Address,Phone,Status,Gmail,Rule")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View("Index"));
        }
        public async Task <IActionResult> Create([Bind("ID,Name,Status")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View("Index"));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Create([Bind("Id,RegNo,Model,Brand")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Create([Bind("ID,Make,Model,Year,VIN,Color,DealershipID")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
        public async Task <IActionResult> Create([Bind("id,FirstName,LastName,UserName,Email,Company,Position,BirthDate")] Member member)
        {
            if (ModelState.IsValid)
            {
                _context.Add(member);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(member));
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Create([Bind("ManufacterID,ManufacterName")] VehicleManufacter vehicleManufacter)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vehicleManufacter);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehicleManufacter));
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> Create([Bind("FeatureID,FeatureDescription")] VehicleFeature vehicleFeature)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vehicleFeature);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehicleFeature));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> Create([Bind("carID,make,model,year,kilometers")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> Create([Bind("Id,Nombre")] Marca marca)
        {
            if (ModelState.IsValid)
            {
                _context.Add(marca);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(marca));
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> Create([Bind("ID,Name,Email,PhoneNumber")] Dealership dealership)
        {
            if (ModelState.IsValid)
            {
                _context.Add(dealership);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(dealership));
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> Create([Bind("Id,CarDealerName,CityId")] CarDealer carDealer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carDealer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CityId"] = new SelectList(_context.Cities, "Id", "CityName", carDealer.CityId);
            return(View(carDealer));
        }
        public async Task <IActionResult> Create([Bind("Id,OderDate,UserId,Status,TotalPrice")] Oder oder)
        {
            if (ModelState.IsValid)
            {
                _context.Add(oder);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.users, "ID", "Address", oder.UserId);
            return(View(oder));
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> Create([Bind("ID,Model,MaxSpeed,ImageLink,ManufacturerID")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ManufacturerID"] = new SelectList(_context.Manufacturers, "ID", "Make", car.ManufacturerID);
            return(View(car));
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> CreateOrder([Bind("OrderId", "CarId", "ManagerId", "UserId", "StartOfRent", "EndOfRent", "DateOfOrder", "PriceToPay")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                order.DateOfOrder = DateTime.Now;
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(ApplyOrder)));
            }
            return(View(order));
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> Create([Bind("Id,Quantity,price,OderId,ProductId")] OderDetail oderDetail)
        {
            if (ModelState.IsValid)
            {
                _context.Add(oderDetail);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OderId"]    = new SelectList(_context.oders, "Id", "Id", oderDetail.OderId);
            ViewData["ProductId"] = new SelectList(_context.products, "ID", "Color", oderDetail.ProductId);
            return(View(oderDetail));
        }
        public async Task <IActionResult> Create([Bind("ModelID,ModelName,ManufacterID")] VehicleModel vehicleModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vehicleModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            //ViewData["ManufacterID"] = new SelectList(_context.VehicleManufacters, "ManufacterID", "ManufacterID", vehicleModel.ManufacterID);
            PopulateFieldsDropDownList();
            return(View(vehicleModel));
        }
        public async Task <IActionResult> Create([Bind("Id,DealerId,CarId,Count,State")] SupplyRequest supplyRequest)
        {
            if (ModelState.IsValid)
            {
                _context.Add(supplyRequest);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarId"]    = new SelectList(_context.Cars, "Id", "Name", supplyRequest.CarId);
            ViewData["DealerId"] = new SelectList(_context.Dealers, "Id", "Name", supplyRequest.DealerId);
            return(View(supplyRequest));
        }
        public async Task <IActionResult> Create([Bind("CarRegistration,FeatureID")] LinkFeatureToVehicle linkFeatureToVehicle)
        {
            if (ModelState.IsValid)
            {
                _context.Add(linkFeatureToVehicle);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PopulateFieldsDropDownList();
            PopulateFieldsDropDownList2();
            return(View(linkFeatureToVehicle));
        }
        public async Task <IActionResult> Create([Bind("CarRegistration,ModelID,ManufactureYear,ColourID,FuelTypeID,CurrentMilage,VehiclePrice")] VehicleDetail vehicleDetail)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vehicleDetail);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PopulateFieldsDropDownList();
            PopulateFieldsDropDownList2();
            PopulateFieldsDropDownList3();
            return(View(vehicleDetail));
        }
Ejemplo n.º 30
0
        public async Task <IActionResult> Create([Bind("Id,ManufacturerId,CarModel,EngineId,ProductionYear,CarPrice,CardealerId")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CardealerId"]    = new SelectList(_context.CarDealers, "Id", "CarDealerName", car.CardealerId);
            ViewData["EngineId"]       = new SelectList(_context.Engines, "Id", "EngineType", car.EngineId);
            ViewData["ManufacturerId"] = new SelectList(_context.Manufacturers, "Id", "ManufacturerName", car.ManufacturerId);
            return(View(car));
        }