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)); }
public ActionResult Verification(string VerificationCode) { EGalleryEntities db = new EGalleryEntities(); int id = Int32.Parse(Session["UserUrl"].ToString()); Verification verification = db.Verification.FirstOrDefault(v => v.UserId == id); if (verification.VerificationCode == VerificationCode) { db.Verification.Remove(verification); db.SaveChanges(); FormsAuthentication.SetAuthCookie(Session["UserUrl"].ToString(), false); Session.Remove("UserUrl"); return(View("Greeting")); } else { if ((--verification.NumberAttempts) == 0) { Users User = db.Users.FirstOrDefault(u => u.Id == id); db.Users.Remove(User); db.SaveChanges(); return(View("Login")); } db.SaveChanges(); ModelState.AddModelError("VerificationCode", Resources.Resource.VerificationCode); return(View()); } }
public ActionResult Registration(AccountModel account) { if (ModelState.IsValid) { Users user = null; using (EGalleryEntities db = new EGalleryEntities()) { user = db.Users.FirstOrDefault(u => u.Email == account.Email); if (user == null) { user = new Users() { Email = account.Email, Password = account.Password, Nick = account.Username }; db.Users.Add(user); db.SaveChanges(); Session["UserUrl"] = user.UserURL; ModelState.Clear(); SendEmail.SendVerificationCode(user.Email, user.Nick, user.Id); return(View("Verification")); } else { ModelState.AddModelError("Email", Resources.Resource.EmailExist); } } } return(View()); }
public ActionResult Login(LoginModel model) { using (EGalleryEntities db = new EGalleryEntities()) { Users user = db.Users.FirstOrDefault(u => u.Email == model.Email && u.Password == model.Password); if (user != null) { user.State = "online"; db.SaveChanges(); Response.Cookies.Add(EditLanguageUserPage.EditLanguage(user.CodeLanguage, Request.Cookies["lang"])); if (user.Verification.Count == 0) { FormsAuthentication.SetAuthCookie(user.UserURL, false); return(RedirectToAction("Home", "Gallery", new RouteValueDictionary( new { controller = "Gallery", action = "Home", id = user.UserURL }))); } else { Session["UserUrl"] = user.UserURL; return(View("Verification")); } } else { ModelState.Clear(); ModelState.AddModelError("", Resources.Resource.NoSuchUser); } } return(View()); }
public JsonResult EditNick(string Nick) { EGalleryEntities db = new EGalleryEntities(); var user = db.Users.FirstOrDefault(u => u.UserURL == User.Identity.Name); user.Nick = Nick; db.SaveChanges(); return(Json(true, JsonRequestBehavior.AllowGet)); }
public JsonResult SetStatusUser(string Status) { EGalleryEntities db = new EGalleryEntities(); var user = db.Users.FirstOrDefault(u => u.UserURL == User.Identity.Name); user.Status = Status; db.SaveChanges(); return(Json(true, JsonRequestBehavior.AllowGet)); }
private PicturesWaiting GetPicture(string UrlImage, Status status, string Message) { EGalleryEntities db = new EGalleryEntities(); var Picture = db.PicturesWaiting.FirstOrDefault(im => im.Name == UrlImage); Picture.Status = (int)status; db.SaveChanges(); AnswerUser(Message, Picture.Id, Picture.UserId); return(Picture); }
public ActionResult EditLanguage(string CodeLanguage) { EGalleryEntities db = new EGalleryEntities(); var user = db.Users.FirstOrDefault(u => u.UserURL == User.Identity.Name); user.CodeLanguage = CodeLanguage; db.SaveChanges(); Response.Cookies.Add(EditLanguageUserPage.EditLanguage(user.CodeLanguage, Request.Cookies["lang"])); return(View("Edit")); }
public ActionResult Logout() { EGalleryEntities db = new EGalleryEntities(); var user = db.Users.FirstOrDefault(u => u.UserURL == User.Identity.Name); user.State = "offline"; db.SaveChanges(); FormsAuthentication.SignOut(); return(View("Login")); }
public JsonResult ReadAnswer(string NameImage, string Directory) { EGalleryEntities db = new EGalleryEntities(); var Image = db.PicturesWaiting.FirstOrDefault(p => p.Name == NameImage); var Answer = db.Answers.FirstOrDefault(a => a.PictureId == Image.Id); db.Answers.Remove(Answer); db.SaveChanges(); System.IO.File.Delete(GetPathToImg(Image.Name + "." + Image.Expansion, Directory)); return(Json(true, JsonRequestBehavior.AllowGet)); }
public JsonResult Block(string UrlImage) { EGalleryEntities db = new EGalleryEntities(); var Picture = GetPicture(UrlImage, Status.BLOCK, "Block"); MoveFile(Picture.Name + "." + Picture.Expansion, Picture.Name + "." + Picture.Expansion, "expectation", "block"); var user = db.Users.Find(Picture.UserId); user.Permission--; db.SaveChanges(); return(Json(true, JsonRequestBehavior.AllowGet)); }
private void AnswerUser(string Message, int ImageId, int UserId) { EGalleryEntities db = new EGalleryEntities(); Users user = db.Users.Find(UserId); Answers answer = new Answers() { UserId = user.Id, PictureId = ImageId, Text = user.Nick + ", your image: " + Message + "." }; db.Answers.Add(answer); db.SaveChanges(); }
public JsonResult EditAvatar(string fileData, string expansion) { EGalleryEntities db = new EGalleryEntities(); var user = db.Users.FirstOrDefault(u => u.UserURL == User.Identity.Name); if (user.Avatar != "http://www.teniteatr.ru/assets/no_avatar-e557002f44d175333089815809cf49ce.png") { System.IO.File.Delete(GetPathToImg(user.Avatar, "avatar")); } ImageSave.Save(fileData, GetPathToImg(user.UserURL + "." + expansion, "avatar")); user.Avatar = Url.Content("~/Images/avatar/" + user.UserURL + "." + expansion); db.SaveChanges(); return(Json(true, JsonRequestBehavior.AllowGet)); }
public JsonResult SetComment(string UrlImage, string Comment) { EGalleryEntities db = new EGalleryEntities(); var Image = db.Images.FirstOrDefault(img => img.Name == UrlImage); var UserId = Int32.Parse(User.Identity.Name); var CommentImage = new CommentsToImages() { Comment = Comment, UserId = UserId, ImageId = Image.Id }; db.CommentsToImages.Add(CommentImage); db.SaveChanges(); return(Json(true, JsonRequestBehavior.AllowGet)); }
public ActionResult EditPassword(UpdatePassword model) { if (ModelState.IsValid) { EGalleryEntities db = new EGalleryEntities(); var user = db.Users.FirstOrDefault(u => u.UserURL == User.Identity.Name); if (user.Password == model.OldPassword) { user.Password = model.NewPassword; db.SaveChanges(); ViewBag.Message = "Edit Password"; } else { ModelState.AddModelError("OldPassword", "You have entered the wrong password"); } } return(PartialView()); }
public JsonResult Accect(string UrlImage) { EGalleryEntities db = new EGalleryEntities(); var Picture = GetPicture(UrlImage, Status.VIEW, "Accect"); var Image = new Images() { Expansion = Picture.Expansion, DateUpload = Picture.DateUpload, UserId = Picture.UserId }; db.Images.Add(Image); db.SaveChanges(); var url = Picture.Name + "." + Picture.Expansion; System.IO.File.Copy(GetPathToImg(url, "expectation"), GetPathToImg(url, "view")); MoveFile(url, Image.Name + "." + Image.Expansion, "expectation", "gallery"); return(Json(true, JsonRequestBehavior.AllowGet)); }
public JsonResult GetInformationImage(string UrlImage) { EGalleryEntities db = new EGalleryEntities(); var Image = db.Images.FirstOrDefault(img => img.Name == UrlImage); var Author = db.Users.Find(Image.UserId); Image.CountView++; db.SaveChanges(); var informationImage = new ImageInformation() { CountLike = db.LikesToImages.Where(li => li.ImageId == Image.Id).Count(), CountView = Image.CountView, UploadData = Convert.ToString(Image.DateUpload), AuthorName = Author.Nick, UrlUser = Author.UserURL, Avatar = Author.Avatar }; return(Json(informationImage, JsonRequestBehavior.AllowGet)); }
public JsonResult PutImageLikes(string UrlImage) { EGalleryEntities db = new EGalleryEntities(); var Image = db.Images.FirstOrDefault(img => img.Name == UrlImage); var UserId = Int32.Parse(User.Identity.Name); var UserLike = db.LikesToImages.FirstOrDefault(li => li.ImageId == Image.Id && li.UserId == UserId); if (UserLike == null) { db.LikesToImages.Add(new LikesToImages() { UserId = UserId, ImageId = Image.Id }); } else { db.LikesToImages.Remove(UserLike); } db.SaveChanges(); return(Json(db.Images.FirstOrDefault(img => img.Id == Image.Id).LikesToImages.Count, JsonRequestBehavior.AllowGet)); }