Exemple #1
0
        private void GetImages()
        {
            int brand_id = Convert.ToInt32(Request.QueryString["id"]);;

            //Getting Images Based on This Brand ID
            List <Gallery> images = GalleryDAL.GetImages(brand_id);

            if (images.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Gallery image in images)
                {
                    sb.Append(string.Format(@"
                    <a class='group' rel='gallery' href='../images/gallery/{2}' title='{0}'>
                        <div class='image'>
                            <img src = '../images/gallery/{2}' runat='server' alt='Gallery Image Here' title='{3}' height='300px' />
                        </div>
                    </a>     

                    ", image.image_id, image.brand_id, image.image_name, image.image_title));
                    lblGallery.Text = sb.ToString();
                }
            }
            else
            {
                lblGallery.Text = "No Image Added";
            }
        }
Exemple #2
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            int brand_id = 0;
            //To Get Brand ID
            string            email       = Session["login"].ToString();
            List <brandClass> brandDetail = brandDAL.GetBrandDetailsByEmail(email);

            if (brandDetail.Count == 1)
            {
                foreach (brandClass brand in brandDetail)
                {
                    brand_id = brand.brand_id;
                }
            }
            //For Uploading Image
            Gallery gallery = new Gallery();

            //File Upload Starts Here
            try
            {
                //Upploading Image Here
                if (FileUpload1.HasFile)
                {
                    //Generating RAndom Number
                    Random rand = new Random();
                    //string imagepath;
                    int    guid     = rand.Next();
                    string fileName = guid + Path.GetFileName(FileUpload1.FileName);
                    FileUpload1.PostedFile.SaveAs(Server.MapPath("~/images/gallery/") + fileName);
                    lblImage.Text      = "Image " + fileName + " Successfully Uploaded";
                    gallery.image_name = fileName;
                    //Saving to Database
                    gallery.brand_id    = brand_id;
                    gallery.image_title = txtImageName.Text;

                    //Object for DAL
                    GalleryDAL DAL     = new GalleryDAL();
                    bool       success = DAL.AddImage(gallery);
                    if (success == true)
                    {
                        lblImage.Text     = "Image Successfully Added.";
                        txtImageName.Text = "";
                    }
                    else
                    {
                        lblImage.Text = "Failed to Add new Image";
                    }
                }
                else
                {
                    lblImage.Text = "No Image Selected! Failed to upload image.";
                }
            }
            catch (Exception ex)
            {
                lblImage.Text = "Image Upload Failed";
            }
        }
Exemple #3
0
        public static void AddNewGalleryImage(HttpPostedFileBase fileUpload, int ModelID, string UpdatedBy)
        {
            try
            {
                var FileName = Path.GetFileName(fileUpload.FileName);
                //Make sure we don't attempt to upload a very large file
                if (fileUpload.ContentLength > 1048576) //1MB limit
                {
                    throw new InvalidCastException("File size too big, please make sure your file size is less than 1MB.");
                }

                //We need to check that it's a valid image we have uploaded
                if (!ValidateFileExtension(FileName))
                {
                    //Invalid file type so refuse the upload
                    throw new InvalidCastException("Invalid file type, only files with the extension 'JPG' or 'PNG' allowed.");
                }



                //Now we can try to create our images
                WebImage uploadedImage = new WebImage(fileUpload.InputStream);

                //Now we need to make sure we have the minimum image dimensions as we need to make 3 versions
                if (!ValidateImageSize(uploadedImage))
                {
                    //Invalid image sizes so refuse the upload
                    throw new InvalidCastException("Image is too small, the minimum dimension is Width 200px by Height 150px.");
                }

                //Remove any spaces in the image filename and replace with underscores
                FileName = FileName.Replace(" ", "_");

                //Generate a unique filename, which will include the original name too
                FileName = DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss") + "_" + FileName;

                //Generate the 'save to' path for the raw uploaded file
                var path = HttpContext.Current.Server.MapPath("~/images/uploads/");

                //Now save the original file to disk
                uploadedImage.Save(path + FileName);

                //Generate the thumbnails and save them
                var thumbnailImage = ResizeImage(uploadedImage, "thumb", FileName);
                thumbnailImage.Save(path + thumbnailImage.FileName);
                var smallThumbnailImage = ResizeImage(uploadedImage, "small", FileName);
                smallThumbnailImage.Save(path + smallThumbnailImage.FileName);

                //Finally update the DB now
                GalleryDAL.AddNewGalleryImage(FileName, ModelID, UpdatedBy);
            }
            finally
            {
            }
        }
Exemple #4
0
        public static List <GalleryListViewModel> GetImageGallery(int pageNumber, int numberOfItems, out int numberOfPages)
        {
            List <GalleryListViewModel> myList = new List <GalleryListViewModel>();
            DataTable dt = GalleryDAL.GetImageGalleryList(pageNumber, numberOfItems, out numberOfPages);

            foreach (DataRow row in dt.Rows)
            {
                GalleryListViewModel myListItems = new GalleryListViewModel
                {
                    ImageId        = (int)row["ImageID"],
                    MainImage      = row["ImageName"].ToString().Trim(),
                    ThumbnailImage = row["ImageName"].ToString().Replace(Path.GetExtension(row["ImageName"].ToString()).ToLower(), "_thumb") + Path.GetExtension(row["ImageName"].ToString()).ToLower().Trim(),
                    SmallThumbnail = row["ImageName"].ToString().Replace(Path.GetExtension(row["ImageName"].ToString()).ToLower(), "_small") + Path.GetExtension(row["ImageName"].ToString()).ToLower().Trim(),
                    Manufacturer   = row["Manufacturer"].ToString(),
                    ModelName      = row["ModelName"].ToString(),
                    Disabled       = (bool)row["Disabled"]
                };
                myList.Add(myListItems);
            }
            return(myList);
        }
Exemple #5
0
        public static void DeleteImage(int ImageID)
        {
            //First we delete from SQL, this will return the main image name to allow us to delete the files from the server
            var imageName = GalleryDAL.DeleteGalleryImage(ImageID);

            //Check that we got a value back, if this is an empty string then there was no image to delete
            //and attempting to remove them from the drive will cause an error
            if (imageName != "")
            {
                var path           = HttpContext.Current.Server.MapPath("~/images/uploads/");
                var ThumbnailImage = imageName.Replace(Path.GetExtension(imageName.ToString()).ToLower(), "_thumb") + Path.GetExtension(imageName.ToString()).ToLower().Trim();
                var SmallThumbnail = imageName.Replace(Path.GetExtension(imageName.ToString()).ToLower(), "_small") + Path.GetExtension(imageName.ToString()).ToLower().Trim();
                //Now delete the 3 files
                File.Delete(path + imageName);
                File.Delete(path + ThumbnailImage);
                File.Delete(path + SmallThumbnail);
            }
            else
            {
                throw new InvalidCastException("No image selected for deletion, please use the 'Delete' button to remove the image you wish to delete.");
            }
        }
Exemple #6
0
        private void GetImages()
        {
            int brand_id = 0;
            //To Get Brand ID
            string            email       = Session["login"].ToString();
            List <brandClass> brandDetail = brandDAL.GetBrandDetailsByEmail(email);

            if (brandDetail.Count == 1)
            {
                foreach (brandClass brand in brandDetail)
                {
                    brand_id = brand.brand_id;
                }
            }
            //Getting Images Based on This Brand ID
            List <Gallery> images = GalleryDAL.GetImages(brand_id);

            if (images.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Gallery image in images)
                {
                    sb.Append(string.Format(@"
                    <a class='group' rel='gallery' href='../images/gallery/{2}' title='{0}'>
                        <div class='image'>
                            <img src = '../images/gallery/{2}' runat='server' alt='Gallery Image Here' title='{3}' height='300px' />
                        </div>
                    </a>     

                    ", image.image_id, image.brand_id, image.image_name, image.image_title));
                    lblGallery.Text = sb.ToString();
                }
            }
            else
            {
                lblGallery.Text = "No Image Added";
            }
        }
        public override IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName)
        {
            IController controller = null;
            dynamic     obj        = null;

            switch (controllerName)
            {
            case "Services":
            {
                obj = new ServicesDAL();
                break;
            }

            case "Histories":
            {
                obj = new HistoryDAL();
                break;
            }

            case "Employees":
            {
                obj = new EmployeeDAL();
                break;
            }

            case "AboutClinic":
            {
                obj = new AboutClinicDAL();
                break;
            }

            case "Testimonial":
            {
                obj = new TestimonialsDAL();
                break;
            }

            case "GalleryAdmin":
            {
                obj = new GalleryDAL();
                break;
            }

            case "Gallery":
            {
                obj = new GalleryDAL();
                break;
            }

            case "AdminPartial":
            {
                obj = new PartialPagesDAL();
                break;
            }
            }
            Type controllerType = GetControllerType(requestContext, controllerName);

            if (obj != null)
            {
                controller = Activator.CreateInstance(controllerType, new[] { obj }) as Controller;
            }
            else
            {
                controller = Activator.CreateInstance(controllerType) as Controller;
            }

            return(controller);
        }
Exemple #8
0
 public static DataTable GetJsonImageGallery(int pageNumber, int numberOfItems, out int numberOfPages)
 {
     return(GalleryDAL.GetImageGalleryList(pageNumber, numberOfItems, out numberOfPages));
 }