public ActionResult Delete(FormCollection values, int Id) { CheckAda(); ApplicationUser User = GetLoggedInUser(); if (User != null) { try { Image imageEntity = ApplicationDbContext.Images.Find(Id); if (imageEntity != null) { if (imageEntity.User.UserName.Equals(User.Email)) { ApplicationDbContext.Images.Remove(imageEntity); ApplicationDbContext.SaveChanges(); List <int> lstDeleteImage = new List <int>(); lstDeleteImage.Add(imageEntity.Id); ImageStorage.DeleteBlobs(lstDeleteImage, Server); return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction("Error", "Home", new { errid = "DeleteNotAuth" })); } } else { return(RedirectToAction("Error", "Home", new { errid = "DeleteNotFound" })); } } catch (Exception) { return(RedirectToAction("Error", "Home")); } } else { return(RedirectToAction("Login", "Account")); } }
public ActionResult Deactivate(IList <SelectItemView> model) { CheckAda(); ViewBag.Message = string.Empty; using (ApplicationDbContext db = new ApplicationDbContext()) { foreach (var item in model) { ApplicationUser User = db.Users.Find(item.Id); if (User != null) { if (User.Active && item.Active) { List <Image> UserImages = User.Images.ToList <Image>(); List <int> ImagesIds = new List <int>(); foreach (var image in UserImages) { db.Images.Remove(image); if (image.Id != 1) { ImagesIds.Add(image.Id); } } db.Users.Find(item.Id).Active = false; ImageStorage.DeleteBlobs(ImagesIds, Server); } else if (!User.Active && !item.Active) { db.Users.Find(item.Id).Active = true; } } } db.SaveChanges(); ViewBag.Message = "User(s) updated."; } return(View(GetUsers())); }
public ActionResult Approve(IList <SelectImageView> model) { CheckAda(); ViewBag.Message = string.Empty; List <Image> LstDeleteImages = new List <Image>(); List <int> LstDeleteImageBlobs = new List <int>(); foreach (var item in model) { Image image = ApplicationDbContext.Images.Find(item.Id); if (image != null) { if (!image.Approved && item.Approved && !item.Delete) { ApplicationDbContext.Images.Find(item.Id).Approved = true; ViewBag.Message = "Image(s) approved"; } else if (!image.Approved && !item.Approved && item.Delete) { LstDeleteImages.Add(image); LstDeleteImageBlobs.Add(image.Id); } } } ApplicationDbContext.Images.RemoveRange(LstDeleteImages); foreach (var image in LstDeleteImages) { //String imgFileName = Server.MapPath("~/Content/Images/" + image.Id + ".jpg"); ImageStorage.DeleteBlobs(LstDeleteImageBlobs, Server); } ApplicationDbContext.SaveChanges(); ViewBag.SuccessMessage = "Images are approved/deleted successfully."; return(View(GetNotApprovedImages())); }