public ThreadDetailsMenuModel(Thread thread,ICollection<MenuButtons> activeButtons, Post post) { Thread = thread; ActiveButtons = activeButtons; Post = post; }
public void MoveAttachmentsFromTemporaryFolder(string temporaryAttachmentFolder, int threadId) { var attachmentsDirPath = HttpContext.Server.MapPath("~/Attachments/"); Directory.SetCurrentDirectory(attachmentsDirPath); var destinationDir = "Thread_" + threadId; Directory.Move(attachmentsDirPath + temporaryAttachmentFolder, attachmentsDirPath + destinationDir); var thread = Repository.Thread.Get(threadId); var post = new Post { Attachments = new List<Attachment>(), Author = thread.Author, Type = PostType.Attachment, Content = "Pytanie zawiera załączniki" }; var directoryInfo = new DirectoryInfo(attachmentsDirPath + destinationDir); foreach (var file in directoryInfo.GetFiles()) { var attachment = new Attachment { AttachmentName = file.Name, AttachmentPath = string.Format("\\Attachments\\{0}\\{1}", destinationDir, file.Name), Author = thread.Author, ContentType = file.Extension, AttachmentSize = (int)file.Length }; attachment.Type = UploadHelper.SpecifyAttachmentType(file.Extension); post.Attachments.Add(attachment); } Repository.Thread.AddPost(thread, post); }
public virtual ActionResult ShowThreadDetailsMenu(Thread thread, bool isModerator = false, Post post = null) { if (!IsAuthorExpertOrModerator(thread)) { FormsAuthentication.RedirectToLoginPage(); return null; } var buttons = new List<ThreadDetailsMenuModel.MenuButtons>(); //jeśli user jest pytającym , padła już odpowiedź ale nie została jeszcze zaakceptowana, i jest ekspert przypisany => może akceptować if (thread.Author == AuthenticationHelper.CurrentUser && thread.Posts.FirstOrDefault(p => p.Type == PostType.Answer) != null && thread.State != ThreadState.Closed && thread.State != ThreadState.Accepted && thread.Expert != null) { buttons.Add(ThreadDetailsMenuModel.MenuButtons.Accept); } if (thread.Author == AuthenticationHelper.CurrentUser && !thread.IsPaid) { buttons.Add(ThreadDetailsMenuModel.MenuButtons.Pay); buttons.Add(ThreadDetailsMenuModel.MenuButtons.Delete); } //jeśli user jest pytającym, a wątek został przejęty => może pisać posty if (thread.Author == AuthenticationHelper.CurrentUser && thread.State != ThreadState.Unoccupied && thread.State != ThreadState.Closed) { buttons.Add(ThreadDetailsMenuModel.MenuButtons.Answer); } if(thread.Author == AuthenticationHelper.CurrentUser && thread.State != ThreadState.Closed) { buttons.Add(ThreadDetailsMenuModel.MenuButtons.AttachFile); } if (isModerator) { buttons.Add(ThreadDetailsMenuModel.MenuButtons.ExpertPM); buttons.Add(ThreadDetailsMenuModel.MenuButtons.ModeratorAnswer); buttons.Add(ThreadDetailsMenuModel.MenuButtons.Events); if (thread.State == ThreadState.Occupied) buttons.Add(ThreadDetailsMenuModel.MenuButtons.IncreaseExpertValue); } //jeśli user jest pytającym, a wątek nie został zaakceptowany lub zamknięty //if (thread.Author == AuthenticationHelper.CurrentUser && thread.State != ThreadState.Closed && thread.State != ThreadState.Accepted) //{ //} //jeśli user jest pytającym, a wątek został zarezerwowany if (thread.Author == AuthenticationHelper.CurrentUser && thread.State == ThreadState.Reserved) { if(!thread.Posts.Any(p => p.Author == thread.Expert.User)) buttons.Add(ThreadDetailsMenuModel.MenuButtons.ReleaseReservedQuestion); } if (AuthenticationHelper.IsExpert && AuthenticationHelper.CurrentUser != thread.Author) { var expert = AuthenticationHelper.CurrentUser.Expert; if (thread.State == ThreadState.Accepted && thread.Expert == expert) { buttons.Add(ThreadDetailsMenuModel.MenuButtons.Answer); buttons.Add(ThreadDetailsMenuModel.MenuButtons.AttachFile); } //jeśli user jest ekspertem,ale nie pytającym i jeśli przejął pytanie lub został zapytany bezpośrednio (reserved) if ((thread.State == ThreadState.Occupied || thread.State == ThreadState.Reserved) && thread.Expert == expert) { buttons.Add(ThreadDetailsMenuModel.MenuButtons.Answer); buttons.Add(ThreadDetailsMenuModel.MenuButtons.AttachFile); buttons.Add(ThreadDetailsMenuModel.MenuButtons.DetailsRequest); buttons.Add(ThreadDetailsMenuModel.MenuButtons.GiveUp); buttons.Add(ThreadDetailsMenuModel.MenuButtons.ProposeAdditionalService); } if (thread.State == ThreadState.Unoccupied) { buttons.Add(ThreadDetailsMenuModel.MenuButtons.Occupy); if (!thread.PriceProposals.Any(pp => pp.Expert == expert)) buttons.Add(ThreadDetailsMenuModel.MenuButtons.PriceProposal); } buttons.Add(ThreadDetailsMenuModel.MenuButtons.ReportIssue); } return PartialView(MVC.Thread.Views._ThreadDetailsMenu, new ThreadDetailsMenuModel(thread, buttons, post)); }
public virtual ActionResult ShowPost(Post post, bool isCatalogMode = false, bool isSanitizationMode = false) { if (isSanitizationMode) { return PartialView(MVC.Thread.Views._PostSanitize, post); } if(isCatalogMode) { post.Content = post.GetPublicNameIfNotEmpty(); } return PartialView(post.Type == PostType.Attachment ? MVC.Thread.Views._AttachmentPost : MVC.Thread.Views._Post, new PostViewModel {Post = post, IsCatalogMode = isCatalogMode}); }
public virtual ActionResult ThreadAttachmentUpload(int threadId) { var post = new Post { Attachments = new List<Attachment>() }; var user = AuthenticationHelper.CurrentUser; var thread = Repository.Thread.Get(threadId); if (!IsAuthorExpertOrModerator(thread)) { FormsAuthentication.RedirectToLoginPage(); return null; } for (int fileCount = 0; fileCount < Request.Files.Count; fileCount++) { var file = Request.Files[fileCount]; if (UploadHelper.ValidateUpload(file.ContentLength, file.ContentType, UploadHelper.FileType.PostAttachment)) { var attachmentCount = thread.Posts.Sum(p => p.Attachments.Count()); var attachmentPath = string.Format("\\Attachments\\Thread_{0}\\{1}{2}", thread.Id, attachmentCount, file.FileName); var attachmentsDirPath = HttpContext.Server.MapPath("~/Attachments/"); Directory.SetCurrentDirectory(attachmentsDirPath); Directory.CreateDirectory("Thread_" + thread.Id); var filePath = Path.Combine(HttpContext.Server.MapPath(attachmentPath)); file.SaveAs(filePath); if (fileCount == 0) { post.Author = user; post.Content = Request.Files.Count == 1 ? Resources.Attachments.AttachmentAdded : Resources.Attachments.AttachmentsAdded; post.Type = PostType.Attachment; } if (fileCount == 0 && thread.Posts.Last().Author == user && thread.Posts.Last().Type == PostType.Attachment) { post = thread.Posts.Last(); } var attachment = new Attachment { AttachmentName = file.FileName, AttachmentPath = attachmentPath, Author = user, ContentType = file.ContentType, AttachmentSize = file.ContentLength }; attachment.Type = UploadHelper.SpecifyAttachmentType(file.ContentType); if (fileCount == 0 && (thread.Posts.Last().Type != PostType.Attachment || thread.Posts.Last().Author != AuthenticationHelper.CurrentUser)) { Repository.Thread.AddPost(thread, post); } post.Attachments.Add(attachment); Repository.Thread.Update(thread); Flash.Success(Resources.Attachments.AttachmentAdded + " " + attachment.AttachmentName + " " + UploadHelper.RoundBytes(attachment.AttachmentSize, 2)); return null; } } Flash.Error(Resources.Attachments.AttachmentSizeError); return new HttpStatusCodeResult(400); }
public static void ChangePostToAnswered(Post post, Expert expert) { post.Type = PostType.Answered; post.Content = string.Format(Resources.Thread.AnsweredPostContent, expert.PublicName); }