public static List<PaymentMode> ApplyPaymentComissions(List<PaymentMode> modes, ReservationPrice topay)
        {
            var excontrol = new GuestService.Controllers.Api.ExcursionController();

            for (int i = 0; i < modes.Count; i++)
            {
                try
                {
                    var modeId = modes[i].id.Split('.')[0];

                    decimal comissionProcent = 0;
                    var targetCurrency = modes[i].payrest.currency;
                    //если есть комиссия
                    if (ConfigurationManager.AppSettings.AllKeys.Contains("PaymentModeComission_" + modeId))
                    {
                        comissionProcent = Convert.ToDecimal(ConfigurationManager.AppSettings["PaymentModeComission_" + modeId]);
                    }

                    modes[i].comission = new ReservationOrderPrice()
                    {
                        currency = topay.currency,
                        total = Math.Round((topay.total / 100m * comissionProcent), 2)
                    };

                    modes[i].payrest = new ReservationOrderPrice()
                    {
                        currency = topay.currency,
                        total = Math.Round(modes[i].comission.total + topay.total, 2)
                    };

                    modes[i].comission = excontrol.ConvertPrice(modes[i].comission, targetCurrency);
                    modes[i].payrest = excontrol.ConvertPrice(modes[i].payrest, targetCurrency);
                }
                catch (Exception ex) {
                    Console.Write(ex.Message);
                }
            }

            return modes;
        }
        public ActionResult Index([Bind(Prefix = "Form")] BookingModel form)
        {
            Predicate<BookingOrderModel> match = null;
            Predicate<BookingOrder> predicate2 = null;
            Action<BookingOrderModel> action2 = null;
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }
            if (form.Action == "remove")
            {
                base.ModelState.Clear();
                if ((form.RemoveOrderId != null) && (form.Orders != null))
                {
                    if (match == null)
                    {
                        match = m => ((m != null) && (m.BookingOrder != null)) && (m.BookingOrder.orderid == form.RemoveOrderId);
                    }
                    form.Orders.RemoveAll(match);
                    using (ShoppingCart cart = ShoppingCart.CreateFromSession(base.Session))
                    {
                        if ((cart != null) && (cart.Orders != null))
                        {
                            if (predicate2 == null)
                            {
                                predicate2 = m => m.orderid == form.RemoveOrderId;
                            }
                            cart.Orders.RemoveAll(predicate2);
                        }
                    }
                }
            }
            BookingContext model = new BookingContext();

            model.PaymentModes = BookingProvider.GetPaymentModes(UrlLanguage.CurrentLanguage, 2025654180);

            BookingClaim bookingClaim = new BookingClaim {
                orders = new List<BookingOrder>()
            };
            if (form.Orders != null)
            {
                if (action2 == null)
                {
                    action2 = delegate (BookingOrderModel m) {
                        if ((m != null) && (m.BookingOrder != null))
                        {
                            bookingClaim.orders.Add(m.BookingOrder);
                        }
                    };
                }
                form.Orders.ForEach(action2);
            }
            BookingCartParam bookingCartParam = new BookingCartParam {
                ln = UrlLanguage.CurrentLanguage,
                pa = form.PartnerAlias,
                psid = form.PartnerSessionID,
                wl = PartnerContentProvider.GetPartnerUserId()
            };
            GuestService.Controllers.Api.BookingController controller = new GuestService.Controllers.Api.BookingController();
            bookingClaim.note = form.BookingNote;
            Customer customer = new Customer {
                name = form.CustomerName + " " + form.CustomerSecondName,
                mobile = form.CustomerMobile,
                email = form.CustomerEmail,
                address = form.CustomerAddress
            };
            bookingClaim.customer = customer;
            if (form.PromoCodes != null)
            {
                bookingClaim.PromoCodes = new List<string>(form.PromoCodes);
            }
            if (form.Action == null)
            {
                if (!form.RulesAccepted)
                {
                    base.ModelState.AddModelError("Form.RulesAccepted", BookingStrings.RulesAccepted);
                }
                if (base.ModelState.IsValid)
                {
                    CompleteOperation operation = CompleteOperation.CreateFromSession(base.Session);
                    operation.Start();
                    model.BookingOperationId = operation.OperationId;
                    int? userId = WebSecurity.IsAuthenticated ? new int?(WebSecurity.CurrentUserId) : null;
                    ThreadPool.QueueUserWorkItem(delegate (object o) {
                        try
                        {
                            BookingCartResult result = new BookingCartResult {
                                Form = form,
                                Reservation = controller.Book(bookingCartParam, bookingClaim)
                            };
                            if (((result.Reservation != null) && result.Reservation.claimId.HasValue) && userId.HasValue)
                            {
                                GuestProvider.LinkGuestClaim(userId.Value, result.Reservation.claimId.Value);
                            }
                            string data = JsonConvert.SerializeObject(result);
                            CompleteOperationProvider.SetResult(operation.OperationId, "bookingresult", data);
                        }
                        catch (Exception exception)
                        {
                            Tracing.WebTrace.TraceEvent(TraceEventType.Error, 2, exception.ToString());
                            CompleteOperationProvider.SetResult(operation.OperationId, null, null);
                        }
                    }, null);
                    model.Form = form;
                    return base.View("_BookingProcessing", model);
                }
            }
            else if (form.Action == "promo")
            {
                base.ModelState.Clear();
                List<string> list = (form.PromoCodes == null) ? new List<string>() : new List<string>(form.PromoCodes);
                if (!string.IsNullOrWhiteSpace(form.PromoCode))
                {
                    Action<BookingOrderModel> action = null;
                    BookingClaim checkPromoClaim = new BookingClaim {
                        orders = new List<BookingOrder>()
                    };
                    if (form.Orders != null)
                    {
                        if (action == null)
                        {
                            action = delegate (BookingOrderModel m) {
                                if ((m != null) && (m.BookingOrder != null))
                                {
                                    checkPromoClaim.orders.Add(m.BookingOrder);
                                }
                            };
                        }
                        form.Orders.ForEach(action);
                    }
                    checkPromoClaim.PromoCodes = (form.PromoCodes != null) ? new List<string>(form.PromoCodes) : new List<string>();
                    CheckPromoCodeResult result = controller.CheckPromoCode(bookingCartParam, bookingClaim, form.PromoCode);
                    if ((result != null) && (result.errorcode == 0))
                    {
                        list.Add(form.PromoCode);
                        bookingClaim.PromoCodes = list;
                        form.PromoCodes = list.ToArray();
                    }
                    else
                    {
                        base.ModelState.AddModelError("PromoCodeError", (result != null) ? result.errormessage : "невозможно применить промо код");
                    }
                }
            }

            ReservationState reservation = controller.Calculate(bookingCartParam, bookingClaim);

            model.Prepare(form, reservation);
            model.PaymentModes = ApplyPaymentComissions(model.PaymentModes, model.Reservation.price);

            for (int i = 0; i < bookingClaim.orders.Count; i++)
            {
                if ((bookingClaim.orders[i].excursion.pickuptime != null) && (bookingClaim.orders[i].excursion.pickuptime.Length > 5))
                    model.Reservation.orders[i].excursion.pickuptime = Convert.ToDateTime(bookingClaim.orders[i].excursion.pickuptime).ToString("HH:mm");
                else
                    model.Reservation.orders[i].excursion.pickuptime = bookingClaim.orders[i].excursion.pickuptime;
            }

            var targetCurr = "EUR";

            if (Session["currency"] != null)
                targetCurr = Session["currency"].ToString();

            if (targetCurr != model.Reservation.price.currency)
            {
                var excontrol = new GuestService.Controllers.Api.ExcursionController();

                model.Reservation.price = excontrol.ConvertPrice(model.Reservation.price, targetCurr);

                for (int i = 0; i < model.Reservation.orders.Count; i++)
                {
                    model.Reservation.orders[i].price = excontrol.ConvertPrice(model.Reservation.orders[i].price, targetCurr);
                    model.Form.Orders[i].ReservationOrder.price = excontrol.ConvertPrice(model.Form.Orders[i].ReservationOrder.price, targetCurr);
                }
            }

            model.PaymentModes = FilterModes(model.PaymentModes, targetCurr);
            model.Form.WhiteLabelId = PartnerContentProvider.GetPartnerUserId();

            return base.View(model);
        }