public void SortTestWithName()
        {
            ImageDal dal = new ImageDal();

            ImageDetails idetails = new ImageDetails();
            idetails.Name = "Lighthouse.jpg";
            idetails.Image = new byte[] { };
            idetails.Size = 100;

            dal.AddImage(idetails);

             ImageDetails idetails1 = new ImageDetails();
            idetails.Name = "Desert.jpg";
            idetails.Image = new byte[] { };
            idetails.Size = 100;

            dal.AddImage(idetails);

            int index1 = dal.Sort(1).FindLastIndex(x => x.Name == "Lighthouse.jpg");
            int index2 = dal.Sort(1).FindLastIndex(x => x.Name == "Desert.jpg");

            Assert.IsTrue(index1 > index2);

            



        }
        public void AddImageTest()
        {

            ImageDal dal = new ImageDal();
            ImageDetails idetails = new ImageDetails();
            idetails.Name = "Lighthouse.jpg";
            idetails.Image = new byte[] { };
            idetails.Size = 100;
            
            dal.AddImage(idetails);

            List<ImageDetails> resultlist = dal.GetAllImages().FindAll(x => x.Name == "Lighthouse.jpg");
            Assert.AreNotEqual(0, resultlist.Count);

        }
        protected void Upload_Click(object sender, EventArgs e)
        {

            try
            {

                if (FileUpload1.HasFile)
                {
                    ImageDetails iDetails = new ImageDetails();
                    iDetails.Name = FileUpload1.FileName;

                    File.WriteAllBytes(filepath, FileUpload1.FileBytes);

                    FileUpload1.SaveAs(filepath + FileUpload1.FileName);


                    FileInfo fInfo = new FileInfo(filepath);

                    long numBytes = fInfo.Length;

                    //Open FileStream to read file
                    FileStream fStream = new FileStream(filepath, FileMode.Open, FileAccess.Read);

                    //Use BinaryReader to read file stream into byte array.
                    BinaryReader br = new BinaryReader(fStream);

                    //storing byte information in Image field
                    iDetails.Image = br.ReadBytes((int)numBytes);

                    iDetails.Size = numBytes;

                    ImageDal dal = new ImageDal();

                    dal.AddImage(iDetails);

                    ListView1.DataSource = dal.GetAllImages();
                    ListView1.DataBind();


                }
            }
            catch (Exception ex)
            {
                ImageException exception = new ImageException(ex.Message);

            }

        }
        public void AddImage(ImageDetails newImage)
        {
            using (ImageClassesDataContext context = new ImageClassesDataContext())
            {
                try
                {

                    ImageTable entity = new ImageTable();
                    entity.Name = newImage.Name;
                    entity.Image = newImage.Image;
                    entity.Size = newImage.Size;
                    context.ImageTables.InsertOnSubmit(entity);
                    context.SubmitChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }


            }

        }
        //Helper method
        private static void AddToImagelist(List<ImageDetails> imageList, List<ImageTable> result)
        {
            foreach (var item in result)
            {

                ImageDetails imageDetail = new ImageDetails();
                imageDetail.Id = item.Id;
                imageDetail.Image = item.Image.ToArray();
                imageDetail.Size = item.Size;
                imageDetail.Name = item.Name;
                imageDetail.ImageUrl = "data:image/jpg;base64," + Convert.ToBase64String(imageDetail.Image, 0, imageDetail.Image.Length);
                imageList.Add(imageDetail);

            }
        }