Пример #1
0
        public IActionResult Edit(int id, TicketFormViewModel viewModel)
        {
            int currnetUserId = _userService.GetByUsername(User.Identity.Name).Id;

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

            var model = new UpdateTicketModel
            {
                Id          = id,
                ProjectName = viewModel.ProjectName,
                Title       = viewModel.TicketTitle,
                Description = viewModel.Description,
                State       = viewModel.TicketState.Replace(" ", ""),
                Type        = viewModel.TicketType.Replace(" ", ""),
            };

            try
            {
                _ticketService.Edit(model);
            }
            catch (Exception e)
            {
                viewModel.ErrorMessage = e.Message;
                viewModel.ProjectName  = _projectService.GetById(_ticketService.GetByTicketId(id).ProjectId).Name;
                return(View(viewModel));
            }

            return(RedirectToAction(nameof(ListTickets)));
        }
Пример #2
0
        private static void ChangeTicketState()
        {
            Console.Write("Enter project name: ");
            string projectName = Console.ReadLine();

            Console.Write("Enter ticket title: ");
            string ticketTitle = Console.ReadLine();

            Project project = _projectService.GetByName(projectName);
            Ticket  ticket  = _ticketService.GetByProjectIdAndTicketTitle(project.Id, ticketTitle);

            Console.WriteLine("Draft");
            Console.WriteLine("New");
            Console.WriteLine("WorkedOn");
            Console.WriteLine("Done");
            Console.Write("Enter state: ");
            string state = Console.ReadLine();

            UpdateTicketModel model = new UpdateTicketModel
            {
                Id    = ticket.Id,
                State = state
            };

            try
            {
                _ticketService.ChangeState(model);
            }
            catch (ServiceException se)
            {
                Console.WriteLine(se.Message);
            }
        }
Пример #3
0
        public async Task <UpdateTicketModel> GetUpdateTicket(int id)
        {
            using (var context = DataContextFactory.CreateReadOnlyContext())
            {
                var projection = await context.SupportTicket
                                 .AsNoTracking()
                                 .Where(t => t.Id == id)
                                 .Select(t => new {
                    Ticket = t,
                    Tags   = t.Tags
                }).FirstOrDefaultNoLockAsync().ConfigureAwait(false);

                var queueDictionary = await context.SupportTicketQueue.ToDictionaryNoLockAsync(x => x.Id, x => x.Name).ConfigureAwait(false);

                var categoryDictionary = Enum.GetValues(typeof(SupportTicketCategory)).Cast <SupportTicketCategory>().ToDictionary(t => t, t => t.ToString());

                var updateModel = new UpdateTicketModel
                {
                    TicketId           = projection.Ticket.Id,
                    Title              = projection.Ticket.Title,
                    Description        = projection.Ticket.Description,
                    QueueId            = projection.Ticket.QueueId,
                    Category           = projection.Ticket.Category,
                    Tags               = String.Join(",", projection.Tags.Select(t => t.Name)),
                    QueueDictionary    = queueDictionary,
                    CategoryDictionary = categoryDictionary
                };

                return(updateModel);
            }
        }
Пример #4
0
        private static void ChangeTicketType()
        {
            Console.Write("Enter project name: ");
            string projectName = Console.ReadLine();

            Console.Write("Enter ticket title: ");
            string ticketTitle = Console.ReadLine();

            Project project = _projectService.GetByName(projectName);
            Ticket  ticket  = _ticketService.GetByProjectIdAndTicketTitle(project.Id, ticketTitle);

            Console.WriteLine("BugReport");
            Console.WriteLine("FeatureRequest");
            Console.WriteLine("AssistanceRequest");
            Console.WriteLine("Other");
            Console.Write("Enter type: ");
            string type = Console.ReadLine();

            UpdateTicketModel model = new UpdateTicketModel
            {
                Id   = ticket.Id,
                Type = type
            };

            try
            {
                _ticketService.ChangeType(model);
            }
            catch (ServiceException se)
            {
                Console.WriteLine(se.Message);
            }
        }
Пример #5
0
        public void Edit(UpdateTicketModel model)
        {
            DATA.TicketType ticketType = (DATA.TicketType)Enum.Parse(typeof(DATA.TicketType), model.Type);
            if (!Enum.IsDefined(typeof(DATA.TicketType), ticketType))
            {
                throw new ServiceException("Invalid Ticket Type.");
            }

            DATA.TicketState ticketState = (DATA.TicketState)Enum.Parse(typeof(DATA.TicketState), model.State);
            if (!Enum.IsDefined(typeof(DATA.TicketState), ticketState))
            {
                throw new ServiceException("Invalid Ticket State.");
            }

            if (string.IsNullOrEmpty(model.Title) || model.Title.Length < 5 || string.IsNullOrWhiteSpace(model.Title))
            {
                throw new ServiceException("The Ticket title should have no less than 5 characters.");
            }

            if (string.IsNullOrEmpty(model.Description) || model.Description.Length < 5)
            {
                throw new ServiceException("The description should have no less than 5 characters.");
            }

            DATA.Ticket ticket = _context.Tickets.First(t => t.Id == model.Id);

            ticket.Description = model.Description;
            ticket.Title       = model.Title;
            ticket.Type        = ticketType;
            ticket.State       = ticketState;

            _context.SaveChanges();
        }
Пример #6
0
        public async Task <ActionResult> UpdateTicket(UpdateTicketModel model)
        {
            var result = await TicketWriter.UpdateTicket(User.Identity.GetUserId(), model);

            await SupportHubContext.Clients.All.TicketUpdated(model.TicketId);

            return(CloseModalSuccess(result.Message));
        }
        public Task <Result <TicketCoreModel> > Edit(UpdateTicketModel model)
        => Result <TicketCoreModel> .TryAsync(async() =>
        {
            var isAdmin = generalDataService.User.Permissions.Any(p => p == (int)PermissionType.Admin);

            var ticket = (await _repository.FirstOrDefaultAsync <Ticket>(i => i.Id == model.Id)).Data;
            if (ticket == null)
            {
                return(Result <TicketCoreModel> .Failed(Error.WithData(1000, new[] { "Ticket Not Found" })));
            }

            ticket.Text             = model.Text;
            ticket.Title            = model.Title;
            ticket.Active           = model.Active;
            ticket.BlobId           = model.BlobId;
            ticket.Priority         = (byte)model.Priority;
            ticket.RepresentativeId = model.RepresentativeId;


            await _repository.CommitAsync();

            var userIds = new List <Guid> {
                ticket.UserId
            };
            if (ticket.RepresentativeId.HasValue)
            {
                userIds.Add(ticket.RepresentativeId.Value);
            }
            userIds.AddRange(ticket.Comment != null
                    ? ticket.Comment.Select(c => c.UserId).ToList()
                    : new List <Guid>());
            var users = (await _membershipServiceApi.SystemUserApiService.ListByIds(userIds)).Data;
            var user  = users.FirstOrDefault(u => u.Id == ticket.UserId);


            return(Result <TicketCoreModel> .Successful(new TicketCoreModel
            {
                Id = ticket.Id,
                BlobId = ticket.BlobId,
                Priority = (TicketPriority)ticket.Priority,
                Active = ticket.Active,
                Text = ticket.Text,
                CreationDate = ticket.CreationDate,
                User = user,
                Representative = ticket.RepresentativeId.HasValue
                        ? users.FirstOrDefault(u => u.Id == ticket.RepresentativeId.Value)
                        : null,
                Title = ticket.Text,
                Comment = ticket.Comment?.Select(c => new CommentCoreModel
                {
                    Id = c.Id,
                    BlobId = c.BlobId,
                    CreationDate = c.CreationDate,
                    Text = c.Text,
                    User = users.FirstOrDefault(u => u.Id == c.UserId)
                }).ToList(),
            }));
        });
Пример #8
0
        public void ChangeState(UpdateTicketModel model)
        {
            DATA.Ticket ticket = _context.Tickets.First(t => t.Id == model.Id);

            if (ticket == null)
            {
                throw new ServiceException("Ticket not found.");
            }

            if (!string.IsNullOrEmpty(model.State))
            {
                DATA.TicketState state = (DATA.TicketState)Enum.Parse(typeof(DATA.TicketState), model.Type);
                ticket.State = state;
            }

            _context.SaveChanges();
        }
Пример #9
0
 public async Task <Result <TicketCoreModel> > Edit(UpdateTicketModel model)
 => await _ticketBiz.Edit(model);
Пример #10
0
        public async Task <IWriterResult> UpdateTicket(string adminUserId, UpdateTicketModel model)
        {
            using (var context = DataContextFactory.CreateContext())
            {
                var ticket = await context.SupportTicket.Include(x => x.Tags).Where(t => t.Id == model.TicketId).FirstNoLockAsync().ConfigureAwait(false);

                var queue = await context.SupportTicketQueue.Where(q => q.Id == model.QueueId).FirstNoLockAsync().ConfigureAwait(false);

                var tagProjections = await context.SupportTag.Select(tag => new {
                    Tag         = tag,
                    TicketCount = tag.Tickets.Count
                }).ToListNoLockAsync().ConfigureAwait(false);

                List <SupportTag> tagToRemoveList;

                if (model.Tags == null)
                {
                    tagToRemoveList = ticket.Tags.ToList();
                }
                else
                {
                    var tagNames = model.Tags.Split(',').ToList();
                    tagToRemoveList = ticket.Tags.Where(t => !tagNames.Contains(t.Name)).ToList();

                    foreach (var tagName in tagNames)
                    {
                        if (ticket.Tags.Any(x => x.Name == tagName))
                        {
                            continue;
                        }

                        var tag = tagProjections.FirstOrDefault(p => p.Tag.Name == tagName)?.Tag;

                        if (tag != null)
                        {
                            ticket.Tags.Add(tag);
                        }
                        else
                        {
                            var newTag = new SupportTag
                            {
                                Name = tagName
                            };

                            ticket.Tags.Add(newTag);
                            context.SupportTag.Add(newTag);
                            context.LogActivity(adminUserId, $"Created new tag: {tagName}");
                        }
                    }
                }

                foreach (var tagToRemove in tagToRemoveList)
                {
                    ticket.Tags.Remove(tagToRemove);
                    var tagProjection = tagProjections.First(p => p.Tag.Id == tagToRemove.Id);
                    if (tagProjection.TicketCount <= 1)
                    {
                        context.SupportTag.Remove(tagToRemove);
                        context.LogActivity(adminUserId, $"Removed tag: {tagToRemove.Name}");
                    }
                }

                ticket.Title       = model.Title;
                ticket.Description = model.Description;
                ticket.Category    = model.Category;
                ticket.Queue       = queue;
                ticket.LastUpdate  = DateTime.UtcNow;

                await context.SaveChangesAsync().ConfigureAwait(false);

                return(new WriterResult(true, $"Ticket - {ticket.Title} updated"));
            }
        }