private void serializeToModel(ref excursion excursion) { if (Request.Form["starting_time"] == "") { excursion.starting_time = null; } else { excursion.starting_time = TimeSpan.Parse(Request.Form["starting_time"]); } if (Request.Form["city_id"] == "") { excursion.city_id = null; } else { excursion.city_id = int.Parse(Request.Form["city_id"]); } excursion.name = Request.Form["name"]; excursion.cost = int.Parse(Request.Form["cost"]); excursion.description = Request.Form["description"]; excursion.duration = int.Parse(Request.Form["duration"]); }
public JsonResult Delete(int id) { Dictionary <string, object> result = new Dictionary <string, object>(); try { excursion excursion = _dbContext.excursions.Find(id); if (excursion != null) { if (excursion.excursion_order.Count() > 0) { int excursionOrdersBlockedCounter = 0; List <excursion_order> excursionOrderList = excursion.excursion_order.ToList(); foreach (excursion_order eo in excursionOrderList) { if (Utils.dtToTimestamp(DateTime.Now) > eo.starting_at) { _dbContext.excursion_order.Remove(eo); } else { excursionOrdersBlockedCounter++; } } if (excursionOrdersBlockedCounter == 0) { _dbContext.excursions.Remove(excursion); } else { result.Add("error", "На данный момент экскурсия заказана. Удаление недопустимо"); } } else { _dbContext.excursions.Remove(excursion); } _dbContext.SaveChanges(); } else { result.Add("error", "Экскурсия не найдена"); } } catch (Exception exc) { result.Add("error", exc.Message); } return(Json(result, JsonRequestBehavior.DenyGet)); }
private void serializeToExcursionOrderModel(ref excursion_order excursionOrder) { excursionOrder.excursion_id = int.Parse(Request.Form["excursion_id"]); excursionOrder.starting_address = Request.Form["starting_address"]; excursionOrder.starting_at = Utils.dtToTimestamp(Convert.ToDateTime(Request.Form["starting_at"])); excursionOrder.created_at = Utils.dtToTimestamp(DateTime.Now); excursionOrder.callout_id = int.Parse(Request.Form["callout_id"]); excursionOrder.is_baby = Request.Form["is_baby"] == "on" ? 1 : 0; excursionOrder.is_privilege = Request.Form["is_privilege"] == "on" ? 1 : 0; excursion excursion = _dbContext.excursions.Find(excursionOrder.excursion_id); excursionOrder.payment = excursionOrder.is_privilege == 1 ? (excursion.cost - excursion.cost / 2) : excursion.cost; excursionOrder.payment = excursionOrder.is_baby == 1 ? 0 : excursionOrder.payment; }
public JsonResult Edit(int id) { Dictionary <string, object> result = new Dictionary <string, object>(); try { excursion excursion = _dbContext.excursions.Find(id); serializeToModel(ref excursion); _dbContext.SaveChanges(); } catch (Exception exc) { result.Add("error", exc.Message); } return(Json(result, JsonRequestBehavior.DenyGet)); }
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)); }