public void RemoveTest() { ImageDal dal = new ImageDal(); //ImageDetails idetails = new ImageDetails(); //idetails.Id = 5; dal.RemoveImage(1034); List<ImageDetails> result = dal.GetAllImages().FindAll(x => x.Id==1034); Assert.AreEqual(0,result.Count); }
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); } }
protected void Page_Load(object sender, EventArgs e) { try { ImageDal dal = new ImageDal(); FileUpload1.Visible = false; ListView1.DataSource = dal.GetAllImages(); ListView1.DataBind(); Button4.Visible = false; // File.Delete(filepath); } catch (Exception ex) { ImageException exception = new ImageException(ex.Message); } }
protected void Remove_Click(object sender, EventArgs e) { try { ImageDal dal = new ImageDal(); if(hdCheckRadio.Value=="true") dal.RemoveImage(int.Parse(hdSelectedImage.Value)); ListView1.DataSource = dal.GetAllImages(); ListView1.DataBind(); } catch (Exception ex) { ImageException exception = new ImageException(ex.Message); } }