示例#1
0
        public async Task <ActionResult <bool> > Update([FromBody] VMs.Ticket ticket)
        {
            try
            {
                var ticketData = await context.Tickets
                                 .Where(x => x.RowStatus == Base.enRowStatus.Active && x.Id == ticket.Id)
                                 .FirstOrDefaultAsync();

                if (ticket != null)
                {
                    ticketData.Code          = ticket.Code;
                    ticketData.Description   = ticket.Description;
                    ticketData.OpeningDate   = ticket.OpeningDate;
                    ticketData.ClosingDate   = ticket.ClosingDate;
                    ticketData.TypeInner     = (short)Enum.Parse(typeof(enType), ticket.Type);
                    ticketData.PriorityInner = (short)Enum.Parse(typeof(enPriority), ticket.Priority);
                    ticketData.StatusInner   = (short)Enum.Parse(typeof(enStatus), ticket.Status);

                    await context.SaveChangesAsync();

                    return(OkResponse(true));
                }
                else
                {
                    throw new Exception("Registro não existe!");
                }
            }
            catch (Exception ex) { return(BadRequestResponse(ex)); }
            finally { context.Dispose(); }
        }
示例#2
0
        private async Task <VMs.Ticket> ConvertVMTicket(Data.Ticket ticket)
        {
            VMs.Ticket result = new VMs.Ticket();

            try
            {
                result.Id          = ticket.Id;
                result.Code        = ticket.Code;
                result.Description = ticket.Description;
                result.OpeningDate = ticket.OpeningDate;
                result.ClosingDate = ticket.ClosingDate;
                result.Priority    = ticket.Priority.ToString();
                result.Status      = ticket.Status.ToString();
                result.Type        = ticket.Type.ToString();

                using (var user = new UserController(context))
                {
                    result.Owner = await user.GetUserData(ticket.UserId);
                }

                using (var comment = new CommentController(context))
                {
                    result.Comments = await comment.GetCommentData(ticket.Id);
                }

                return(result);
            }
            catch (Exception ex) { throw ex; }
        }
示例#3
0
        public async Task <VMs.Ticket> ConvertVMTicket(Data.Ticket ticket)
        {
            try
            {
                VMs.User           u;
                List <VMs.Comment> c;
                using (var user = new UserController(context))
                {
                    u = await user.GetUserData(ticket.UserId);
                }
                using (var com = new CommentController(context))
                {
                    c = await com.GetCommentData(ticket.Id);
                }
                VMs.Ticket result = new VMs.Ticket
                {
                    Id          = ticket.Id,
                    ClosingDate = ticket.ClosingDate,
                    Code        = ticket.Code,
                    Description = ticket.Description,
                    OpeningDate = ticket.OpeningDate,
                    Priority    = ticket.Priority.ToString(),
                    Status      = ticket.Status.ToString(),
                    Type        = ticket.Type.ToString(),
                    Owner       = u,
                    Comments    = c
                };

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#4
0
        public async Task <ActionResult <bool> > Save([FromBody] VMs.Ticket ticket)
        {
            try
            {
                //Validation
                if (!context.Tickets
                    .Where(x => x.RowStatus == Data.enRowStatus.Active && x.Code == ticket.Code && x.Description == x.Description)
                    .Any())
                {
                    // TICKETS

                    var ticketId = context.Tickets
                                   .Max(x => x.Id);

                    var dataTicket = new Data.Ticket
                    {
                        Id            = ++ticketId,
                        Code          = ticket.Code,
                        Description   = ticket.Description,
                        UserId        = ticket.Owner.Id,
                        OpeningDate   = ticket.OpeningDate,
                        ClosingDate   = ticket.ClosingDate,
                        TypeInner     = (short)Enum.Parse(typeof(enType), ticket.Type),
                        StatusInner   = (short)Enum.Parse(typeof(enStatus), ticket.Status),
                        PriorityInner = (short)Enum.Parse(typeof(enPriority), ticket.Priority),
                        RowStatus     = enRowStatus.Active,
                        RowDate       = DateTime.Now,
                    };

                    context.Tickets.Add(dataTicket);

                    // TICKET USER

                    var idTicketUser = context.TicketUser
                                       .Max(x => x.Id);

                    var ticketUser = new TicketUser
                    {
                        Id        = ++idTicketUser,
                        UserId    = ticket.Owner.Id,
                        TicketId  = ticketId,
                        RowStatus = enRowStatus.Active,
                        RowDate   = DateTime.Now
                    };

                    context.TicketUser.Add(ticketUser);

                    await context.SaveChangesAsync();

                    return(OkResponse(true));
                }
                else
                {
                    throw new Exception("Ticket já cadastrado!");
                }
            }
            catch (Exception ex) { return(BadRequestResponse(ex)); }
            finally { context.Dispose(); }
        }