public ActionResult Edit(Profile member)
        {
            try
            {
                MemberProvider memberProvider = new MemberProvider();
                AspNetUserImagesProvider _aspNetUserImagesProvider = new AspNetUserImagesProvider();

                var userId = User.Identity.GetUserId();
                var user = memberProvider.Single(u => u.Id.Equals(userId, StringComparison.OrdinalIgnoreCase));

                // TODO: UPDATE IMAGES HERE
                var images = _aspNetUserImagesProvider.List(i=>i.UserId.Equals(userId,StringComparison.OrdinalIgnoreCase)).ToList();
                    images.ForEach(i => i.IsInUse = false);
                    _aspNetUserImagesProvider.Update(images.ToArray());

                var newProfile = _aspNetUserImagesProvider.Single(i => i.AspNetUserImageId == member.ProfileImageId);
                    newProfile.IsInUse = true;
                    _aspNetUserImagesProvider.Update(newProfile);
                //END IMAGES HERE

                return RedirectToAction("Wall");
            }
            catch
            {
                return View();
            }
        }
        public ContentResult FileUpload()
        {
            ControllerContext context = this.ControllerContext;

            //Get users current id and store image
            var userId = User.Identity.GetUserId();
            var virtualImagePath = System.Configuration.ConfigurationManager.AppSettings["VirtualImagePath"];
            var actualImagepath = Server.MapPath(virtualImagePath);

               // string path = AppDomain.CurrentDomain.BaseDirectory + "uploads/";

            string filename = Path.GetFileName(Request.Files[0].FileName);
            string directory = string.Concat(actualImagepath, "\\Users\\", userId, "\\profile\\");

            if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);

            Request.Files[0].SaveAs(Path.Combine(directory, filename));

            //Add new image to database and set all existing in use to false.
            var virtualProfileImagePath = string.Concat(virtualImagePath, "/users/", userId, "/profile/", Request.Files[0].FileName);

            AspNetUserImagesProvider _aspNetUserImagesProvider = new AspNetUserImagesProvider();

            var newImage = new AspNetUserImages();
            newImage.UserImage = virtualProfileImagePath;
            newImage.UserId = userId;
                newImage.IsInUse = false;
            _aspNetUserImagesProvider.Add(newImage);

            ProfileUploadResult result = new ProfileUploadResult();
            result.ImageId = newImage.AspNetUserImageId;
            result.ImagePath = newImage.UserImage;

            var json = new JavaScriptSerializer().Serialize(result);

            return Content(json, "text/json");
        }
        public ContentResult DeleteProfileImage(string id)
        {
            var aspNetUserImagesProvider = new AspNetUserImagesProvider();
            var message = string.Empty;

            int imageId;

            if (int.TryParse(id, out imageId))
            {
                var image = aspNetUserImagesProvider.Single(a => a.AspNetUserImageId == imageId);
                if (image.UserImage.Equals("\\images\\default\\profile.png", StringComparison.OrdinalIgnoreCase))
                {
                    message = "Cannot delete the default profile image";
                }
                else
                {
                    aspNetUserImagesProvider.Remove(image);
                    var defaultImage =
                        aspNetUserImagesProvider.Single(
                            i =>
                                i.UserImage.Equals("\\images\\default\\profile.png", StringComparison.OrdinalIgnoreCase) && i.UserId.Equals(image.UserId,StringComparison.OrdinalIgnoreCase));
                    defaultImage.IsInUse = true;
                    aspNetUserImagesProvider.Update(defaultImage);

                }
            }
            else
            {
                message = "Unable to find image";
            }
            return new ContentResult {Content = message};
        }