예제 #1
0
        public async Task <ActionResult> DeleteTicketAsync(TicketVm ticketVm)
        {
            await _ticketService.DeleteTicketAsync(ticketVm);

            Log.Information("Ticket {@ticketVm} deleted", ticketVm);
            return(Ok(ticketVm));
        }
예제 #2
0
        public async Task ShouldDeleteTicket()
        {
            List <TicketsToBuyVm> tickets = new List <TicketsToBuyVm>();

            tickets.Add(new TicketsToBuyVm {
                Id = 1
            });
            await CreateTickets(tickets);

            TicketService    ticketService    = new TicketService(_dbContext, _mainEventProvider);
            TicketController ticketController = new TicketController(ticketService);

            SetUser(ticketController, _createdUser1.Entity.Id);

            TicketVm ticketVm = new TicketVm {
                Id = 1
            };

            ActionResult <TicketVm> result = await ticketController.DeleteTicketAsync(ticketVm);

            TicketVm deletedTicket = (TicketVm)((OkObjectResult)result.Result).Value;

            Assert.AreEqual(1, deletedTicket.Id);

            // Check that we have deleted only the first, but not the other
            Ticket ticket1 = _dbContext.Tickets.Find(1);

            Assert.IsNull(ticket1);
            Ticket ticket2 = _dbContext.Tickets.Find(2);

            Assert.IsNotNull(ticket2);
        }
예제 #3
0
        public static TicketVm CrearVm(Ticket ticket)
        {
            var obj = new TicketVm
            {
                TicketId       = ticket.TicketId,
                Numero         = ticket.Numero,
                Tema           = ticket.Tema,
                Descripcion    = ticket.Descripcion,
                TicketEstadoId = ticket.TicketEstadoId,

                ListaEmpleado = ticket.ListaEmpleado.Select(o => new TicketEmpleadoVm
                {
                    TicketEmpleadoId = o.TicketEmpleadoId,
                    TicketId         = o.TicketId,
                    EmpleadoId       = o.EmpleadoId,
                    EmpleadoNombre   = String.Format("{0} {1}", o.Empleado?.Nombre, o.Empleado?.Apellido)
                }).OrderBy(o => o.TicketEmpleadoId),

                ListaEntrada = ticket.ListaEntrada.Select(o => new TicketEntradaVm
                {
                    TicketEntradaId = o.TicketEntradaId,
                    TicketId        = o.TicketId,
                    EmpleadoId      = o.EmpleadoId,
                    FechaInicio     = o.FechaInicio,
                    FechaFinal      = o.FechaFinal,
                    Nota            = o.Nota,
                    EmpleadoNombre  = String.Format("{0} {1}", o.Empleado?.Nombre, o.Empleado?.Apellido)
                }).OrderBy(o => o.FechaInicio)
            };

            return(obj);
        }
예제 #4
0
        public ActionResult DepartureTimes(TicketVm ticket)
        {
            var ticketService = new TicketService();
            var ticketId      = ticketService.AddTicket(ticket);

            return(RedirectToAction("TicketOrder", new { id = ticketId }));
        }
예제 #5
0
        public async Task ShouldGetTicketById()
        {
            List <TicketsToBuyVm> tickets = new List <TicketsToBuyVm>();

            tickets.Add(new TicketsToBuyVm {
                Id = 1
            });
            await CreateTickets(tickets);

            TicketService    ticketService    = new TicketService(_dbContext, _mainEventProvider);
            TicketController ticketController = new TicketController(ticketService);

            ActionResult <TicketVm> result1 = await ticketController.GetTicketAsync(1);

            TicketVm returnedTicket1 = result1.Value;

            Assert.AreEqual(1, returnedTicket1.Id);
            Assert.AreEqual(15, returnedTicket1.Price);


            ActionResult <TicketVm> result2 = await ticketController.GetTicketAsync(2);

            TicketVm returnedTicket2 = result2.Value;

            Assert.AreEqual(2, returnedTicket2.Id);
            Assert.AreEqual(10, returnedTicket2.Price);
        }
예제 #6
0
        private OperationResult ValidarModelo(TicketVm obj)
        {
            var resultado = new OperationResult();

            if (String.IsNullOrWhiteSpace(obj.Tema))
            {
                resultado.Agregar("You must specify the ticket's subject");
            }

            if (String.IsNullOrWhiteSpace(obj.Descripcion))
            {
                resultado.Agregar("You must specify the ticket's Description");
            }

            if (obj.ListaEmpleado == null || obj.ListaEmpleado.Count() <= 0)
            {
                resultado.Agregar("You must specify at least one employee for the ticket");
            }

            foreach (var item in obj.ListaEntrada)
            {
                if (item.Nota == "")
                {
                    resultado.Agregar("You must specify the nota for the entry ");
                }

                if (item.EmpleadoId <= 0)
                {
                    resultado.Agregar("You must specify the employee for the entry " + item.Nota);
                }
            }

            return(resultado);
        }
예제 #7
0
        public async Task ShouldUpdateTicket()
        {
            List <TicketsToBuyVm> tickets = new List <TicketsToBuyVm>();

            tickets.Add(new TicketsToBuyVm {
                Id = 1
            });
            await CreateTickets(tickets);

            int newPrice = 50;

            TicketService    ticketService    = new TicketService(_dbContext, _mainEventProvider);
            TicketController ticketController = new TicketController(ticketService);

            SetUser(ticketController, _createdUser1.Entity.Id);

            TicketVm ticketVm = new TicketVm {
                Id = 1, Price = newPrice
            };

            await ticketController.UpdateTicketAsync(ticketVm);

            // Check that only one has been changed
            Ticket ticket1 = _dbContext.Tickets.Find(1);

            Assert.AreEqual(newPrice, ticket1.Price);

            Ticket ticket2 = _dbContext.Tickets.Find(2);

            Assert.AreEqual(10, ticket2.Price);
        }
예제 #8
0
        public static void MapearAEntity(Ticket obj, TicketVm ticket)
        {
            obj.Tema           = ticket.Tema;
            obj.Descripcion    = ticket.Descripcion;
            obj.TicketEstadoId = ticket.TicketEstadoId;

            MapTicketEmpleado(ticket, obj);
            MapTicketEntrada(ticket, obj);
        }
예제 #9
0
        public int AddTicket(TicketVm ticket)
        {
            var basePrice        = _tripRepository.GetPrice(ticket.TripId);
            var getNumberOfStops = _tripRepository.GetNumberOfStops(ticket.TripId, ticket.DepartureStationId, ticket.ArrivalStationId);
            var price            = TripService.CalculatePrice(basePrice.BasePrice, basePrice.StopsPrice, getNumberOfStops);

            ticket.Price = price;

            return(_ticketRepository.AddTicket(ticket));
        }
예제 #10
0
 public static Ticket CrearEntity(TicketVm ticket)
 {
     return(new Ticket()
     {
         Tema = ticket.Tema,
         Descripcion = ticket.Descripcion,
         TicketEstadoId = (byte)TicketEstadoEnum.Pending,
         ListaEmpleado = new List <TicketEmpleado>(),
         ListaEntrada = new List <TicketEntrada>()
     });
 }
예제 #11
0
        private void Agregar(TicketVm ticketVm)
        {
            var obj = TicketFactory.CrearEntity(ticketVm);

            obj.Numero        = ObtenerProximoIdentificador();
            obj.FechaCreacion = DateTime.Now;
            TicketFactory.MapTicketEmpleado(ticketVm, obj);
            TicketFactory.MapTicketEntrada(ticketVm, obj);

            _repository.Agregar(obj);
        }
예제 #12
0
        public static void MapTicketEntrada(TicketVm origen, Ticket destino)
        {
            if (destino.ListaEntrada == null)
            {
                destino.ListaEntrada = new List <TicketEntrada>();
            }

            int cantidad = destino.ListaEntrada.Count();

            for (int i = 0; i < cantidad; i++)
            {
                var item = destino.ListaEntrada[i];

                var itemVm = origen
                             .ListaEntrada?
                             .FirstOrDefault(o => o.TicketEntradaId == item.TicketEntradaId);

                if (itemVm == null)
                {
                    // ELIMINAR
                    destino.ListaEntrada.Remove(item);
                    i--; cantidad--;
                }
                else
                {
                    // ACTUALIZAR
                    item.TicketId    = itemVm.TicketId;
                    item.EmpleadoId  = itemVm.EmpleadoId;
                    item.FechaInicio = itemVm.FechaInicio;
                    item.FechaFinal  = itemVm.FechaFinal;
                    item.Nota        = itemVm.Nota;
                }
            }

            // AGREGAR
            if (origen.ListaEntrada != null && origen.ListaEntrada.Any())
            {
                foreach (var itemVm in origen.ListaEntrada?.Where(o => o.TicketEntradaId <= 0))
                {
                    var item = new TicketEntrada
                    {
                        TicketEntradaId = 0,
                        TicketId        = itemVm.TicketId,
                        EmpleadoId      = itemVm.EmpleadoId,
                        FechaInicio     = itemVm.FechaInicio,
                        FechaFinal      = itemVm.FechaFinal,
                        Nota            = itemVm.Nota,
                    };

                    destino.ListaEntrada.Add(item);
                }
            }
        }
예제 #13
0
        private void Actualizar(TicketVm ticketVm)
        {
            var obj = _repository.Obtener(ticketVm.TicketId);

            if (obj == null)
            {
                throw new InvalidOperationException("El registro no existe.");
            }

            TicketFactory.MapearAEntity(obj, ticketVm);

            _repository.Actualizar(obj);
        }
예제 #14
0
        public int AddTicket(TicketVm ticket)
        {
            var travelTicket = new Ticket
            {
                ArrivalStationId   = 9,
                DepartureStationId = 0,
                TripId             = 1,
                JourneyDate        = DateTime.Parse("2020-05-01"),
                Id = 1
            };

            return(travelTicket.Id);
        }
예제 #15
0
        /// <summary>
        /// Delete ticket
        /// </summary>
        /// <param name="ticketVm"></param>
        public async Task <int> DeleteTicketAsync(TicketVm ticketVm)
        {
            var ticketToBeDeleted = _dbContext.Tickets.Where(a => a.Id == ticketVm.Id && a.MainEventId == _mainEventProvider.MainEventId).FirstOrDefault();

            if (ticketToBeDeleted == null)
            {
                throw new HttpException(HttpStatusCode.NotFound, "Fant ikke billetten");
            }

            _dbContext.Remove <Ticket>(ticketToBeDeleted);
            await _dbContext.SaveChangesAsync();

            return(ticketToBeDeleted.Id);
        }
예제 #16
0
        public static void MapTicketEmpleado(TicketVm origen, Ticket destino)
        {
            if (destino.ListaEmpleado == null)
            {
                destino.ListaEmpleado = new List <TicketEmpleado>();
            }

            int cantidad = destino.ListaEmpleado.Count();

            for (int i = 0; i < cantidad; i++)
            {
                var item = destino.ListaEmpleado[i];

                var itemVm = origen
                             .ListaEmpleado?
                             .FirstOrDefault(o => o.TicketEmpleadoId == item.TicketEmpleadoId);

                if (itemVm == null)
                {
                    // ELIMINAR
                    destino.ListaEmpleado.Remove(item);
                    i--; cantidad--;
                }
                else
                {
                    // ACTUALIZAR
                    item.TicketId   = itemVm.TicketId;
                    item.EmpleadoId = itemVm.EmpleadoId;
                }
            }

            // AGREGAR
            if (origen.ListaEmpleado != null && origen.ListaEmpleado.Any())
            {
                foreach (var itemVm in origen.ListaEmpleado?.Where(o => o.TicketEmpleadoId <= 0))
                {
                    var item = new TicketEmpleado
                    {
                        TicketEmpleadoId = 0,
                        TicketId         = itemVm.TicketId,
                        EmpleadoId       = itemVm.EmpleadoId
                    };

                    destino.ListaEmpleado.Add(item);
                }
            }
        }
예제 #17
0
        public OperationResult Registrar(TicketVm ticket)
        {
            var resultado = ValidarModelo(ticket);

            if (resultado.EsValido)
            {
                if (ticket.TicketId == 0)
                {
                    Agregar(ticket);
                }
                else
                {
                    Actualizar(ticket);
                }
            }

            return(resultado);
        }
예제 #18
0
        /// <summary>
        /// Modify ticket
        /// </summary>
        /// <param name="ticketVm"></param>
        public async Task <int> UpdateTicketAsync(TicketVm ticketVm)
        {
            var existingTicket = _dbContext.Tickets.Where(a => a.Id == ticketVm.Id && a.MainEventId == _mainEventProvider.MainEventId).FirstOrDefault();

            if (existingTicket == null)
            {
                throw new HttpException(HttpStatusCode.NotFound, "Fant ikke billetten");
            }

            existingTicket.Id    = ticketVm.Id;
            existingTicket.Price = ticketVm.Price;


            _dbContext.Update <Ticket>(existingTicket);
            await _dbContext.SaveChangesAsync();

            return(existingTicket.Id);
        }
예제 #19
0
        public int AddTicket(TicketVm ticket)
        {
            var travelTicket = new Ticket
            {
                ArrivalStationId   = ticket.ArrivalStationId,
                DepartureStationId = ticket.DepartureStationId,
                TripId             = ticket.TripId,
                JourneyDate        = ticket.Date,
                Price = ticket.Price,
                State = TicketState.Pending
            };

            using (Oblig1Context db = new Oblig1Context())
            {
                db.Tickets.Add(travelTicket);
                db.SaveChanges();
            }

            return(travelTicket.Id);
        }
예제 #20
0
        public IActionResult Post([FromBody] TicketVm viewModel)
        {
            if (ModelState.IsValid == false)
            {
                return(BadRequest("The information is invalid"));
            }

            try
            {
                var resultado = _servicio.Registrar(viewModel);
                if (resultado.EsValido)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest("The register can't complete"));
                }
            }
            catch (Exception)
            {
                return(BadRequest("The register can't complete"));
            }
        }
        public IActionResult ConfirmTicket(List <TicketReservationVm> a, string PassengerName, int PassengerMobile)
        {
            var ab = a.Where(s => s.ConfirmStatus == true && s.MightBeReserve == true).ToList();

            if (ab.Count != 0)
            {
                Passenger p = new Passenger()
                {
                    PassengerId = 0,
                    Mobile      = PassengerMobile,
                    Name        = PassengerName
                };
                _context.Passengers.Add(p);
                _context.SaveChanges();

                var seatList = new List <string>();

                foreach (var item in ab)
                {
                    TicketReservation c = new TicketReservation()
                    {
                        TicketReservationId = item.TicketReservationId,
                        AgentId             = item.AgentId,
                        ConfirmStatus       = item.ConfirmStatus,
                        BusScheduleId       = item.BusScheduleId,
                        Date        = item.Date,
                        PassengerId = p.PassengerId,
                        SeatNumber  = item.SeatNumber
                    };

                    _context.TicketReservations.Update(c);
                    _context.SaveChanges();
                    seatList.Add(c.SeatNumber);
                }

                var ss = _context.BusSchedules.AsNoTracking().Include(sp => sp.Bus).ToList();
                var pa = _context.Places.AsNoTracking().ToList();
                var pp = _context.Places.AsNoTracking().ToList();
                var s  = from abc in ss
                         join ab1 in pa on abc.StartingFrom equals ab1.PlaceId
                         join aaab in pp on abc.Destination equals aaab.PlaceId
                         where abc.BusScheduleId == ab[0].BusScheduleId
                         select new
                {
                    DestinationName  = aaab.PlaceName,
                    StartingFromName = ab1.PlaceName,
                    Time             = abc.Time,

                    CoachName   = abc.Bus.CoachName,
                    TicketPrice = abc.TicketPrice,
                };



                TicketVm t = new TicketVm()
                {
                    PassengerName = p.Name,
                    Mobile        = p.Mobile,
                    Seat          = seatList,
                };
                foreach (var item in s)
                {
                    t.Destination = item.DestinationName;
                    t.StartFrom   = item.StartingFromName;

                    t.TicketPrice = item.TicketPrice;
                    t.Date        = a[0].Date;
                    t.BusName     = item.CoachName;
                    t.Time        = item.Time;
                }
                t.TotalCost = t.TicketPrice * ab.Count();



                return(View(t));
            }
            return(RedirectToAction("Index"));
        }