public ActionResult AddCar(AddCarViewModel vm) { tblCarsService cservice = new tblCarsService(); tblColorsService colservice = new tblColorsService(); tblBrandsService bservice = new tblBrandsService(); tblCars car = new tblCars(); car.BrandID = vm.selectedBrandId; car.ColorID = vm.selectedColorId; car.CarModel = vm.car.CarModel; car.CarDescription = vm.car.CarDescription; car.CarFuel = vm.fuelChoice.ToString(); car.CarKilometers = vm.car.CarKilometers; car.CarPrice = vm.car.CarPrice; car.CarEquipment = vm.car.CarEquipment; car.CarYearOfConstruction = vm.car.CarYearOfConstruction; car.Sold = (byte)0; car.C02Emissions = vm.car.C02Emissions; car.PowerKW = vm.car.PowerKW; car.PowerPK = vm.car.PowerPK; car.CylinderCapacity = vm.car.CylinderCapacity; car.FirstRegistration = vm.car.FirstRegistration; car.Transmission = vm.transmissionChoice.ToString(); car.Createdate = DateTime.Now.Date; cservice.addCar(car); List <HttpPostedFileBase> files = vm.files.ToList(); for (int i = 0; i < files.Count(); i++) { if (files.ElementAt(i) != null && files.ElementAt(i).ContentLength > 0) { tblImages Image = new tblImages(); System.Diagnostics.Debug.WriteLine("image"); Image.CarID = car.CarID; Image.ImageOrder = i; Image.ImagePath = @"Cars\Car" + car.CarID + @"\Image"; tblImagesService iservice = new tblImagesService(); iservice.AddImage(Image); Image.ImagePath = @"Cars/Car" + car.CarID + @"/Image" + Image.ImageID + ".jpg"; iservice.UpdateImage(Image); CSCBelgiumCloudService cloudservice = new CSCBelgiumCloudService(); cloudservice.UploadImageAsBlob(Image, files.ElementAt(i)); } else { Debug.WriteLine("file null"); } } return(RedirectToAction("CarIndex")); }
public ActionResult EditCar(AddCarViewModel vm) { tblCarsService cservice = new tblCarsService(); tblColorsService colservice = new tblColorsService(); tblBrandsService bservice = new tblBrandsService(); tblImagesService iservice = new tblImagesService(); tblCars car = cservice.getCar(vm.car.CarID); car.BrandID = vm.selectedBrandId; car.ColorID = vm.selectedColorId; car.CarModel = vm.car.CarModel; car.CarDescription = vm.car.CarDescription; car.CarFuel = vm.fuelChoice.ToString(); car.CarKilometers = vm.car.CarKilometers; car.CarPrice = vm.car.CarPrice; car.CarEquipment = vm.car.CarEquipment; car.CarYearOfConstruction = vm.car.CarYearOfConstruction; car.Sold = (byte)0; car.C02Emissions = vm.car.C02Emissions; car.PowerKW = vm.car.PowerKW; car.PowerPK = vm.car.PowerPK; car.CylinderCapacity = vm.car.CylinderCapacity; car.FirstRegistration = vm.car.FirstRegistration; car.Transmission = vm.transmissionChoice.ToString(); car.Createdate = DateTime.Now.Date; cservice.editCar(car); List <HttpPostedFileBase> files = vm.files.ToList(); //ICollection<tblImages> images = cservice.GetImagesByCar(car); //for (int i = 0; i < images.Count() ; i++) //{ // tblImages temp = images.ElementAt(i); // temp.Image = ResizeImage(temp.Image, 0.70f); // iservice.UpdateImage(temp); //} for (int i = 0; i < files.Count(); i++) { if (files.ElementAt(i) != null && files.ElementAt(i).ContentLength > 0) { if (i == 0) { iservice.DeleteAllImagesOfCar(vm.car); } tblImages Image = new tblImages(); System.Diagnostics.Debug.WriteLine("image"); MemoryStream target = new MemoryStream(); files.ElementAt(i).InputStream.CopyTo(target); byte[] image = target.ToArray(); Image.CarID = car.CarID; Image.ImageOrder = i; Image.ImagePath = "Temp"; iservice.AddImage(Image); Image.ImagePath = @"Cars/Car" + car.CarID + @"/Image" + Image.ImageID + ".jpg"; iservice.UpdateImage(Image); } else { Debug.WriteLine("file null"); return(RedirectToAction("CarIndex")); } } return(RedirectToAction("CarIndex")); }