views:

34

answers:

2

Hi,

I have an Employee object which has an image property. Image class contains image metadata as image caption, and image file name.

If I upload a new image for an employee on async way without full post back the new image is not appeared on the page.

I use GUID to name the image file to avoid the page caching.

I do the image modifying the following way:

ctrEmployee employee = Repository.Get(PassedItemID);

        if (employee.ctrImage != null)
        {
            string fullFileName = serverFolder + employee.ctrImage.FileName;

            FileInfo TheFile = new FileInfo(fullFileName);

            if (TheFile.Exists)
            {
                TheFile.Delete();
            }


            fileName = Guid.NewGuid() + ".jpg";
            employee.ctrImage.FileName = fileName;
        }

        resizedBmp.Save(string.Format("{0}{1}", serverFolder, fileName), System.Drawing.Imaging.ImageFormat.Jpeg);

        Repository.Edit<ctrEmployee>(employee);

        ImageID = employee.Image.Value;


        return PartialView(UserControlPaths.Thumbnail, new ThumbnailDataModel(employee.Image.Value, 150, 150));

The partial view has an image tag which gets the saved image url string which is a GUID.

Anybody has an idea what I do wrong?

A: 

Can you share your Repository.Edit<ctrEmployee>(employee); method. Is it void?

mmcteam.com.ua
Yes it is a void method.I use a Generic repostory pattern so the Repostory.Edit does this:var originalEntity = Get<T>(GetKeyPropertyValue<T>(entityToEdit)); _context.ApplyCurrentValues(GetEntitySetName<T>(), entityToEdit); } _context.SaveChanges();
Is value for ImageID is as you expect?May be you have to make enployee.Image.Load() call?In any case i can't understand how you can get same image for employee if you have deleted it..And also what is employee.ctrImage?
mmcteam.com.ua
A: 

I found a bug in my head :)

The problem was that the url string didn't changed so the browser didn't refresh the image.

l.