public ActionResult Delete(int id) { CheckADA(); ApplicationUser user = getLoggedInUser(); if (user != null) { Image image = db.Images.Find(id); if (image != null) { if (image.userId == user.Id) { db.Entry(image).State = EntityState.Deleted; db.Images.Remove(image); db.SaveChanges(); ImageStorage.deleteFile(Server, id); return(RedirectToAction("Index", "Home")); } else { ViewBag.Message = "you are not uploader of this image and cannot edit it! please login as another user!"; return(RedirectToAction("Login", "Account")); } } else { ViewBag.Message = "image not found"; ViewBag.id = id; return(View("Query")); } } else { ViewBag.Message = "no such user registered!"; return(RedirectToAction("Register", "Account")); } }