示例#1
0
 public void UpdateImage(tblImages image)
 {
     using (var db = new CSCbelgiumDatabaseEntities())
     {
         db.Entry(image).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
示例#2
0
 public void AddImage(tblImages image)
 {
     using (var db = new CSCbelgiumDatabaseEntities())
     {
         db.tblImages.Add(image);
         db.SaveChanges();
     }
 }
示例#3
0
        public void UploadImageAsBlob(tblImages image, HttpPostedFileBase file)
        {
            file.InputStream.Position = 0;
            CloudBlobContainer container = blobClient.GetContainerReference("filesystem");
            CloudBlockBlob     blockBlob = container.GetBlockBlobReference(image.ImagePath);

            blockBlob.Properties.ContentType = "image/jpg";
            MemoryStream target = new MemoryStream();

            file.InputStream.CopyTo(target);
            byte[] Image = target.ToArray();
            blockBlob.UploadFromByteArray(Image, 0, Image.Length);
        }
示例#4
0
        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"));
        }
示例#5
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"));
        }
示例#6
0
 public void UploadImageAsBlob(tblImages image, HttpPostedFileBase file)
 {
     storage.UploadImageAsBlob(image, file);
 }
        public ActionResult Process(HttpPostedFileBase photo)
        {
            if (photo == null)
            {
                ViewBag.Error = "Nie wybrano pliku";
                return(View("Index"));
            }

            if (!IsValidCVontentType(photo.ContentType))
            {
                ViewBag.Error = "Dostępne formaty to [PNG] [JPG] [PDF]";
                return(View("Index"));
            }
            else if (!isValidContentLength(photo.ContentLength))
            {
                ViewBag.Error = "Za duzy plik";
                return(View("Index"));
            }
            else
            {
                if (photo.ContentLength > 0)
                {
                    DbDataContext cos = new DbDataContext();
                    StringBuilder sb  = new StringBuilder();

                    byte[] bytes;
                    var    fileName = Path.GetFileName(photo.FileName);
                    // var path = Path.Combine(Server.MapPath())
                    ViewBag.TypeOfFile = FilesType(photo.ContentType);
                    ViewBag.fileName   = photo.FileName;



                    using (BinaryReader br = new BinaryReader(photo.InputStream))
                    {
                        bytes = br.ReadBytes(photo.ContentLength);
                    }

                    var item = new tblImages
                    {
                        Id        = 1,
                        ImageDate = bytes,
                        Size      = 5,
                        Name      = fileName,
                    };
                    list.Add(new tblImages()
                    {
                        Id = item.Id, ImageDate = item.ImageDate, Size = item.Size, Name = item.Name
                    });
                    //string base64 = Convert.ToBase64String(bytes);
                    cos.Files.Add(new tblImages
                    {
                        Id        = 4,
                        Name      = fileName,
                        Size      = 6,
                        ImageDate = bytes
                    });

                    cos.SaveChanges();

                    //  @ViewBag.picture = (bytes);
                }

                return(View("Success"));
            }
            //
        }
 public void UpdateImage(tblImages image)
 {
     dao.UpdateImage(image);
 }
 public void AddImage(tblImages image)
 {
     dao.AddImage(image);
 }