예제 #1
0
        public ActionResult Details(int? id, int? commentsPage)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var ticketId = id.GetValueOrDefault();
            var ticket = this.Data.Tickets.GetById(ticketId);

            if (ticket == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.NotFound);
            }

            var ticketViewModel = new TicketDetailsViewModel()
            {
                Id = ticket.Id,
                AuthorName = ticket.Author.UserName,
                CategoryName = ticket.Category.Name,
                CategoryId = ticket.Category.Id,
                Description = ticket.Description,
                Priority = ticket.Priority,
                Status = ticket.Status,
                Title = ticket.Title,
                Attachments = ticket.Attatchments
                                    .Where(a => a.Status == AttachmentStatus.Existing)
                                    .Select(a => new AttachmentViewModel
                                           {
                                               Id = a.Id,
                                               Name = a.Name,
                                               Path = a.Path,
                                               TicketId = ticket.Id
                                           })
            };

            var commentsPageIndex = commentsPage.GetValueOrDefault(1);
            var comments = ticket.Comments
                                 .Select(c => new CommentDetailsViewModel()
                                        {
                                            Id = c.Id,
                                            UserName = c.User.UserName,
                                            Content = c.Content,
                                            PostDate = c.PostDate,
                                            TicketId = c.Ticket.Id,
                                        })
                                 .OrderByDescending(c => c.PostDate)
                                 .Skip((commentsPageIndex - 1) * Properties.Settings.Default.TicketPageCommentsPageSize)
                                 .Take(Properties.Settings.Default.TicketPageCommentsPageSize)
                                 .ToList();

            ticketViewModel.CommentsContainer = new CommentPagebleViewModel
            {
                Comments = comments,
                CurrentPage = commentsPageIndex,
                TotalRecordsCount = comments.Count(),
                PagesCount = (int)Math.Ceiling((double)ticket.Comments.Count / Properties.Settings.Default.TicketPageCommentsPageSize)
            };

            return this.View(ticketViewModel);
        }
예제 #2
0
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var ticketId = id.GetValueOrDefault();
            var ticket = this.Data.Tickets.GetById(ticketId);

            if (ticket == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.NotFound);
            }

            var ticketViewModel = new TicketDetailsViewModel()
            {
                AuthorName = ticket.Author.UserName,
                CategoryName = ticket.Category.Name,
                CategoryId = ticket.Category.Id,
                Description = ticket.Description,
                Priority = ticket.Priority,
                Status = ticket.Status,
                Title = ticket.Title,
                Id = ticket.Id
            };

            return this.View(ticketViewModel);
        }
예제 #3
0
        public ActionResult Delete(int? id, TicketDetailsViewModel ticketViewModel)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var ticketId = id.GetValueOrDefault();
            var ticket = this.Data.Tickets.GetById(ticketId);

            if (ticket == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.NotFound);
            }

            this.Data.Tickets.Delete(ticket);
            this.Data.SaveChanges();

            return this.RedirectToAction("Index", "Home");
        }