public JsonResult Suggestions(int id)
        {
            double totalPayment = 0;
            // С вкладки Заявки Админки при клике на заявку сюда приходит id выбранной заявки
            callout callout = _dbContext.callouts.Where(c => c.id == id).FirstOrDefault();

            // Сбор данных о авиабилетах
            List <object> airticketsList = new List <object>();

            foreach (airticket airticket in callout.airtickets)
            {
                flight flight = airticket.flight;

                double payment = 0;
                if (flight != null)
                {
                    payment = flight.cost;
                }

                if (airticket.is_baggage == 1)
                {
                    payment += payment * 0.1;
                }

                if (airticket.is_baby == 1)
                {
                    payment = 0;
                }

                totalPayment += payment;

                airticketsList.Add(new
                {
                    id = airticket.id,
                    created_datetime = Utils.tsToDateTime(airticket.created_at).ToString(Constants.ddMMMyyyyHmmss),
                    departure_at     = airticket.departure_at,

                    flight = flight != null ? new
                    {
                        id           = flight.id,
                        airline_name = flight.airline.name,
                        code         = flight.code,
                        duration     = flight.duration,
                        cost         = flight.cost,
                        total_seats  = flight.total_seats
                    } : null,

                    payment    = airticket.payment == 0 ? payment : airticket.payment,
                    is_baggage = airticket.is_baggage,
                    is_baby    = airticket.is_baby
                });
            }

            // Сбор данных о трансферах
            List <object> transfersList = new List <object>();

            foreach (transfer transfer in callout.transfers)
            {
                route route = transfer.route;

                airport fromAirport = null;
                airport toAirport   = null;

                double payment = 0;

                if (route != null)
                {
                    fromAirport = route.airport;
                    toAirport   = route.airport1;
                    payment     = route.cost;
                }

                if (transfer.is_baggage == 1)
                {
                    payment += payment * 0.1;
                }

                if (transfer.is_baby == 1)
                {
                    payment = 0;
                }

                totalPayment += payment;

                transfersList.Add(new
                {
                    id               = transfer.id,
                    starting_date    = transfer.starting_date.ToString(Constants.ddMMMyyyy),
                    created_datetime = Utils.tsToDateTime(transfer.created_at).ToString(Constants.ddMMMyyyyHmmss),
                    is_baggage       = transfer.is_baggage,
                    is_baby          = transfer.is_baby,

                    payment = transfer.payment == 0 ? payment : transfer.payment,

                    route = route != null ? new
                    {
                        id   = route.id,
                        type = route.type,

                        from_airport = fromAirport != null ? new
                        {
                            id        = fromAirport.id,
                            name      = fromAirport.name,
                            city_name = fromAirport.city.name
                        } : null,

                        to_airport = toAirport != null ? new
                        {
                            id        = toAirport.id,
                            name      = toAirport.name,
                            city_name = toAirport.city.name
                        } : null,

                        starting_address = route.starting_address,
                        starting_time    = route.starting_time.ToString(Constants.hhmmss),
                        final_address    = route.final_address,
                        duration         = route.duration,
                        total_seats      = route.total_seats,
                        distance         = route.distance,
                        cost             = route.cost,
                    } : null
                });
            }

            // Сбор данных о желаемых комнатах
            List <object> calloutRoomsList = new List <object>();

            foreach (callout_room calloutRoom in callout.callout_room)
            {
                room    room    = calloutRoom.room;
                hotel   hotel   = room.hotel;
                food    food    = hotel.food;
                city    city    = hotel.city;
                country country = city.country;

                int    numberNights = calloutRoom.duration / 24;
                double payment      = calloutRoom.room.cost_per_day * numberNights;

                totalPayment += payment;

                calloutRoomsList.Add(new
                {
                    id = calloutRoom.id,
                    created_datetime      = Utils.tsToDateTime(calloutRoom.created_at).ToString(Constants.ddMMMyyyyHmmss),
                    start_living_datetime = Utils.tsToDateTime(calloutRoom.start_living_at).ToString(Constants.ddMMMyyyyHmmss),
                    start_living_at       = calloutRoom.start_living_at,
                    duration = calloutRoom.duration,
                    payment  = calloutRoom.payment == 0 ? payment : calloutRoom.payment,

                    room = new
                    {
                        id           = room.id,
                        number       = room.number,
                        @class       = room.type,
                        seats_number = room.seats_number,
                        room_size    = room.room_size,
                        description  = room.description,
                        hotel        = new
                        {
                            id                = hotel.id,
                            name              = hotel.name,
                            stars_number      = hotel.stars_number,
                            distance_to_beach = hotel.distance_to_beach,

                            food = food != null ? new
                            {
                                id          = food.id,
                                type        = food.type,
                                description = food.description
                            } : null,

                            city = new
                            {
                                id      = city.id,
                                name    = city.name,
                                country = new
                                {
                                    id   = country.id,
                                    name = country.name
                                }
                            }
                        }
                    }
                });
            }

            // Сбор данных об экскурсиях в заявке
            List <object> excursionOrdersList = new List <object>();

            foreach (excursion_order excursionOrder in callout.excursion_order)
            {
                excursion excursion = excursionOrder.excursion;

                double payment = excursion.cost;

                if (excursionOrder.is_privilege == 1)
                {
                    payment -= payment * 0.5;
                }

                if (excursionOrder.is_baby == 1)
                {
                    payment = 0;
                }

                totalPayment += payment;

                excursionOrdersList.Add(new
                {
                    id = excursionOrder.id,
                    created_datetime  = Utils.tsToDateTime(excursionOrder.created_at).ToString(Constants.ddMMMyyyyHmmss),
                    starting_address  = excursionOrder.starting_address,
                    starting_datetime = Utils.tsToDateTime(excursionOrder.starting_at).ToString(Constants.ddMMMyyyy),
                    starting_at       = excursionOrder.starting_at,
                    is_baby           = excursionOrder.is_baby,
                    is_privilege      = excursionOrder.is_privilege,
                    is_custom         = excursionOrder.is_custom,
                    bus_place_number  = excursionOrder.bus_place_number,
                    payment           = excursionOrder.payment == 0 ? payment : excursionOrder.payment,

                    excursion = new
                    {
                        id            = excursion.id,
                        name          = excursion.name,
                        starting_time = excursion.starting_time != null ? ((TimeSpan)excursion.starting_time).ToString(Constants.hhmmss) : null,
                        duration      = excursion.duration,
                        city_name     = excursion.city != null ? excursion.city.name : null,
                        description   = excursion.description
                    }
                });
            }

            // Сбор данных о платных услугах в заявке
            List <object> hotelServiceOrdersList = new List <object>();

            foreach (hotel_service_order hotelServiceOrder in callout.hotel_service_order)
            {
                hotel_service service = hotelServiceOrder.hotel_service;

                double payment = service.cost_per_min * hotelServiceOrder.duration;

                totalPayment += payment;

                hotelServiceOrdersList.Add(new
                {
                    id = hotelServiceOrder.id,
                    created_datetime   = Utils.tsToDateTime(hotelServiceOrder.created_at).ToString(Constants.ddMMMyyyyHmmss),
                    provision_datetime = Utils.tsToDateTime(hotelServiceOrder.provision_at).ToString(Constants.ddMMMyyyyHmmss),
                    provision_at       = hotelServiceOrder.provision_at,
                    duration           = hotelServiceOrder.duration,
                    payment            = hotelServiceOrder.payment == 0 ? payment : hotelServiceOrder.payment,

                    room = hotelServiceOrder.room != null ? new
                    {
                        id     = hotelServiceOrder.room.id,
                        number = hotelServiceOrder.room.number
                    } : null,

                    hotel_service = new
                    {
                        id            = service.id,
                        hotel_name    = service.hotel.name,
                        description   = service.description,
                        starting_time = service.starting_time != null ? ((TimeSpan)service.starting_time).ToString(Constants.hhmmss) : null
                    }
                });
            }

            // возврат данных на фронтэнд (клиенту)
            return(Json(new
            {
                airtickets = airticketsList,
                transfers = transfersList,
                callout_rooms = calloutRoomsList,
                excursion_orders = excursionOrdersList,
                hotel_service_orders = hotelServiceOrdersList,

                total_payment = totalPayment,
                is_services =
                    airticketsList.Count() > 0
                    ||
                    transfersList.Count() > 0
                    ||
                    calloutRoomsList.Count() > 0
                    ||
                    excursionOrdersList.Count() > 0
                    ||
                    hotelServiceOrdersList.Count() > 0
            }, JsonRequestBehavior.DenyGet));
        }
Exemple #2
0
 return(SCDynamicStoreCreate(IntPtr.Zero, name, callout, context));
Exemple #3
0
        public ActionResult CalloutCreate(FavotiteListView favListView)
        {
            callout callout = new callout
            {
                fullname   = favListView.Fullname,
                email      = favListView.Email,
                phone      = favListView.Phone,
                created_at = Utils.dtToTimestamp(DateTime.Now)
            };

            if (Request.Form["is_predefined"] != null)
            {
                callout.is_predefined = sbyte.Parse(Request.Form["is_predefined"]);
            }

            _dbContext.callouts.Add(callout);

            _dbContext.SaveChanges();

            var rooms = _dbContext.rooms;
            var list  = Session["selected-check"] as List <int>;

            if (list != null)
            {
                foreach (var item in list)
                {
                    _dbContext.callout_room.Add(
                        new callout_room
                    {
                        callout_id = callout.id,
                        room_id    = item,
                        created_at = Utils.dtToTimestamp(DateTime.Now)
                    });

                    _dbContext.SaveChanges();
                }
            }

            Session["selected-check"] = null;

            var list2 = Session["flight-check"] as List <int>;

            if (list2 != null)
            {
                foreach (var item in list2)
                {
                    _dbContext.airtickets.Add(
                        new airticket
                    {
                        callout_id = callout.id,
                        flight_id  = item,
                        created_at = Utils.dtToTimestamp(DateTime.Now)
                    });

                    _dbContext.SaveChanges();
                }
            }

            Session["flight-check"] = null;

            var list3 = Session["route-check"] as List <int>;

            if (list3 != null)
            {
                foreach (var item in list3)
                {
                    _dbContext.transfers.Add(
                        new transfer
                    {
                        callout_id = callout.id,
                        route_id   = item,
                        created_at = Utils.dtToTimestamp(DateTime.Now)
                    });

                    _dbContext.SaveChanges();
                }
            }

            Session["route-check"] = null;

            var list4 = Session["excursion-check"] as List <int>;

            if (list4 != null)
            {
                foreach (var item in list4)
                {
                    var eo = new excursion_order
                    {
                        callout_id       = callout.id,
                        excursion_id     = item,
                        created_at       = Utils.dtToTimestamp(DateTime.Now),
                        starting_address = ""
                    };

                    _dbContext.excursion_order.Add(eo);
                    _dbContext.SaveChanges();
                }
            }

            Session["excursion-check"] = null;

            var list5 = Session["hotelservice-check"] as List <int>;

            if (list5 != null)
            {
                foreach (var item in list5)
                {
                    _dbContext.hotel_service_order.Add(
                        new hotel_service_order
                    {
                        callout_id       = callout.id,
                        hotel_service_id = item,
                        created_at       = Utils.dtToTimestamp(DateTime.Now)
                    });

                    _dbContext.SaveChanges();
                }
            }

            Session["hotelservice-check"] = null;

            _dbContext.SaveChanges();

            return(View());
        }