Пример #1
0
        public ActionResult <Ticket> CreateTicket(Ticket model)
        {
            if (model.Id > 0)
            {
                return(BadRequest(
                           new ProblemDetails {
                    Detail = "This method can't be used to update tickets."
                }));
            }
            var evt = _context.Events.Find(model.EventId);

            if (evt == null)
            {
                return(BadRequest(
                           new ProblemDetails {
                    Detail = $"There's no event with id {model.EventId}."
                }));
            }
            var entity = new DataAccess.Models.Ticket();

            _mapper.Map(model, entity);
            entity.TicketGuid   = Guid.NewGuid();
            entity.TicketNumber = entity.TicketNumber
                                  ?? TicketNumberHelper.GenerateTicketNumber(evt);
            SetAuthorInfo(entity);
            _context.Add(entity);
            _context.SaveChanges();
            model = _mapper.Map <Ticket>(entity);
            return(CreatedAtAction(nameof(GetById), new { id = model.Id }, model));
        }
Пример #2
0
        public void GenerateTicketNumber()
        {
            var evt = new Event {
                Id = 1
            };
            string ticketNr = TicketNumberHelper.GenerateTicketNumber(evt);

            ticketNr.Should().NotBeNull();
            ticketNr.Should().HaveLength(10);
            // should begin with event id padded right with zeros.
            ticketNr.Should().StartWith("100");
        }