Exemple #1
0
        public async Task <ActionResult <bool> > Save([FromBody] VMs.Comment comment)
        {
            try
            {
                var ticketUserID = -1;

                var tickerUser = await context.TicketUser
                                 .Where(x => x.RowStatus == enRowStatus.Active && x.TicketId == comment.TicketId && x.UserId == comment.User.Id)
                                 .FirstOrDefaultAsync();

                if (tickerUser != null)
                {
                    ticketUserID = tickerUser.Id;
                }
                else
                {
                    // TICKET USER
                    ticketUserID = context.TicketUser
                                   .Max(x => x.Id);

                    var ticketUser = new TicketUser
                    {
                        Id        = ++ticketUserID,
                        UserId    = comment.User.Id,
                        TicketId  = comment.TicketId,
                        RowStatus = enRowStatus.Active,
                        RowDate   = DateTime.Now
                    };

                    context.TicketUser.Add(ticketUser);
                    await context.SaveChangesAsync();
                }

                // COMMENT
                var commentId = context.Comments
                                .Max(x => x.Id);

                var dataComment = new Data.Comments
                {
                    Id           = ++commentId,
                    Comment      = comment.Description,
                    TicketUserId = ticketUserID,
                    RowStatus    = enRowStatus.Active,
                    RowDate      = DateTime.Now,
                };

                context.Comments.Add(dataComment);

                await context.SaveChangesAsync();

                return(OkResponse(true));
            }
            catch (Exception ex) { return(BadRequestResponse(ex)); }
            finally { context.Dispose(); }
        }
Exemple #2
0
        private async Task <VMs.Comment> ConvertVMComment(Data.Comments comment)
        {
            VMs.Comment result = new VMs.Comment();

            try
            {
                result.Id          = comment.Id;
                result.Description = comment.Comment;

                using (var user = new UserController(context))
                {
                    TicketUser ticketUserId = await context.TicketUser
                                              .Where(x => x.RowStatus == Data.enRowStatus.Active && x.Id == comment.TicketUserId)
                                              .FirstOrDefaultAsync();

                    result.TicketId = ticketUserId.TicketId;
                    result.User     = await user.GetUserData(ticketUserId.UserId);
                }

                return(result);
            }
            catch (Exception ex) { throw ex; }
            finally { context.Dispose(); }
        }