public JsonResult DeleteImage(string UrlImage) { EGalleryEntities db = new EGalleryEntities(); var Image = db.Images.FirstOrDefault(img => img.Name == UrlImage); if (User.IsInRole("Moderator") && User.Identity.Name != Image.Users.UserURL) { var Picture = new PicturesWaiting() { Expansion = Image.Expansion, DateUpload = Image.DateUpload, UserId = Image.UserId, Status = (int)Status.BLOCK }; db.PicturesWaiting.Add(Picture); db.SaveChanges(); MoveFile(Image.Name + "." + Image.Expansion, Picture.Name + "." + Picture.Expansion, "gallery", "block"); AnswerUser("Delete", Picture.Id, Picture.UserId); } else { System.IO.File.Delete(GetPathToImg(Image.Name + "." + Image.Expansion, "gallery")); } db.Images.Remove(Image); db.SaveChanges(); return(Json(true, JsonRequestBehavior.AllowGet)); }
public JsonResult AddImageAjax(string expansion, string fileData) { EGalleryEntities db = new EGalleryEntities(); Users user = db.Users.FirstOrDefault(u => u.UserURL == User.Identity.Name); var permission = user.Permission > 0; if (permission) { if (User.IsInRole("Moderator")) { Images image = new Images { Expansion = expansion.ToLower(), UserId = user.Id }; db.Images.Add(image); db.SaveChanges(); ImageSave.Save(fileData, GetPathToImg(image.Name + "." + image.Expansion, "gallery")); } else { PicturesWaiting image = new PicturesWaiting { Expansion = expansion.ToLower(), UserId = user.Id, Status = (int)Status.WAITING }; db.PicturesWaiting.Add(image); db.SaveChanges(); ImageSave.Save(fileData, GetPathToImg(image.Name + "." + image.Expansion, "expectation")); } } return(Json(permission, JsonRequestBehavior.AllowGet)); }