Ejemplo n.º 1
0
        public async Task <ActionResult <TicketLine> > PostTicketLine(TicketLine ticketLine)
        {
            _context.TicketLines.Add(ticketLine);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTicketLine", new { id = ticketLine.TicketLineId }, ticketLine));
        }
Ejemplo n.º 2
0
        private void ProductClickedCommandExec(object clickedProduct)
        {
            Product    product     = (Product)clickedProduct;
            TicketLine ticketLine1 = this.CurrentTicket.Ticket.TicketLines.FirstOrDefault <TicketLine>((Func <TicketLine, bool>)(tl => tl.Product == product));

            if (ticketLine1 != null)
            {
                ++ticketLine1.Amount;
                TicketLine ticketLine2 = ticketLine1;
                ticketLine2.LinePriceExcl = (double)ticketLine2.Amount * ticketLine1.UnitPrice;
            }
            else
            {
                TicketLine ticketLine2 = new TicketLine()
                {
                    Product        = product,
                    Amount         = 1,
                    UnitPrice      = product.Price,
                    UnitPriceCoins = product.PriceCoin
                };
                TicketLine ticketLine3 = ticketLine2;
                ticketLine3.LinePriceExcl = (double)ticketLine3.Amount * ticketLine2.UnitPrice;
                this.CurrentTicket.Ticket.TicketLines.Add(ticketLine2);
            }
            this.CurrentTicket.Ticket.RecalculatePrice();
            this.CurrentTicket.Ticket.TotalRemaining = this.CurrentTicket.Ticket.TotalPrice;
            this.CurrentTicket.Ticket.CreationTime   = DateTime.Now;
            if (this.CurrentTicket.Ticket.CreatedBy == null && AuthenticationService.Instance.AuthenticatedMember != null)
            {
                this.CurrentTicket.Ticket.CreatedBy = this.UnitOfWork.MemberRepository.GetById(AuthenticationService.Instance.AuthenticatedMember.Id);
            }
            this.CurrentTicket.Visibility = Visibility.Visible;
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PutTicketLine(int id, TicketLine ticketLine)
        {
            if (id != ticketLine.TicketLineId)
            {
                return(BadRequest());
            }

            _context.Entry(ticketLine).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TicketLineExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public IIndexResponse Index(TicketLine data, bool overrides = false)
 {
     Refresh();
     if (overrides)
     {
         DeleteIfExists(data.IndexKey);
     }
     return(Client.Index(data, cl => cl.Index(IndexName)));
 }
Ejemplo n.º 5
0
        public static Permission ToPermission(this TicketLine ticketLine, TimeSpan rptLifetime = default)
        {
            var iat = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

            return(new Permission
            {
                Scopes = ticketLine.Scopes,
                ResourceSetId = ticketLine.ResourceSetId,
                Expiry = DateTimeOffset.UtcNow.Add(rptLifetime).ToUnixTimeSeconds(),
                IssuedAt = iat,
                NotBefore = iat
            });
        }
Ejemplo n.º 6
0
        private void AddProduct(Product product, double quantity)
        {
            var ticketline = new TicketLine();

            //--populate ticketline with product
            ticketline.ProductId   = product.Id;
            ticketline.ItemName    = product.Name;
            ticketline.ItemPrice   = product.UnitPrice;
            ticketline.Quantity    = quantity;
            ticketline.TotalAmount = product.UnitPrice * quantity;
            ticketlineBindingSource.Add(ticketline);
            ItemTenderGrid.DataSource = ticketlineBindingSource;
            ticketlineBindingSource.MoveLast();
        }
Ejemplo n.º 7
0
        private void PlusCommandExec()
        {
            if (this.SelectedTicketLine == null || this.Ticket == null || this.Ticket.TicketLines == null)
            {
                return;
            }
            TicketLine ticketLine = this.Ticket.TicketLines.FirstOrDefault <TicketLine>((Func <TicketLine, bool>)(t => t.Product == this.selectedTicketLine.Product));

            if (ticketLine != null)
            {
                ++ticketLine.Amount;
            }
            this.Ticket.RecalculatePrice();
            this.Ticket.TotalRemaining = this.Ticket.TotalPrice;
            this.OnPropertyChanged <Ticket>((System.Linq.Expressions.Expression <Func <Ticket> >)(() => this.Ticket));
        }
Ejemplo n.º 8
0
            public async Task <int> Handle(ReplyTicketCommand request, CancellationToken cancellationToken)
            {
                bool         isMemberOrAdmin = false;
                TicketHeader ticket          = null;
                TicketLine   ticketLine      = null;
                AppUser      user            = null;
                string       sendToemail     = "";
                int          result          = 0;
                string       messageMail     = "Your ticket is now closed.<br>You can reply to this ticket to reopen it.";

                user = await _context.User.FirstOrDefaultAsync(x => x.Id == _currentUserService.UserId);

                if (await _userManager.IsInRoleAsync(_currentUserService.UserId, "Admin") || await _userManager.IsInRoleAsync(_currentUserService.UserId, "Member"))
                {
                    isMemberOrAdmin = true;
                }

                ticket = await _context.TickerHeader.Include(x => x.Requester).FirstOrDefaultAsync(x => x.Id == request.TicketHeaderId);

                ticketLine = new TicketLine();

                if (ticket == null || (ticket.Requester == null && !isMemberOrAdmin) || (!isMemberOrAdmin && !ticket.Requester.Equals(user)))
                {
                    throw new NotFoundException(nameof(TicketHeader), request.TicketHeaderId);
                }

                if (ticket.Requester == null)
                {
                    sendToemail = ticket.Email;
                }
                else
                {
                    sendToemail = ticket.Requester.Email;
                }

                if (!request.AskForClose)
                {
                    if (isMemberOrAdmin)
                    {
                        ticket.Status = _context.Status.FirstOrDefault(x => x.Name == "Waiting on customer");
                        ticket.Readed = TicketHeader.ReadedByMemberOrAdmin;
                    }
                    else
                    {
                        ticket.Status = _context.Status.FirstOrDefault(x => x.Name == "Open");
                        ticket.Readed = TicketHeader.ReadedByCustomer;
                    }
                    ticketLine.Content    = request.Response;
                    ticketLine.ResponseBy = user;
                    ticketLine.Email      = user.Email;

                    ticket.TicketLine.Add(ticketLine);
                }
                else
                {
                    ticket.ClosedDate = DateTime.Now;
                    ticket.Status     = _context.Status.FirstOrDefault(x => x.Name == "Closed");
                    if (isMemberOrAdmin)
                    {
                        _email.SendEmail(sendToemail, ticket.InternTitle, messageMail);
                    }
                }

                result = await _context.SaveChangesAsync(cancellationToken);

                if (result > 0)
                {
                    _email.SendEmail(sendToemail, ticket.InternTitle, "A new response is available on your ticket, click " +
                                     "<a href ='" + GlobalVar.FEUrl + "Ticket/" + ticket.Id + "' >here.</a>" +
                                     "to see.");
                }

                return(result);
            }
Ejemplo n.º 9
0
            public async Task <int> Handle(CreateReplyTicketByMailCommand request, CancellationToken cancellationToken)
            {
                try
                {
                    List <Email>  lt              = _email.ReadInbox() as List <Email>;
                    string        senderEmail     = "";
                    bool          createTicket    = true;
                    string        internRef       = "";
                    int           ticketId        = 0;
                    int           index           = -1;
                    string        subject         = "";
                    bool          isMemberOrAdmin = false;
                    List <byte[]> attachementList;
                    TicketLine    ticketLine;
                    TicketHeader  ticket;
                    AppUser       user;
                    int           result = 0;


                    foreach (var t in lt)
                    {
                        user = _context.User.FirstOrDefault(x => x.Email.ToUpper() == t.from.ToUpper());
                        if (user == null)
                        {
                            senderEmail = t.from;
                        }
                        else
                        {
                            if (await _userManager.IsInRoleAsync(user.Id, "Member"))
                            {
                                isMemberOrAdmin = true;
                            }
                            else if (await _userManager.IsInRoleAsync(user.Id, "Admin"))
                            {
                                isMemberOrAdmin = true;
                            }
                        }
                        if (t.Subject.Length > 0)
                        {
                            subject = Regex.Replace(t.Subject, @"\s+", "");
                            index   = subject.IndexOf("-#");
                            if (index > -1)
                            {
                                internRef = subject.Substring(index + 2);
                                Int32.TryParse(internRef, out ticketId);
                                ticket = _context.TickerHeader.FirstOrDefault(x => x.Id == ticketId);
                                if (ticket != null)
                                {
                                    if (user == null && ticket.Email.ToUpper() == senderEmail.ToUpper())
                                    {
                                        ticket.Status = _context.Status.FirstOrDefault(x => x.Name == "Open");
                                        ticketLine    = new TicketLine
                                        {
                                            AskForClose = false,
                                            Content     = t.Body,
                                            Email       = senderEmail,
                                        };
                                    }
                                    else if ((user != null && ticket.Email.ToUpper() == user.Email.ToUpper()) || isMemberOrAdmin)
                                    {
                                        if (isMemberOrAdmin)
                                        {
                                            ticket.Status = _context.Status.FirstOrDefault(x => x.Name == "Waiting on customer");
                                            ticket.Readed = TicketHeader.ReadedByMemberOrAdmin;
                                        }
                                        else
                                        {
                                            ticket.Status = _context.Status.FirstOrDefault(x => x.Name == "Open");
                                            ticket.Readed = TicketHeader.ReadedByCustomer;
                                        }

                                        ticketLine = new TicketLine
                                        {
                                            AskForClose = false,
                                            Content     = t.Body,
                                            ResponseBy  = user,
                                        };
                                    }
                                    else
                                    {
                                        throw new NotFoundException(nameof(TicketHeader), ticket.Id);
                                    }

                                    foreach (var str in _cloudinary.UploadToCloudinary(t.attachement.ToList()))
                                    {
                                        ticketLine.Content += str;
                                    }
                                    ticket.TicketLine.Add(ticketLine);
                                    result += await _context.SaveChangesAsync(cancellationToken);
                                }
                                else
                                {
                                    throw new NotFoundException(nameof(TicketHeader), ticketId);
                                }
                            }
                            else
                            {
                                //We need to create the ticket
                                ticket = new TicketHeader
                                {
                                    Title       = t.Subject,
                                    Description = t.Body,
                                    Priority    = _context.Priority.FirstOrDefault(x => x.Name == "Unknow"),
                                    Project     = _context.Project.FirstOrDefault(x => x.Name == "Unknow"),
                                    Type        = _context.Type.FirstOrDefault(x => x.Name == "Unknow"),
                                    AssignTO    = null,
                                    ClosedDate  = null,
                                    Requester   = user,
                                    Status      = _context.Status.FirstOrDefault(x => x.Name == "Open"),
                                    CreatedBy   = user?.Id,
                                    Email       = user?.Email,
                                    Readed      = TicketHeader.ReadedByCustomer
                                };
                                if (user == null)
                                {
                                    ticket.Email = senderEmail;
                                }
                                foreach (var str in _cloudinary.UploadToCloudinary(t.attachement.ToList()))
                                {
                                    ticket.Description += str;
                                }

                                _context.TickerHeader.Add(ticket);
                                await _context.SaveChangesAsync(cancellationToken);

                                ticket.InternTitle = ticket.Title + " - #" + ticket.Id;

                                result += await _context.SaveChangesAsync(cancellationToken);

                                if (result > 0 && !isMemberOrAdmin)
                                {
                                    if (user != null)
                                    {
                                        senderEmail = user.Email;
                                    }

                                    _email.SendEmail(senderEmail, ticket.InternTitle, "Your ticket is successfully created. <br>" +
                                                     "We will reply soon as possible.<br>" +
                                                     "<hr>Ticket content :<br>" + ticket.Description);
                                }
                            }
                        }

                        else
                        {
                            throw new ApplicationException();
                        }
                    }

                    return(result);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
 public void Add(TicketLine ticketLine)
 {
     ticketLines.Add(ticketLine);
     OnPropertyChanged("TicketLines");
 }