public HttpResponseMessage ImportPowerMenuOrder()
        {
            HttpResponseMessage returnValue = new HttpResponseMessage();
            string payload = null;
            VendorPurchaseOrderRequest po = null;

            try
            {
                _log.WriteInformationLog("Receiving order from PowerMenu");
                payload = this.Request.Content.ReadAsStringAsync().Result;
                payload = WebUtility.UrlDecode(payload.Replace("xml=", ""));

                _log.WriteInformationLog(String.Format("PowerMenu Order Payload: {0}", payload));

                XmlSerializer serializer = new XmlSerializer(typeof(VendorPurchaseOrderRequest));

                using (XmlReader rdr = XmlReader.Create(new StringReader(payload)))
                {
                    po = (VendorPurchaseOrderRequest)serializer.Deserialize(rdr);
                }

                Guid newCart = _cartService.ImportFromPowerMenu(po);

                string redirectTo = string.Format("{0}/#/cart/{1}", KeithLink.Svc.Impl.Configuration.PresentationUrl, newCart);
                returnValue.Headers.Location = new Uri(redirectTo);
                returnValue.StatusCode       = HttpStatusCode.Redirect;
                _log.WriteInformationLog("Successfully imported powermenu order.");
            }
            catch (Exception ex)
            {
                _log.WriteErrorLog(String.Format("Problem importing powermenu order. Payload: {0} - Purchase Order: {1}", payload, po), ex);
            }

            return(returnValue);
        }
示例#2
0
        public Guid ImportFromPowerMenu(VendorPurchaseOrderRequest powerMenuRequest)
        {
            UserProfile user = _profileLogic.GetUserProfile(powerMenuRequest.Login.Username).UserProfiles.FirstOrDefault();

            Core.Models.ShoppingCart.ShoppingCart newCart = new Core.Models.ShoppingCart.ShoppingCart();
            newCart.Items = new List <ShoppingCartItem>();

            // Get the customer information needed
            List <Customer> customers = _customerRepo.GetCustomersForUser(user.UserId);
            Customer        customer  = customers.Distinct()
                                        .Where(x =>
                                               x.CustomerNumber.Equals(powerMenuRequest.Order.OrderHeader.CustomerNumber) &&
                                               x.IsPowerMenu.Equals(true)
                                               )
                                        .FirstOrDefault();

            // Set the selected user context
            UserSelectedContext context = new UserSelectedContext();

            context.BranchId   = customer.CustomerBranch;
            context.CustomerId = customer.CustomerNumber;

            // Build the generated cart
            newCart.BranchId = customer.CustomerBranch;
            newCart.PONumber = string.Format("eMenuManage Order {0} ", powerMenuRequest.Order.OrderHeader.PurchaseOrderNumber);
            newCart.Name     = string.Format("eMenuManage Order - {0}", DateTime.Now.ToString());

            List <ShoppingCartItem> shoppingCartItems = powerMenuRequest.Order.OrderItem.ToShoppingCartItems(context.BranchId.ToLower());

            newCart.Items.AddRange(shoppingCartItems);

            ShipDateReturn validDates = _shipDateRepository.GetShipDates(context);

            newCart.RequestedShipDate = validDates.ShipDates.FirstOrDefault().Date;

            return(_shoppingCartLogic.CreateCart(user, context, newCart));
        }