public static ExternalCartAddOrderResult ExternalCart_AddOrder(string language, WebPartner partner, string externalCartId, BookingOrder order) { if (partner == null) { throw new System.ArgumentNullException("partner"); } if (order == null) { throw new System.ArgumentNullException("order"); } BookingClaim claim = new BookingClaim { orders = new System.Collections.Generic.List <BookingOrder>() }; claim.orders.Add(order); XElement xml = BookingProvider.BuildBookingClaimXml(partner.id, claim); DataSet ds = DatabaseOperationProvider.QueryProcedure("up_guest_ExternalCart_AddOrder", "result", new { lang = language, OrdersXML = xml, CartId = externalCartId, PartPass = partner.passId }); return(( from DataRow row in ds.Tables["result"].Rows select BookingProvider.factory.ExternalCartAddOrderResult(row)).FirstOrDefault <ExternalCartAddOrderResult>()); }
public static ReservationState DoCalculation(string language, int partnerId, BookingClaim claim) { if (claim == null) { throw new System.ArgumentNullException("claim"); } XElement xml = BookingProvider.BuildBookingClaimXml(partnerId, claim); return(BookingProvider.BuildBookingProcessResult(language, "calc", xml, null)); }
public static CheckPromoCodeResult CheckExcursionPromoCode(string language, int partnerId, BookingClaim claim, string promoCode) { if (claim == null) { throw new System.ArgumentNullException("claim"); } if (string.IsNullOrEmpty(promoCode)) { throw new System.ArgumentNullException("promoCode"); } XElement xml = BookingProvider.BuildBookingClaimXml(partnerId, claim); DataSet ds = DatabaseOperationProvider.QueryProcedure("[promo].[up_CheckExPromoCodes]", "errors", new { OrdersXML = xml, lang = language, PromoCode = promoCode }); CheckPromoCodeResult result = ( from DataRow row in ds.Tables["errors"].Rows select BookingProvider.factory.CheckPromoCodeResult(row)).FirstOrDefault<CheckPromoCodeResult>(); result.code = promoCode; return result; }
private static XElement BuildBookingClaimXml(int partner, BookingClaim claim) { if (claim == null) { throw new System.ArgumentNullException("claim"); } XElement bookingXml = new XElement("Booking"); XElement reservationXml = new XElement("Reservation", new object[] { new XAttribute("partnerid", partner), new XElement("Note", claim.note) }); bookingXml.Add(reservationXml); XElement personsXml = new XElement("Persons"); bookingXml.Add(personsXml); XElement ordersXml = new XElement("Orders"); bookingXml.Add(ordersXml); if (claim.orders != null) { foreach (BookingOrder order in claim.orders) { if (order.excursion != null) { XElement membersXml = new XElement("Members"); if (order.excursion.pax != null) { for (int i = 0; i < order.excursion.pax.adult; i++) { string personId = System.Guid.NewGuid().ToString(); if (i == 0 && order.excursion.contact != null) { personsXml.Add(new XElement("Person", new object[] { new XAttribute("id", personId), new XAttribute("agetype", "adult"), (order.excursion.contact.name != null) ? new XAttribute("name", order.excursion.contact.name) : null, (order.excursion.contact.name != null) ? new XAttribute("latinname", order.excursion.contact.name) : null, (order.excursion.contact.mobile != null) ? new XElement("Contact", new XElement("Phones", new XAttribute("mobile", order.excursion.contact.mobile))) : null })); } else { personsXml.Add(new XElement("Person", new object[] { new XAttribute("id", personId), new XAttribute("agetype", "adult") })); } membersXml.Add(new XElement("Member", new XAttribute("personid", personId))); } for (int i = 0; i < order.excursion.pax.child; i++) { string personId = System.Guid.NewGuid().ToString(); personsXml.Add(new XElement("Person", new object[] { new XAttribute("id", personId), new XAttribute("agetype", "child") })); membersXml.Add(new XElement("Member", new XAttribute("personid", personId))); } for (int i = 0; i < order.excursion.pax.infant; i++) { string personId = System.Guid.NewGuid().ToString(); personsXml.Add(new XElement("Person", new object[] { new XAttribute("id", personId), new XAttribute("agetype", "infant") })); membersXml.Add(new XElement("Member", new XAttribute("personid", personId))); } } ordersXml.Add(new XElement("Order", new object[] { new XAttribute("type", "excursion"), new XAttribute("id", order.orderid ?? ""), new XAttribute("datefrom", System.DateTime.SpecifyKind(order.excursion.date.Date, System.DateTimeKind.Unspecified)), new XAttribute("datetill", System.DateTime.SpecifyKind(order.excursion.date.Date, System.DateTimeKind.Unspecified)), new XElement("Excursion", new object[] { new XAttribute("excursionid", order.excursion.id), (!order.excursion.extime.HasValue) ? null : new XElement("Time", new XAttribute("id", order.excursion.extime)), (!order.excursion.grouptype.HasValue) ? null : new XElement("GroupType", new XAttribute("id", order.excursion.grouptype)), (!order.excursion.language.HasValue) ? null : new XElement("Language", new XAttribute("id", order.excursion.language)), (order.excursion.pickuppoint.HasValue || order.excursion.pickuphotel.HasValue) ? new XElement("From", new object[] { order.excursion.pickuppoint.HasValue ? new XElement("Geopoint", new XAttribute("id", order.excursion.pickuppoint)) : null, order.excursion.pickuphotel.HasValue ? new XElement("Hotel", new XAttribute("id", order.excursion.pickuphotel)) : null }) : null }), new XElement("Note", order.excursion.note), membersXml })); } } } if (claim.customer != null) { Customer customer = claim.customer; bookingXml.Add(new XElement("Customer", new object[] { new XAttribute("name", customer.name ?? ""), (claim.customer.passport == null) ? null : new XElement("Passport", new object[] { (customer.passport.serie == null) ? null : new XAttribute("serie", customer.passport.serie), (customer.passport.number == null) ? null : new XAttribute("number", customer.passport.number), (!customer.passport.issuedate.HasValue) ? null : new XAttribute("issuedate", System.DateTime.SpecifyKind(customer.passport.issuedate.Value, System.DateTimeKind.Unspecified)), (customer.passport.issueplace == null) ? null : new XAttribute("issueplace", customer.passport.issueplace) }), new XElement("Contact", new object[] { (customer.address == null) ? null : new XElement("Address", customer.address), (customer.mobile == null) ? null : new XElement("Phones", new XAttribute("mobile", customer.mobile)), (customer.email == null) ? null : new XElement("Email", customer.email) }) })); } if (claim.PromoCodes != null && claim.PromoCodes.Count > 0) { XElement promoCodesXML = new XElement("Promo"); foreach (string code in claim.PromoCodes) { promoCodesXML.Add(new XElement("Code", code)); } bookingXml.Add(promoCodesXML); } return bookingXml; }
public static ExternalCartAddOrderResult ExternalCart_AddOrder(string language, WebPartner partner, string externalCartId, BookingOrder order) { if (partner == null) { throw new System.ArgumentNullException("partner"); } if (order == null) { throw new System.ArgumentNullException("order"); } BookingClaim claim = new BookingClaim { orders = new System.Collections.Generic.List<BookingOrder>() }; claim.orders.Add(order); XElement xml = BookingProvider.BuildBookingClaimXml(partner.id, claim); DataSet ds = DatabaseOperationProvider.QueryProcedure("up_guest_ExternalCart_AddOrder", "result", new { lang = language, OrdersXML = xml, CartId = externalCartId, PartPass = partner.passId }); return ( from DataRow row in ds.Tables["result"].Rows select BookingProvider.factory.ExternalCartAddOrderResult(row)).FirstOrDefault<ExternalCartAddOrderResult>(); }
public static ReservationState DoCalculation(string language, int partnerId, BookingClaim claim) { if (claim == null) { throw new System.ArgumentNullException("claim"); } XElement xml = BookingProvider.BuildBookingClaimXml(partnerId, claim); return BookingProvider.BuildBookingProcessResult(language, "calc", xml, null); }
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 }; GuestService.Controllers.Api.BookingController controller = new GuestService.Controllers.Api.BookingController(); bookingClaim.note = form.BookingNote; Customer customer = new Customer { name = form.CustomerName, 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); return base.View(model); }
private static XElement BuildBookingClaimXml(int partner, BookingClaim claim) { if (claim == null) { throw new System.ArgumentNullException("claim"); } XElement bookingXml = new XElement("Booking"); XElement reservationXml = new XElement("Reservation", new object[] { new XAttribute("partnerid", partner), new XElement("Note", claim.note) }); bookingXml.Add(reservationXml); XElement personsXml = new XElement("Persons"); bookingXml.Add(personsXml); XElement ordersXml = new XElement("Orders"); bookingXml.Add(ordersXml); if (claim.orders != null) { foreach (BookingOrder order in claim.orders) { if (order.excursion != null) { XElement membersXml = new XElement("Members"); if (order.excursion.pax != null) { for (int i = 0; i < order.excursion.pax.adult; i++) { string personId = System.Guid.NewGuid().ToString(); if (i == 0 && order.excursion.contact != null) { personsXml.Add(new XElement("Person", new object[] { new XAttribute("id", personId), new XAttribute("agetype", "adult"), (order.excursion.contact.name != null) ? new XAttribute("name", order.excursion.contact.name) : null, (order.excursion.contact.name != null) ? new XAttribute("latinname", order.excursion.contact.name) : null, (order.excursion.contact.mobile != null) ? new XElement("Contact", new XElement("Phones", new XAttribute("mobile", order.excursion.contact.mobile))) : null })); } else { personsXml.Add(new XElement("Person", new object[] { new XAttribute("id", personId), new XAttribute("agetype", "adult") })); } membersXml.Add(new XElement("Member", new XAttribute("personid", personId))); } for (int i = 0; i < order.excursion.pax.child; i++) { string personId = System.Guid.NewGuid().ToString(); personsXml.Add(new XElement("Person", new object[] { new XAttribute("id", personId), new XAttribute("agetype", "child") })); membersXml.Add(new XElement("Member", new XAttribute("personid", personId))); } for (int i = 0; i < order.excursion.pax.infant; i++) { string personId = System.Guid.NewGuid().ToString(); personsXml.Add(new XElement("Person", new object[] { new XAttribute("id", personId), new XAttribute("agetype", "infant") })); membersXml.Add(new XElement("Member", new XAttribute("personid", personId))); } } ordersXml.Add(new XElement("Order", new object[] { new XAttribute("type", "excursion"), new XAttribute("id", order.orderid ?? ""), new XAttribute("datefrom", System.DateTime.SpecifyKind(order.excursion.date.Date, System.DateTimeKind.Unspecified)), new XAttribute("datetill", System.DateTime.SpecifyKind(order.excursion.date.Date, System.DateTimeKind.Unspecified)), new XElement("Excursion", new object[] { new XAttribute("excursionid", order.excursion.id), (!order.excursion.extime.HasValue) ? null : new XElement("Time", new XAttribute("id", order.excursion.extime)), (!order.excursion.grouptype.HasValue) ? null : new XElement("GroupType", new XAttribute("id", order.excursion.grouptype)), (!order.excursion.language.HasValue) ? null : new XElement("Language", new XAttribute("id", order.excursion.language)), (order.excursion.pickuppoint.HasValue || order.excursion.pickuphotel.HasValue) ? new XElement("From", new object[] { order.excursion.pickuppoint.HasValue ? new XElement("Geopoint", new XAttribute("id", order.excursion.pickuppoint)) : null, order.excursion.pickuphotel.HasValue ? new XElement("Hotel", new XAttribute("id", order.excursion.pickuphotel)) : null }) : null }), new XElement("Note", order.excursion.note), membersXml })); } } } if (claim.customer != null) { Customer customer = claim.customer; bookingXml.Add(new XElement("Customer", new object[] { new XAttribute("name", customer.name ?? ""), (claim.customer.passport == null) ? null : new XElement("Passport", new object[] { (customer.passport.serie == null) ? null : new XAttribute("serie", customer.passport.serie), (customer.passport.number == null) ? null : new XAttribute("number", customer.passport.number), (!customer.passport.issuedate.HasValue) ? null : new XAttribute("issuedate", System.DateTime.SpecifyKind(customer.passport.issuedate.Value, System.DateTimeKind.Unspecified)), (customer.passport.issueplace == null) ? null : new XAttribute("issueplace", customer.passport.issueplace) }), new XElement("Contact", new object[] { (customer.address == null) ? null : new XElement("Address", customer.address), (customer.mobile == null) ? null : new XElement("Phones", new XAttribute("mobile", customer.mobile)), (customer.email == null) ? null : new XElement("Email", customer.email) }) })); } if (claim.PromoCodes != null && claim.PromoCodes.Count > 0) { XElement promoCodesXML = new XElement("Promo"); foreach (string code in claim.PromoCodes) { promoCodesXML.Add(new XElement("Code", code)); } bookingXml.Add(promoCodesXML); } return(bookingXml); }
public static CheckPromoCodeResult CheckExcursionPromoCode(string language, int partnerId, BookingClaim claim, string promoCode) { if (claim == null) { throw new System.ArgumentNullException("claim"); } if (string.IsNullOrEmpty(promoCode)) { throw new System.ArgumentNullException("promoCode"); } XElement xml = BookingProvider.BuildBookingClaimXml(partnerId, claim); DataSet ds = DatabaseOperationProvider.QueryProcedure("[promo].[up_CheckExPromoCodes]", "errors", new { OrdersXML = xml, lang = language, PromoCode = promoCode }); CheckPromoCodeResult result = ( from DataRow row in ds.Tables["errors"].Rows select BookingProvider.factory.CheckPromoCodeResult(row)).FirstOrDefault <CheckPromoCodeResult>(); result.code = promoCode; return(result); }
public static ReservationState DoCalculation(string language, int partnerId, BookingClaim claim) { if (claim == null) { throw new System.ArgumentNullException("claim"); } XElement xml = BookingProvider.BuildBookingClaimXml(partnerId, claim); var res = BookingProvider.BuildBookingProcessResult("", language, "calc", xml, null, null); List<string> errorsId = new List<string>(); foreach (var error in res.errors) { errorsId.Add(error.orderid); } var placesList = new Dictionary<string, int>(); foreach (var order in claim.orders) { if (!errorsId.Contains(order.orderid)) { string key = order.excursion.id + "_" + order.excursion.date.ToString("yyyy-MM-dd") +"_" + (order.excursion.extime ?? -1) + "_" + (order.excursion.departure ?? -1) + "_" + (order.excursion.language ?? -1); var places = 0; if (placesList.ContainsKey(key)) places = placesList[key]; else { places = GetFreePlacesForExcursion(order); placesList.Add(key, places); } if (places < order.excursion.pax.adult + order.excursion.pax.child + order.excursion.pax.infant) // считать ли инфанта { res.errors.Add(new ReservationError() { errortype = ReservationErrorType.user, isstop = true, message = Resources.BookingStrings.Get("ErrorNoMorePlaces"), usermessage = Resources.BookingStrings.Get("ErrorNoMorePlaces"), number = 1, orderid = order.orderid }); } else { placesList[key] = places - (order.excursion.pax.adult + order.excursion.pax.child + order.excursion.pax.infant); } } } return res; }
public static ReservationState DoBooking(string language, int partnerId, int partnerPassId, BookingClaim claim, int wl) { //перед бронированием проверить наличие мест if (claim == null) { throw new System.ArgumentNullException("claim"); } XElement xml = BookingProvider.BuildBookingClaimXml(partnerId, claim); var calcRes = DoCalculation(language, partnerId, claim); if (calcRes.errors.Count > 0) return calcRes; return BookingProvider.BuildBookingProcessResult( claim.orders[0].excursion.curr ,language, "save", xml, new int?(partnerPassId), new int?(wl)); }