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 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}; }