Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Year,Price,State,ModelId,EngineVolume,Mileage,FuelTypeId,BodyTypeId,TransmissionTypeId,ImagesDirectoryPath")] Car car)
        {
            if (id != car.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(car);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarExists(car.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["State"]      = new SelectList(Enum.GetNames(typeof(Car.CarState)), car.State);
            ViewData["BodyTypeId"] = new SelectList(_context.BodyTypes, "Id", "Name", car.BodyTypeId);
            ViewData["FuelTypeId"] = new SelectList(_context.FuelTypes, "Id", "Name", car.FuelTypeId);

            ViewData["ModelId"]            = new SelectList(CreateViewModel(), "ModelId", "ModelNameWithBrand", car.ModelId);
            ViewData["TransmissionTypeId"] = new SelectList(_context.TransmissionTypes, "Id", "Name", car.TransmissionTypeId);
            return(View(car));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,BrandId,ParentId")] CarModel carModel)
        {
            if (id != carModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(carModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarModelExists(carModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                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));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Status")] Category category)
        {
            if (id != category.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View("Index"));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Email,PhoneNumber")] Dealership dealership)
        {
            if (id != dealership.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(dealership);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DealershipExists(dealership.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(dealership));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Car_Name,Car_Plate,Car_Image,Car_Status")] Car car)
        {
            if (id != car.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(car);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarExists(car.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("ManufacterID,ManufacterName")] VehicleManufacter vehicleManufacter)
        {
            if (id != vehicleManufacter.ManufacterID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vehicleManufacter);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VehicleManufacterExists(vehicleManufacter.ManufacterID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehicleManufacter));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nombre")] Marca marca)
        {
            if (id != marca.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(marca);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MarcaExists(marca.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(marca));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CityName")] City city)
        {
            if (id != city.Id)
            {
                return(NotFound());
            }
            //this code checks if there is a city with the given name in _context
            if (_context.Cities
                .Any(x => x.CityName == city.CityName))
            {
                return(RedirectToAction(nameof(Index)));
            }

            if (ModelState.IsValid)
            {
                try                        // Why you don't try?
                {
                    _context.Update(city); // Här smäller den
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CityExists(city.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(city));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,OderDate,UserId,Status,TotalPrice")] Oder oder)
        {
            if (id != oder.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(oder);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OderExists(oder.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.users, "ID", "Address", oder.UserId);
            return(View(oder));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Quantity,price,OderId,ProductId")] OderDetail oderDetail)
        {
            if (id != oderDetail.OderId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(oderDetail);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OderDetailExists(oderDetail.OderId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                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));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Manufacturer,Model,EngineCapacity,TypeOfTransmition,AdditionalCharacteristics,PriceRatio,NumberOfType,NameOfType,PhotoWay")] Car car)
        {
            if (id != car.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(car);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarExists(car.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,UserName,Password,Name,Address,Phone,Status,Gmail,Rule")] User user)
        {
            if (id != user.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View("Index"));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ManufacturerName")] Manufacturer manufacturer)
        {
            if (id != manufacturer.Id)
            {
                return(NotFound());
            }

            if (_context.Manufacturers
                .Any(x => x.ManufacturerName == manufacturer.ManufacturerName))
            {
                return(RedirectToAction(nameof(Index)));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(manufacturer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ManufacturerExists(manufacturer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(manufacturer));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Email,Phone,BrandId")] Dealer dealer)
        {
            if (id != dealer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(dealer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DealerExists(dealer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BrandId"] = new SelectList(_context.Brands, "Id", "Id", dealer.BrandId);
            return(View(dealer));
        }
        public async Task <IActionResult> Edit(int id, [Bind("id,FirstName,LastName,UserName,Email,Company,Position,BirthDate")] Member member)
        {
            if (id != member.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(member);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MemberExists(member.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(member));
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Model,MaxSpeed,ImageLink,ManufacturerID")] Car car)
        {
            if (id != car.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(car);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarExists(car.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ManufacturerID"] = new SelectList(_context.Manufacturers, "ID", "Make", car.ManufacturerID);
            return(View(car));
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ManufacturerId,CarModel,EngineId,ProductionYear,CarPrice,CardealerId")] Car car)
        {
            if (id != car.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(car);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarExists(car.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                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));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CarDealerName,CityId")] CarDealer carDealer)
        {
            if (id != carDealer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(carDealer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarDealerExists(carDealer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CityId"] = new SelectList(_context.Cities, "Id", "CityName", carDealer.CityId);
            return(View(carDealer));
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> Edit(int id, [Bind("carID,make,model,year,kilometers")] Car car)
        {
            if (id != car.carID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(car);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarExists(car.carID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
        public async Task <IActionResult> Edit(string id, [Bind("CarRegistration,FeatureID")] LinkFeatureToVehicle linkFeatureToVehicle)
        {
            if (id != linkFeatureToVehicle.CarRegistration)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(linkFeatureToVehicle);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LinkFeatureToVehicleExists(linkFeatureToVehicle.CarRegistration))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            PopulateFieldsDropDownList();
            PopulateFieldsDropDownList2();
            return(View(linkFeatureToVehicle));
        }
        public async Task <IActionResult> Edit(string id, [Bind("CarRegistration,ModelID,ManufactureYear,ColourID,FuelTypeID,CurrentMilage,VehiclePrice")] VehicleDetail vehicleDetail)
        {
            if (id != vehicleDetail.CarRegistration)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vehicleDetail);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VehicleDetailExists(vehicleDetail.CarRegistration))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            PopulateFieldsDropDownList();
            PopulateFieldsDropDownList2();
            PopulateFieldsDropDownList3();
            return(View(vehicleDetail));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ModelID,ModelName,ManufacterID")] VehicleModel vehicleModel)
        {
            if (id != vehicleModel.ModelID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vehicleModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VehicleModelExists(vehicleModel.ModelID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            //ViewData["ManufacterID"] = new SelectList(_context.VehicleManufacters, "ManufacterID", "ManufacterID", vehicleModel.ManufacterID);
            PopulateFieldsDropDownList(id);
            return(View(vehicleModel));
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> Edit(int id, [Bind("FeatureID,FeatureDescription")] VehicleFeature vehicleFeature)
        {
            if (id != vehicleFeature.FeatureID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vehicleFeature);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VehicleFeatureExists(vehicleFeature.FeatureID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehicleFeature));
        }
Ejemplo n.º 24
0
        public void setCarToNotAvaiable(int id)
        {
            Car car = car_context.Car.Find(id);

            car.Car_Status = 1;

            car_context.Update(car);
            car_context.SaveChangesAsync();
        }
        public async Task <IActionResult> Create([Bind("ID,Name,SerialNumber,Description,Content,Color,Price,Status,Imgage,CategoryID,BrandID,Namsx,NgayNhapKhau,TinhTrang,DongCo")] Product product, IFormFile ful)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/pro", product.ID + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await ful.CopyToAsync(stream);
                }
                product.Imgage = product.ID + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1];
                _context.Update(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Marca,Descripcion,Modelo,Precio,Estado,Foto")] EditCarViewModel car)
        {
            if (id != car.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    Car myCar = _context.Car.Find(id);

                    myCar.Descripcion = car.Descripcion;
                    myCar.Modelo      = car.Modelo;
                    myCar.Precio      = car.Precio;
                    myCar.Estado      = car.Estado;
                    myCar.Kilometros  = car.Kilometros;
                    myCar.MarcaId     = car.Marca;

                    if (car.Foto != null)
                    {
                        if (car.ExistPathImg != null)
                        {
                            string pathImg = Path.Combine(hosting.WebRootPath, "img", car.ExistPathImg);
                            System.IO.File.Delete(pathImg);
                        }

                        myCar.PathImg = UploadImage(car);
                    }

                    _context.Update(myCar);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarExists(car.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
        public async Task <IActionResult> SendRequest(int id)
        {
            var supplyRequest = await _context.SupplyRequests.FindAsync(id);

            supplyRequest.State = SupplyRequest.SupplyRequestState.Sent;
            _context.Update(supplyRequest);
            var car = await _context.Cars.FindAsync(supplyRequest.CarId);

            car.Presence = Car.CarPresence.AwaitingDelivery;
            _context.Update(car);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 28
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Logo,Status")] Brand brand, IFormFile ful)
        {
            if (id != brand.Id)
            {
                return(NotFound());
            }

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


                    _context.Update(brand);

                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BrandExists(brand.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View("Index"));
        }
Ejemplo n.º 29
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.º 30
0
        public async Task <IActionResult> AddOrEdit([Bind("CarId,Manufacturer,Model,Year,ProductRegion")] Car car)
        {
            if (ModelState.IsValid)
            {
                if (car.CarId == 0)
                {
                    _context.Add(car);
                }
                else
                {
                    _context.Update(car);
                }
                await _context.SaveChangesAsync();

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