Exemplo n.º 1
0
        public async Task <Comment> Add(User user, Ticket baseTicket, string text)
        {
            if (user != null && baseTicket != null && text != null && text != "")
            {
                Comment newComment = new Comment(text, user, DateTime.Now, baseTicket.TeamId, baseTicket.Id);
                baseTicket.Comments.Add(newComment);
                ticketLogger.WriteTicketLog(user, TicketAction.CreateComment, baseTicket);
                await db.SaveChangesAsync();

                return(newComment);
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
        public async Task <Ticket> Add(TicketBase newTicket, User user)
        {
            Ticket baseTicket = null;

            if (newTicket.BaseTicketId != null && newTicket.Description != null && newTicket.BaseTicketId > 0 && newTicket.BaseTeamId > 0)
            {
                baseTicket = await db.Tickets.SingleOrDefaultAsync(x => x.Id == newTicket.BaseTicketId);
            }
            if (newTicket.Description != null && newTicket.BaseTeamId > 0 && user != null && newTicket.TypeId > 0)
            {
                TicketType ticketType = await db.TicketTypes.SingleOrDefaultAsync(x => x.Id == newTicket.TypeId);

                if (ticketType != null)
                {
                    Ticket ticket       = new Ticket(newTicket.BaseTeamId, user, newTicket.Description, ticketType, DateTime.Now, TicketState.New, baseTicket);
                    Ticket ticketFromDb = db.Tickets.Add(ticket);
                    ticketLogger.WriteTicketLog(user, TicketAction.CreateTicket, baseTicket);
                    await db.SaveChangesAsync();

                    return(ticketFromDb);
                }
            }
            throw new ArgumentNullException();
        }