示例#1
0
        public OperationDetails CreateTrip(TripModel item)
        {
            var tripPoco = tripMapper.MapEntity(item);
            var result   = tripRepository.Create(tripPoco);

            unitOfWork.Save();

            return(new OperationDetails(true, $"Trip with id {result.Id} was successsfully created", ""));
        }
示例#2
0
        public OperationDetails CreateRoute(RouteModel item)
        {
            var routePoco = routeMapper.MapEntity(item);

            if (GetExistedRoute(item) == null)
            {
                var result = routeRepository.Create(routePoco);
                unitOfWork.Save();

                return(new OperationDetails(true, $"Route with id {result.Id} was successsfully created", ""));
            }

            throw new PassengersCarriageValidationException("This route already exists", String.Empty);
        }
示例#3
0
        public OperationDetails SaveOrder(OrderModel orderModel)
        {
            var userMessage = "";
            var view        = "";

            if (orderModel.Id != 0)
            {
                var oldOrder = orderRepository.GetById(orderModel.Id);
                AttachSeatNumberToTrip(oldOrder.Trip, oldOrder.SeatNumber);
                userMessage = !(orderModel.SeatNumber == oldOrder.SeatNumber)
                    ? $"Order with id {orderModel.Id} was successfully updated." +
                              $"Your seat number is changed from {oldOrder.SeatNumber} on {orderModel.SeatNumber}"
                                    : $"Your seat number is stayed the same: {oldOrder.SeatNumber}";
                view = "Orders";
            }

            DetachSeatNumberFromTrip(tripRepository.GetById(orderModel.TripId), orderModel.SeatNumber);
            orderRepository.Update(orderMapper.MapEntity(orderModel));
            unitOfWork.Save();

            return(new OperationDetails(true,
                                        String.IsNullOrEmpty(userMessage) ? $"Order was successfully created. " +
                                        $"Your seat number is {orderModel.SeatNumber}"
                    : userMessage, String.IsNullOrEmpty(view) ? "Trips" : view));
        }