Esempio n. 1
0
        public ActionResult Detail(int?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction(nameof(TicketsController.Tickets)));
            }

            var ticket = DbContext.TicketsDatabase.Where(p => p.Project.Archive == false).FirstOrDefault(p => p.Id == id);

            if (ticket == null)
            {
                return(RedirectToAction(nameof(TicketsController.Tickets)));
            }

            var model = new ViewTicketViewModel()
            {
                Title         = ticket.Title,
                Description   = ticket.Description,
                Id            = ticket.Id,
                TicketHistory = ticket.TicketHistory,
                Comments      = ticket.Comments,
                Attachments   = ticket.Attachments.ToList(),
                CreatedBy     = DbContext.Users.FirstOrDefault(p => p.Id == ticket.CreatedById),
                Project       = ticket.Project.ProjectName,
                AssignedTo    = DbContext.Users.FirstOrDefault(p => p.Id == ticket.AssignedToId),
                Type          = DbContext.TicketsTypeDatabase.First(p => p.Id == ticket.TicketTypeId).Name,
                Status        = DbContext.TicketsStatusDatabase.First(p => p.Id == ticket.TicketStatusId).Name,
                Priority      = DbContext.TicketsPriorityDatabase.First(p => p.Id == ticket.TicketPriorityId).Name,
                DateCreated   = ticket.DateCreated,
                DateUpdated   = ticket.DateUpdated,
            };

            return(View(model));
        }
Esempio n. 2
0
        public ActionResult EditComments(int id, ViewTicketViewModel model)
        {
            var comment = DbContext.Comments.FirstOrDefault(
                p => p.Id == id);

            comment.CommentBody = model.CommentBody;

            DbContext.SaveChanges();

            return(RedirectToAction("Details", new { id = comment.TicketId }));
        }
Esempio n. 3
0
        public ActionResult Details(int?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction(nameof(TicketController.Index)));
            }


            var ticket = DbContext.Tickets.FirstOrDefault(p =>
                                                          p.Id == id.Value && p.Project.Archive == false);

            if (ticket == null)
            {
                return(RedirectToAction(nameof(TicketController.Index)));
            }

            var model = new ViewTicketViewModel();

            model.Title              = ticket.Title;
            model.Description        = ticket.Description;
            model.DateUpdated        = ticket.DateUpdated;
            model.Id                 = ticket.Id;
            model.DateCreated        = ticket.DateCreated;
            model.TicketPriorityName = ticket.TicketPriority.Name;
            model.TicketStatusName   = ticket.TicketStatus.Name;
            model.TicketTypeName     = ticket.TicketType.Name;
            model.Attachments        = DbContext.Attachments.Where(p => p.TicketId == ticket.Id).Select(p => new AttachmentTicketViewModel()
            {
                FileUrl = p.FileUrl,
                Id      = p.Id,
                Created = p.User.UserName
            }).ToList();
            model.Comments = DbContext.Comments.Where(p => p.TicketId == ticket.Id).Select(p => new CommentTicketViewModel()
            {
                CommentBody = p.CommentBody,
                DateCreated = p.DateCreated,
                Created     = p.Created.UserName,
                Id          = p.Id,
            }).ToList();

            model.Histories = DbContext.Histories.Where(p => p.TicketId == ticket.Id).Select(p => new ViewHistoryViewModel()
            {
                Changed  = p.Changed,
                Property = p.Property,
                OldValue = p.OldValue,
                NewValue = p.NewValue,
                By       = p.User.DisplayName
            }).ToList();


            return(View(model));
        }
Esempio n. 4
0
        public ActionResult DeleteComments(int?id, ViewTicketViewModel model)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction(nameof(TicketController.Details)));
            }

            var comment = DbContext.Comments.FirstOrDefault(p => p.Id == id.Value);

            if (comment != null)
            {
                DbContext.Comments.Remove(comment);
                DbContext.SaveChanges();
            }

            return(RedirectToAction("Details", new { id = comment.TicketId }));
        }
Esempio n. 5
0
        public ActionResult Details(int?id, ViewTicketViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            Attachments attachment;

            attachment = new Attachments();

            attachment.TicketId = model.Id;

            if (model.Media != null)
            {
                if (!Directory.Exists(Constants.MappedUploadFolder))
                {
                    Directory.CreateDirectory(Constants.MappedUploadFolder);
                }

                var fileName         = model.Media.FileName;
                var fullPathWithName = Constants.MappedUploadFolder + fileName;

                model.Media.SaveAs(fullPathWithName);

                attachment.FileUrl = Constants.UploadFolder + fileName;
                attachment.User    = DbContext.Users.FirstOrDefault(p => p.UserName == User.Identity.Name);
            }

            DbContext.Attachments.Add(attachment);
            DbContext.SaveChanges();

            var ticket = DbContext.Tickets.FirstOrDefault(p => p.Id == attachment.TicketId && p.Project.Archive == false);

            if (ticket.AssignedTo != null)
            {
                EmailNotification.SendNotification(ticket.AssignedTo.Email, "Attachment was added", "Notification");
            }

            foreach (var user in ticket.UserNotifications)
            {
                EmailNotification.SendNotification(user.Email, $"Attachment was changed", "Notification");
            }

            return(RedirectToAction(nameof(TicketController.Details)));
        }
Esempio n. 6
0
        public ActionResult SaveComment(int?id, ViewTicketViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Details", new { id = model.Id }));
            }

            Comments comment;

            if (!id.HasValue)
            {
                comment = new Comments();
                DbContext.Comments.Add(comment);
            }
            else
            {
                comment = DbContext.Comments.FirstOrDefault(p => p.Id == id);

                if (comment == null)
                {
                    return(RedirectToAction(nameof(TicketController.Details)));
                }
            }

            comment.CommentBody = model.CommentBody;
            comment.TicketId    = model.Id;
            comment.DateCreated = DateTime.Now;
            comment.Created     = DbContext.Users.FirstOrDefault(p => p.UserName == User.Identity.Name);

            DbContext.SaveChanges();

            var ticket = DbContext.Tickets.FirstOrDefault(p => p.Id == comment.TicketId && p.Project.Archive == false);

            if (ticket.AssignedTo != null)
            {
                EmailNotification.SendNotification(ticket.AssignedTo.Email, "Comment was created", "Notification");
            }

            foreach (var user in ticket.UserNotifications)
            {
                EmailNotification.SendNotification(user.Email, "Comment was created", "Notification");
            }

            return(RedirectToAction("Details", new { id = comment.TicketId }));
        }
Esempio n. 7
0
        public ActionResult EditComments(int?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction(nameof(TicketController.Details)));
            }

            var comment = DbContext.Comments.FirstOrDefault(
                p => p.Id == id);

            if (comment == null)
            {
                return(RedirectToAction(nameof(TicketController.Details)));
            }

            var model = new ViewTicketViewModel();

            model.CommentBody = comment.CommentBody;
            model.Id          = comment.Id;
            return(View(model));
        }
        public IActionResult Create(int id, string state, ViewTicketViewModel viewModel)
        {
            Ticket ticket = _ticketService.GetByTicketId(id);

            int currnetUserId = _userService.GetByUsername(User.Identity.Name).Id;

            if (User.IsInRole("Client") && currnetUserId != ticket.SubmitterId)
            {
                return(NotFound());
            }

            var model = new CreateMessageModel
            {
                TicketId       = id,
                UserId         = currnetUserId,
                PublishingDate = DateTime.UtcNow,
                Content        = viewModel.MessageContent,
                State          = state
            };

            _messageService.Create(model);

            return(RedirectToAction($"{nameof(TicketController.View)}", "Ticket", new { id }));
        }
        public IActionResult View(int id)
        {
            Ticket ticket = _ticketService.GetByTicketId(id);

            int currnetUserId = _userService.GetByUsername(User.Identity.Name).Id;

            if (User.IsInRole("Client") && currnetUserId != ticket.SubmitterId)
            {
                return(NotFound());
            }

            var model = new ViewTicketViewModel();

            try
            {
                var messages = new List <Message>();

                messages.AddRange(_messageService.Get(id));

                var viewMessages = new List <MessageViewModel>();

                foreach (var message in messages)
                {
                    var viewModel = new MessageViewModel
                    {
                        Id             = message.Id,
                        Content        = message.Content,
                        PublishingDate = message.PublishingDate,
                        State          = message.State,
                        UserId         = message.UserId,
                        Username       = message.Username
                    };

                    viewMessages.Add(viewModel);
                }

                model = new ViewTicketViewModel
                {
                    TicketId    = id,
                    TicketTitle = ticket.Title,
                    Description = ticket.Description,
                    FileName    = ticket.FileName,
                    ProjectName = _projectService.GetById(ticket.ProjectId).Name,
                    SubmitterId = ticket.SubmitterId,
                    TicketState = ticket.State,
                    TicketType  = ticket.Type,
                    Messages    = viewMessages
                };

                return(View(model));
            }
            catch
            {
                model = new ViewTicketViewModel
                {
                    TicketId    = id,
                    TicketTitle = ticket.Title,
                    Description = ticket.Description,
                    FileName    = ticket.FileName,
                    ProjectName = _projectService.GetById(ticket.ProjectId).Name,
                    SubmitterId = ticket.SubmitterId,
                    TicketState = ticket.State,
                    TicketType  = ticket.Type
                };
                return(View(model));
            }
        }
Esempio n. 10
0
 public ActionResult Comment(int?id, ViewTicketViewModel model)
 {
     return(SaveComment(null, model));
 }