public async Task <IActionResult> Post([FromBody] CreateStation station)
        {
            var result = await _stationService.CreateStation(HttpHelper.GetUserId(HttpContext), station);

            return(new JsonResult(result)
            {
                StatusCode = result.Status
            });
        }
        public ActionResult CreateStation(StationCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid Request"));
            }
            var createResult = _stationService.CreateStation(model);

            if (createResult == false)
            {
                return(StatusCode((int)HttpStatusCode.NotAcceptable, createResult));
            }
            return(Ok());
        }
Beispiel #3
0
        private static void StationServiceTest()
        {
            Console.WriteLine("Testing station service");
            stationService = Container.Resolve <IStationService>();
            stationService.CreateStation(new StationDTO
            {
                Name = "Ceska",
                Town = "Brno"
            });

            var brnoStations = stationService.GetAllStationsByTown("Brno");

            if (brnoStations == null || !brnoStations.Any())
            {
                Console.WriteLine("NOK: Not found any station in Brno");
            }
            else if (brnoStations.Where(station => station.Name == "Ceska") == null || !brnoStations.Any())
            {
                Console.WriteLine("NOK: Station Ceska in Brno not created");
            }
            else
            {
                Console.WriteLine("OK");
            }
            var stationCeska = stationService.GetStationById(brnoStations.First().ID);

            if (stationCeska.Name != "Ceska" || stationCeska.Town != "Brno")
            {
                Console.WriteLine("NOK: Not found station Ceska in Brno by Id");
            }
            else
            {
                Console.WriteLine("OK");
            }
            stationService.DeleteStation(stationCeska.ID);
            if (stationService.GetStationById(stationCeska.ID) != null)
            {
                Console.WriteLine("NOK: Station not deleted");
            }
            else
            {
                Console.WriteLine("OK");
            }
        }
Beispiel #4
0
        //data are not deleted, depends on specific id
        private static void FindRouteTest()
        {
            try
            {
                stationService = Container.Resolve <IStationService>();
                routeService   = Container.Resolve <IRouteService>();
                vehicleService = Container.Resolve <IVehicleService>();
                companyService = Container.Resolve <ICompanyService>();
                stationService.CreateStation(new StationDTO
                {
                    Name = "Ceska",
                    Town = "Brno"
                });
                stationService.CreateStation(new StationDTO
                {
                    Name = "Hlavni",
                    Town = "Brno"
                });
                stationService.CreateStation(new StationDTO
                {
                    Name = "Olomoucka",
                    Town = "Brno"
                });
                stationService.CreateStation(new StationDTO
                {
                    Name = "Klusackova",
                    Town = "Brno"
                });

                routeService.CreateRoute(new RouteDTO
                {
                    Name = "First Route"
                }, companyId);

                routeService.CreateRoute(new RouteDTO
                {
                    Name = "Second Route"
                }, companyId);


                var route    = routeService.ListAllRoutes().Last();
                var stations = stationService.GetAllStationsByTown("Brno");
                int order    = 1;

                foreach (var station in stations)
                {
                    routeService.AddRouteStation(station.ID, route.ID, new RouteStationDTO
                    {
                        DepartFromFirstStation      = DateTime.Today,
                        DistanceFromPreviousStation = 2,
                        TimeFromFirstStation        = new TimeSpan(0, 5, 0),
                        TimeToNextStation           = new TimeSpan(0, 0, 0),
                        Order = order
                    });
                    order++;
                }
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }

            //routeService.FindRoutesWithStations(1, 3, DateTime.Today);
        }
Beispiel #5
0
        private static void TicketServiceTest()
        {
            customerService = Container.Resolve <ICustomerService>();
            ticketService   = Container.Resolve <ITicketService>();
            stationService  = Container.Resolve <IStationService>();
            routeService    = Container.Resolve <IRouteService>();
            vehicleService  = Container.Resolve <IVehicleService>();

            Console.WriteLine("Testing ticket and route service");
            routeService.CreateRoute(new RouteDTO
            {
                Name = "Tylova-Ceska"
            }, companyId);

            stationService.CreateStation(new StationDTO
            {
                Name = "Ceska",
                Town = "Brno"
            });
            stationService.CreateStation(new StationDTO
            {
                Name = "Tylova",
                Town = "Brno"
            });

            var stations = stationService.GetAllStationsByTown("Brno");
            var routeId  = routeService.ListAllRoutes().FirstOrDefault().ID;

            foreach (var station in stations)
            {
                if (station.Name.Equals("Ceska"))
                {
                    routeService.AddRouteStation(station.ID, routeId, new RouteStationDTO
                    {
                        DepartFromFirstStation      = null,
                        DistanceFromPreviousStation = 0,
                        TimeFromFirstStation        = new TimeSpan(0, 0, 0),
                        TimeToNextStation           = new TimeSpan(0, 5, 0),
                    });
                }
                else
                {
                    routeService.AddRouteStation(station.ID, routeId, new RouteStationDTO
                    {
                        DepartFromFirstStation      = null,
                        DistanceFromPreviousStation = 2,
                        TimeFromFirstStation        = new TimeSpan(0, 5, 0),
                        TimeToNextStation           = new TimeSpan(0, 0, 0),
                    });
                }
            }

            vehicleService.CreateVehicle(new VehicleDTO
            {
                LicencePlate = "a",
                VehicleType  = VehicleType.Bus,
                SeatCount    = 2
            }, companyId);

            routeService.CreateSpecificRoute(routeId, DateTime.Now, vehicleService.GetVehicleIdByLicencePlate("a"));

            var listRouteStations = routeService.GetRouteStationsByRoute(routeId);

            int[] listRouteStationsForTicket = new int[2];
            int   i = 0;

            foreach (var routeStation in listRouteStations)
            {
                if (routeStation.DepartFromFirstStation != null)
                {
                    listRouteStationsForTicket[i] = routeStation.ID;
                    i++;
                }
            }
            customerService.CreateCustomer(new CustomerDTO
            {
                FirstName = "Josef",
                LastName  = "Kosta",
                Email     = "*****@*****.**"
            });
            var customerDto = customerService.GetCustomerByEmail("*****@*****.**");

            ticketService.CreateTicket(customerDto.ID, companyId, new TicketDTO {
                Departure = DateTime.Now + (new TimeSpan(2, 0, 0)), RouteName = "Ceska"
            }, routeService.ListEmptyProgramsOfRouteStations(listRouteStationsForTicket).First());

            var ticketId = ticketService.ListAllTickets().FirstOrDefault().ID;

            ticketService.TicketReservation(ticketId);

            Console.WriteLine(ticketService.GetTicketById(ticketId).Price == 4 ? "OK: Ticket reservation works... sorry deadline in 1 hour and I managed to create ticket 10 minutes ago so no time for clever tests" : "NOK:Ticket does not work");

            discountService = Container.Resolve <IDiscountService>();
            discountService.CreateDiscount(new DiscountDTO
            {
                Value        = 50,
                DiscountType = DiscountType.Student
            }, companyId);

            var discountId = discountService.ListDiscountsOfCompany(null, companyId).First().ID;

            ticketService.ClaimDiscount(ticketId, discountId, false, null);
            Console.WriteLine(ticketService.GetTicketById(ticketId).Price == 2 ? "OK: Ticket claim discount works... 10 min to deadline...." : "NOK:Ticket does not work");
            ticketService.TicketRefund(ticketId);

            Console.WriteLine(ticketService.GetTicketById(ticketId).IsRefunded ? "OK: Ticket refund works... idk if this is worth 2 credits :/" : "NOK:Ticket does not work");
            routeService.DeleteRoute(routeId);
            foreach (var station in stations)
            {
                stationService.DeleteStation(station.ID);
            }
            customerService.DeleteCustomer(customerDto.ID);
        }
Beispiel #6
0
 public void CreateStation(StationDTO stationDTO)
 {
     stationService.CreateStation(stationDTO);
 }