public ActionResult DeleteIt(int id) { LinkedList <rrForumThread> llThread = rrForumThreadDB.GetForumThread( ForumId: rrForumThreadDB.ForumId, ThreadId: id); if (llThread.Count == 0) { ViewData["ErrorMessage"] = string.Format("Тема не найдена"); return(View("Error")); } rrForumThread ForumThread = llThread.First.Value; if (ForumThread.CreatedBy != CurrentUser.UserId) { ViewData["ErrorMessage"] = "Нельзя удалить сообщение созданное другим пользователем"; return(View("Error")); } if (!string.IsNullOrEmpty(ForumThread.FileName)) { string FilePath = Server.MapPath(string.Format("~/Files/{0}", ForumThread.FileName)); System.IO.File.Delete(FilePath); } rrForumThreadDB.DeleteForumThread( ForumId: rrForumThreadDB.ForumId, ThreadId: id); return(ForumRedirect(ForumThread.ThreadParentId)); }
public ActionResult Edit(int id, ForumThread Model) { if (!ModelState.IsValid) { return(View()); } LinkedList <rrForumThread> llThread = rrForumThreadDB.GetForumThread( ForumId: rrForumThreadDB.ForumId, ThreadId: id); if (llThread.Count == 0) { ViewData["ErrorMessage"] = string.Format("Тема не найдена"); return(View("Error")); } rrForumThread ForumThread = llThread.First.Value; string FileName = ForumThread.FileName; if (!string.IsNullOrEmpty(FileName) && (Model.DeleteFile || Model.File != null)) { string FilePath = Server.MapPath(string.Format("~/Files/{0}", FileName)); System.IO.File.Delete(FilePath); FileName = null; } if (Model.File != null && !Model.DeleteFile) { FileName = string.Format("{0}_{1}", Guid.NewGuid().ToString(), Model.File.FileName); var FilePath = Server.MapPath(Path.Combine("~/Files", FileName)); Model.File.SaveAs(FilePath); } if (ForumThread.CreatedBy != CurrentUser.UserId) { ViewData["ErrorMessage"] = "Нельзя редактировать сообщения созданные другими пользователями"; return(View("Error")); } string Title = CurrentUser.UserId != ForumThread.CreatedBy ? ForumThread.Title : Model.Title; string Description = Uri.UnescapeDataString(Model.Description); rrForumThreadDB.UpdateForumThread(ForumId: rrForumThreadDB.ForumId, UserId: CurrentUser.UserId, ThreadId: ForumThread.ThreadId, Title: Model.Title, Description: Description, FileName: FileName); return(ForumRedirect(ForumThread.ThreadParentId)); }
public ForumThread(rrForumThread ForumThread) { ForumThreadId = ForumThread.ThreadId; ThreadParentId = ForumThread.ThreadParentId; Title = ForumThread.Title; Description = ForumThread.Description; Description = Uri.EscapeDataString(ForumThread.Description); FileName = ForumThread.FileName; CreatedBy = ForumThread.CreatedBy; LastUpdatedBy = ForumThread.LastUpdatedBy; CreateDate = ForumThread.CreateDate; LastUpdate = ForumThread.LastUpdate; CreatedByName = ForumThread.CreatedByName; LastUpdatedByName = ForumThread.LastUpdatedByName; IsTopThread = (ForumThread.ThreadParentId == null); }
public ActionResult Delete(int id) { LinkedList <rrForumThread> llThread = rrForumThreadDB.GetForumThread( ForumId: rrForumThreadDB.ForumId, ThreadId: id); if (llThread.Count == 0) { ViewData["ErrorMessage"] = string.Format("Тема не найдена"); return(View("Error")); } rrForumThread ForumThread = llThread.First.Value; return(View(new ForumThread(ForumThread))); }
public ActionResult Reply(int id, string ReplyText) { rrUser User = (rrUser)Session["User"]; if (User == null) { ViewData["ErrorMessage"] = string.Format("Вы не зарегистрированы"); return(View("Error")); } LinkedList <rrForumThread> llThread = rrForumThreadDB.GetForumThread( ForumId: rrForumThreadDB.ForumId, ThreadId: id); if (llThread.Count == 0) { ViewData["ErrorMessage"] = string.Format("Тема не найдена"); return(View("Error")); } rrForumThread ForumThread = llThread.First.Value; rrForumThreadDB.InsertForumThread(ForumId: rrForumThreadDB.ForumId, UserId: User.UserId, Title: ForumThread.Title, ThreadParentId: ForumThread.ThreadId, Description: Uri.UnescapeDataString(ReplyText), FileName: null); LinkedList <rrForumThread> llThreads = rrForumThreadDB.GetForumThread(ForumId: rrForumThreadDB.ForumId, StartThreadId: id); ForumThread[] arrModel = new ForumThread[llThreads.Count]; int i = 0; foreach (rrForumThread Thread in llThreads) { arrModel[i] = new ForumThread(Thread); i++; } return(View("Details", arrModel)); }