Exemplo n.º 1
0
        public JsonResult Delete(int id)
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            try
            {
                hotel_service hotelService = _dbContext.hotel_service.Find(id);
                if (hotelService != null)
                {
                    if (hotelService.hotel_service_order.Count() > 0)
                    {
                        int hotelServiceOrdersBlockedCounter             = 0;
                        List <hotel_service_order> hotelServiceOrderList = hotelService.hotel_service_order.ToList();
                        foreach (hotel_service_order hso in hotelServiceOrderList)
                        {
                            if (Utils.dtToTimestamp(DateTime.Now) > hso.provision_at)
                            {
                                _dbContext.hotel_service_order.Remove(hso);
                            }
                            else
                            {
                                hotelServiceOrdersBlockedCounter++;
                            }
                        }

                        if (hotelServiceOrdersBlockedCounter == 0)
                        {
                            _dbContext.hotel_service.Remove(hotelService);
                        }
                        else
                        {
                            result.Add("error", "На данный момент услуга заказана. Удаление недопустимо");
                        }
                    }
                    else
                    {
                        _dbContext.hotel_service.Remove(hotelService);
                    }

                    _dbContext.SaveChanges();
                }
                else
                {
                    result.Add("error", "Услуга не найдена");
                }
            }
            catch (Exception exc)
            {
                result.Add("error", exc.Message);
            }

            return(Json(result, JsonRequestBehavior.DenyGet));
        }
        private void serializeToHotelServiceOrderModel(ref hotel_service_order hotelServiceOrder)
        {
            hotelServiceOrder.hotel_service_id = int.Parse(Request.Form["hotel_service_id"]);
            hotelServiceOrder.duration         = int.Parse(Request.Form["duration"]);
            hotelServiceOrder.provision_at     = Utils.dtToTimestamp(Convert.ToDateTime(Request.Form["provision_at"]));
            hotelServiceOrder.created_at       = Utils.dtToTimestamp(DateTime.Now);
            hotelServiceOrder.callout_id       = int.Parse(Request.Form["callout_id"]);

            hotel_service hotelService = _dbContext.hotel_service.Find(hotelServiceOrder.hotel_service_id);

            hotelServiceOrder.payment = hotelService.cost_per_min * hotelServiceOrder.duration;
        }
Exemplo n.º 3
0
        public JsonResult Edit(int id)
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            try
            {
                hotel_service hotelService = _dbContext.hotel_service.Find(id);
                serializeToModel(ref hotelService);
                _dbContext.SaveChanges();
            }
            catch (Exception exc)
            {
                result.Add("error", exc.Message);
            }

            return(Json(result, JsonRequestBehavior.DenyGet));
        }
Exemplo n.º 4
0
        private void serializeToModel(ref hotel_service hotelService)
        {
            if (Request.Form["hotel_id"] == "")
            {
                hotelService.hotel_id = null;
            }
            else
            {
                hotelService.hotel_id = int.Parse(Request.Form["hotel_id"]);
            }

            if (Request.Form["starting_time"] == "")
            {
                hotelService.starting_time = null;
            }
            else
            {
                hotelService.starting_time = TimeSpan.Parse(Request.Form["starting_time"]);
            }

            hotelService.description  = Request.Form["description"];
            hotelService.cost_per_min = int.Parse(Request.Form["cost_per_min"]);
        }
        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));
        }