Пример #1
0
        //TEMP

        //private static byte[] ResizeImage(byte[] array, float resizePercentage,bool OnlyWhenGreaterThan800kB = false)
        //{
        //    if (OnlyWhenGreaterThan800kB)
        //    {
        //        if (array.Length < 800000)
        //        {
        //            Debug.WriteLine("Afbeelding is reeds kleiner dan 800 kB");
        //            return array;
        //        }
        //    }
        //    Bitmap image;
        //    using (var ms = new System.IO.MemoryStream(array))
        //    {
        //        image = new Bitmap(ms);
        //    }
        //    int currentWidth = image.Width;
        //    int currentHeight = image.Height;
        //    int width = (int)((float)currentWidth * resizePercentage);
        //    int height = (int)((float)currentHeight * resizePercentage);
        //    Bitmap resizedImage = new Bitmap(width, height);
        //    using (Graphics gfx = Graphics.FromImage(resizedImage))
        //    {
        //        gfx.DrawImage(image, new Rectangle(0, 0, width, height),
        //            new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
        //    }
        //    ImageConverter converter = new ImageConverter();
        //    return (byte[])converter.ConvertTo(resizedImage, typeof(byte[]));

        //}

        //END TEMP
        public ActionResult CarDetails(int carID)
        {
            CarDetailsViewModel vm      = new CarDetailsViewModel();
            tblCarsService      service = new tblCarsService();

            if (service.isSold(service.getCar(carID)))
            {
                return(HttpNotFound());
            }
            else
            {
                tblBrandsService bservice = new tblBrandsService();
                vm.car              = service.getCar(carID);
                vm.images           = service.GetImagesByCar(vm.car);
                vm.car.CarEquipment = Regex.Replace(vm.car.CarEquipment, @"\r\n?|\n", ",");
                vm.carbrand         = bservice.getBrand(vm.car.BrandID).BrandName;
                vm.carmodel         = vm.car.CarModel;
                return(View(vm));
            }
        }
Пример #2
0
        public ActionResult EditCar(int carID)
        {
            EditCarViewModel vm         = new EditCarViewModel();
            tblCarsService   cservice   = new tblCarsService();
            tblColorsService colservice = new tblColorsService();
            tblBrandsService bservice   = new tblBrandsService();

            vm.car                = cservice.getCar(carID);
            vm.selectedBrandId    = vm.car.BrandID;
            vm.selectedColorId    = vm.car.ColorID;
            vm.brandChoice        = bservice.getBrands();
            vm.colorChoice        = colservice.getColors();
            vm.fuelChoice         = (Fuel)Enum.Parse(typeof(Fuel), vm.car.CarFuel, true);
            vm.transmissionChoice = (Transmission)Enum.Parse(typeof(Transmission), vm.car.Transmission, true);

            return(View(vm));
        }
Пример #3
0
        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"));
        }