Exemple #1
0
        public OrderOperationStatus GetOrder(Contact contact, int orderIndex)
        {
            var operationStatus = new OrderOperationStatus();
            try
            {
                var sql = Sql.Builder
                    .Select("*")
                    .From("cpxOrder");

                sql.Append("WHERE status='PROV' AND OrderIndex=@0",orderIndex);

                if (contact.ContactId > 0)
                {
                    sql.Append("AND ContactId=@0", contact.ContactId);
                }
                else
                    sql.Append("AND UserId=@0", contact.UserId);

                var order =
                    _database.SingleOrDefault<Order>(sql);

                //if no order found with contact id, try user id
                if (contact.ContactId > 0 & order == null)
                {
                    sql = Sql.Builder
                             .Select("*")
                             .From("cpxOrder")
                             .Where("status='PROV' AND OrderIndex=@0 AND UserId=@1",orderIndex,contact.UserId);
                    order = _database.SingleOrDefault<Order>(sql);
                }

                if (order == null)
                {
                    order = CreateOrder(contact, orderIndex);
                }
                if (contact.ContactId != order.ContactId)
                {
                    order.ContactId = contact.ContactId;
                    _database.Update(order);
                }

                order.OrderLines = _database.Fetch<OrderLine>("SELECT * FROM cpxOrderLines WHERE OrderId=@0",order.OrderId);
                operationStatus.Order = order;
                operationStatus.Status = true;
            }
            catch (Exception e)
            {
                operationStatus = OperationStatusExceptionHelper<OrderOperationStatus>
                    .CreateFromException("An error has occurred retrieving the order", e);
            }
            return operationStatus;
        }
Exemple #2
0
 public OrderOperationStatus QueueOrder(Order order, Contact contact)
 {
     var operationStatus = new OrderOperationStatus();
     try
     {
         SendEmails(order, contact);
         _additionalQueueProcessingHandlerFactory.GetHandler(order.AdditionalQueueProcessingHandler).PerformAdditionalProcessing(order,contact);
         order.Status = "QUE";
         order.UpdateOrderLines("QUE");
         _orderRepository.SaveOrder(order);
         operationStatus.Order = order;
         operationStatus.Status = true;
     }
     catch (Exception e)
     {
         operationStatus = OperationStatusExceptionHelper<OrderOperationStatus>
             .CreateFromException("An error has occurred processing the order", e);
     }
     return operationStatus;
 }
Exemple #3
0
 public OrderOperationStatus Remove(Product product)
 {
     var orderOperationStatus = new OrderOperationStatus();
     OrderLine orderLine = GetOrderLine(product);
     orderLine.OrderStatus = "DEL";
     orderOperationStatus.Order = this;
     orderOperationStatus.Status = true;
     orderOperationStatus.OrderLine = orderLine;
     orderOperationStatus.OrderLineDeleted = true;
     return orderOperationStatus;
 }
Exemple #4
0
        public OrderOperationStatus Add(Product product, int quantity,string paymentType,decimal paymentAmount)
        {
            var orderOperationStatus = new OrderOperationStatus();
            if (ContainsProduct(product)&&product.ProductType!="D")
            {
                return Update(product, product, quantity, paymentType, paymentAmount);
            }

            if (product.ChargedPrice == null)
            {
                orderOperationStatus.Message = "The item cannot be added because no price has been specified";
                orderOperationStatus.MessageCode = "CPX.NoPriceSpecified";
                orderOperationStatus.Status = false;
                return orderOperationStatus;
            }

            var orderLine = new OrderLine
            {
                OrderId = OrderId,
                ProductId = product.ProductId,
                ProductExternalId = product.ProductExternalId,
                ProductPrice = (decimal)product.ChargedPrice,
                ProductTitle = product.Title,
                ProductOptionId = product.OptionId,
                ProductOptionTitle = product.OptionTitle,
                ProductCategory = product.Category,
                ProductVoucherCategory = product.VoucherCategory,
                ProductCode = product.Code,
                ProductOptionExternalId = product.OptionExternalId,
                ProductType = product.ProductType,
                ProductUrl = product.ProductUrl,
                PaymentType = paymentType,
                PaymentAmount = paymentAmount,
                Location=product.Location,
                LocationCode=product.LocationCode,
                LocationEmail=product.LocationEmail,
                StartDate = product.StartDate,
                FinishDate=product.FinishDate,
                Quantity = quantity,
                OrderStatus="PROV",
                PaymentStatus="N"
            };
            OrderLines.Add(orderLine);

            orderOperationStatus.Status = true;
            orderOperationStatus.Order = this;
            orderOperationStatus.OrderLine = orderLine;
            return orderOperationStatus;
        }
Exemple #5
0
        public OrderOperationStatus GetOrder(int orderId)
        {
            var operationStatus = new OrderOperationStatus();
            try
            {
                var sql = Sql.Builder
                    .Select("*")
                    .From("cpxOrder");

                sql.Append("WHERE OrderId=@0", orderId);

                var order =
                    _database.SingleOrDefault<Order>(sql);

                order.OrderLines = _database.Fetch<OrderLine>("SELECT * FROM cpxOrderLines WHERE OrderId=@0", order.OrderId);
                operationStatus.Order = order;
                operationStatus.Status = true;
            }
            catch (Exception e)
            {
                operationStatus = OperationStatusExceptionHelper<OrderOperationStatus>
                    .CreateFromException("An error has occurred retrieving the order", e);
            }
            return operationStatus;
        }
Exemple #6
0
        public OrderOperationStatus SaveOrder(Order order, bool updateOrderLines)
        {
            var orderOperationStatus = new OrderOperationStatus();
            try
            {
                if (!_database.IsNew(order))
                {
                    _database.Update(order);
                    if (updateOrderLines)
                    {
                        for (int i = 0; i < order.OrderLines.Count; i++)
                        {
                            if (_database.IsNew(order.OrderLines[i]))
                            {
                                order.OrderLines[i].OrderLineId =
                                    (int)_database.Insert(order.OrderLines[i]);

                            }
                            else
                            {
                                _database.Update(order.OrderLines[i]);
                            }
                        }
                    }
                    orderOperationStatus.Status = true;
                    orderOperationStatus.Message = "The order has been saved successfully.";
                }
                else
                {
                    orderOperationStatus.Status = false;
                    orderOperationStatus.Message = "The order could not be found.";

                }
                orderOperationStatus.Order = order;

            }
            catch (Exception e)
            {
                orderOperationStatus = OperationStatusExceptionHelper<OrderOperationStatus>
                    .CreateFromException("An error has occurred saving the order"+e.Message+e.StackTrace, e);

            }
            return orderOperationStatus;
        }
Exemple #7
0
        public OrderOperationStatus AddVoucherToOrder(string voucherCode)
        {
            var orderOperationStatus=new OrderOperationStatus();
            try
            {
                var voucherOperationStatus = _voucherRepository.GetVoucher(voucherCode);

                if (!voucherOperationStatus.Status)
                {
                    orderOperationStatus =
                        (OrderOperationStatus) orderOperationStatus.InjectFrom(voucherOperationStatus);
                }
                else
                {
                    Voucher voucher = voucherOperationStatus.Voucher;

                    var contactOperationStatus = _contactService.GetContact();
                    if (!contactOperationStatus.Status)
                    {
                        orderOperationStatus =
                            (OrderOperationStatus) orderOperationStatus.InjectFrom(contactOperationStatus);
                    }
                    else
                    {
                        orderOperationStatus = _orderCoordinator.GetOrder(contactOperationStatus.Contact, voucher.OrderIndex);
                        if (orderOperationStatus.Status)
                        {
                            var order = orderOperationStatus.Order;
                            order.VoucherId = voucher.VoucherId;
                            order.VoucherAmount = voucher.Amount;
                            order.VoucherPercentage = voucher.Percentage;
                            order.VoucherPerItemAmount = voucher.PerItemAmount;
                            order.VoucherProductCategoryFilter = voucher.ProductCategoryFilter;
                            order.VoucherCategoryFilter = voucher.VoucherCategoryFilter;
                            order.VoucherMinimumItems = voucher.MinimumItems;
                            order.VoucherMinimumPayment = voucher.MinimumPayment;
                            order.VoucherInfo = "Voucher used: " + voucher.Title;
                            orderOperationStatus = _orderCoordinator.SaveOrder(order, false);
                            if (orderOperationStatus.Status)
                                orderOperationStatus.Message = "Voucher " + voucher.Title + " added successfully!";
                            if (order.GetVoucherTotal() == 0)
                                orderOperationStatus.Message +=
                                "  However, none of your current items are discounted with this voucher";

                        }

                    }
                }
            }
            catch (Exception e)
            {
                orderOperationStatus.LogFailedOperation(e,"An error has occurred adding the voucher");
            }
            return orderOperationStatus;
        }
Exemple #8
0
        public OrderOperationStatus ConfirmOrder(int orderIndex)
        {
            var orderOperationStatus = new OrderOperationStatus();
            try
            {
                var contactOperationStatus = _contactService.GetContact();

                if (!contactOperationStatus.Status)
                {
                    orderOperationStatus =
                        (OrderOperationStatus) orderOperationStatus.InjectFrom(contactOperationStatus);
                }
                else
                {
                    orderOperationStatus = _orderCoordinator.GetOrder(contactOperationStatus.Contact, orderIndex);
                    if (orderOperationStatus.Status)
                    {
                        var order = orderOperationStatus.Order;
                        order.Status = "CONF";
                        order.UpdateOrderLines("CONF");
                        orderOperationStatus = _orderCoordinator.SaveOrder(order, true);
                        if (orderOperationStatus.Status)
                            orderOperationStatus.Message = "Thankyou for confirming your order.";

                    }
                }
            }
            catch (Exception e)
            {
                orderOperationStatus = OperationStatusExceptionHelper<OrderOperationStatus>
                    .CreateFromException("An error has occurred updating the order line", e);

            }
            return orderOperationStatus;
        }
Exemple #9
0
 private OrderOperationStatus AddProductToOrder(int productId, int optionId, int quantity, DateTime? startDate,
     DateTime? finishDate, string paymentType,
     decimal? paymentAmount)
 {
     var orderOperationStatus = new OrderOperationStatus();
     try
     {
         //get the product
         var productOperationStatus = GetProduct(productId, optionId, quantity, startDate, finishDate,
             paymentType, paymentAmount);
         var product = productOperationStatus.Product;
         if (!productOperationStatus.Status)
             return (OrderOperationStatus) orderOperationStatus.InjectFrom(productOperationStatus);
         if (paymentAmount == null) paymentAmount = GetPaymentAmount(product, paymentType);
         orderOperationStatus = AddProductToOrder(product, quantity, paymentType, (decimal) paymentAmount);
     }
     catch (Exception e)
     {
         orderOperationStatus.LogFailedOperation(e, "An error has occurred adding the product to the order");
     }
     return orderOperationStatus;
 }
Exemple #10
0
        public OrderOperationStatus UpdateSpecialRequirements(string specialRequirements, int orderIndex)
        {
            var orderOperationStatus = new OrderOperationStatus();
            try
            {
                var contactOperationStatus = _contactService.GetContact();
                if (!contactOperationStatus.Status)
                {
                    orderOperationStatus =
                        (OrderOperationStatus) contactOperationStatus.InjectFrom(contactOperationStatus);
                }
                else
                {
                    orderOperationStatus = _orderCoordinator.GetOrder(contactOperationStatus.Contact, orderIndex);
                    if (orderOperationStatus.Status)
                    {
                        var order = orderOperationStatus.Order;
                        order.SpecialRequirements = specialRequirements;
                        orderOperationStatus = _orderCoordinator.SaveOrder(order, false);
                        if (orderOperationStatus.Status)
                            orderOperationStatus.Message = "Special requirements updated successfully!";
                    }
                }
            }
            catch (Exception e)
            {
                orderOperationStatus.LogFailedOperation(e, "An error has occurred adding the voucher");
            }
            return orderOperationStatus;

            //var contactOperationStatus = _contactService.GetContact();
            //if (contactOperationStatus.Status)
            //{
            //    return _orderRepository.UpdateSpecialRequirements(specialRequirements, orderIndex, contactOperationStatus.Contact);
            //}
            //return (OrderOperationStatus)new OrderOperationStatus().InjectFrom(contactOperationStatus);
        }
Exemple #11
0
        public OrderOperationStatus UpdateGiftAidAgreement(bool agreementStatus, int orderIndex)
        {
            var orderOperationStatus = new OrderOperationStatus();
            try
            {
                var contactOperationStatus = _contactService.GetContact();
                if (contactOperationStatus.Status)
                {
                    //orderOperationStatus =
                    //    (OrderOperationStatus) orderOperationStatus.InjectFrom(contactOperationStatus);
                    //}
                    //else
                    //{
                    var contact = contactOperationStatus.Contact;
                    if (contact.ContactId > 0)
                    {
                        contact.GiftAidAgreement = agreementStatus;
                        contactOperationStatus = _contactService.SaveContact(contact);
                        if (!contactOperationStatus.Status)
                        {
                            orderOperationStatus =
                                (OrderOperationStatus) orderOperationStatus.InjectFrom(contactOperationStatus);
                            return orderOperationStatus;
                        }
                    }
                }
                orderOperationStatus = _orderCoordinator.GetOrder(contactOperationStatus.Contact, orderIndex);
                if (orderOperationStatus.Status)
                {
                    var order = orderOperationStatus.Order;
                    order.GiftAidAgreement = agreementStatus;
                    orderOperationStatus = _orderCoordinator.SaveOrder(order, false);
                    if (orderOperationStatus.Status)
                        orderOperationStatus.Message = "Gift Aid agreement updated successfully!";
                }

            }
            catch (Exception e)
            {
                orderOperationStatus.LogFailedOperation(e, "An error has occurred updating the Gift Aid agreement");
            }
            return orderOperationStatus;
        }
Exemple #12
0
        public OrderOperationStatus Update(int productId, int optionId, int newOptionId, int quantity, 
                                           string paymentType)
        {
            var orderOperationStatus = new OrderOperationStatus();
            try
            {
                //get the product
                var productOperationStatus = _productRepository.GetProduct(productId, optionId);

                Product oldProduct = productOperationStatus.Product;
                productOperationStatus = _productRepository.GetProduct(productId, newOptionId);

                if (!productOperationStatus.Status)
                    return (OrderOperationStatus) new OrderOperationStatus().InjectFrom(productOperationStatus);

                Product newProduct = productOperationStatus.Product;

                if (quantity > newProduct.MaximumQuantity && newProduct.MaximumQuantity != 0)
                    return new OrderOperationStatus { Message = "No more items of this type can be added!", Status = false };

                //get the contact
                var contactOperationStatus = _contactService.GetContact();
                if (!contactOperationStatus.Status)
                    return (OrderOperationStatus) new OrderOperationStatus().InjectFrom(contactOperationStatus);
                var contact = contactOperationStatus.Contact;

                //get the order
                orderOperationStatus = _orderCoordinator.GetOrder(contact, oldProduct.OrderIndex);
                var order = orderOperationStatus.Order;

                if (newProduct.HasBespokePricing())
                {
                    var oldOrderLine = order.GetOrderLine(oldProduct);
                    newProduct.StartDate = oldOrderLine.StartDate;
                    newProduct.FinishDate = oldOrderLine.FinishDate;
                    newProduct = GetBespokePricing(newProduct, quantity);
                }

                decimal paymentAmount = GetPaymentAmount(newProduct, paymentType);

                orderOperationStatus=order.Update(oldProduct, newProduct, quantity, paymentType, paymentAmount);
                var orderLine = orderOperationStatus.OrderLine;

                if (orderOperationStatus.Status)
                {
                    order = _orderCoordinator.UpdateOrderWithShippingAndDiscounts(order, contact);
                    orderOperationStatus = _orderCoordinator.SaveOrder(order,true);
                    orderOperationStatus.OrderLine = orderLine;
                    orderOperationStatus.Message = "Updated " + oldProduct.Title + " successfully!";
                }
            }
            catch (Exception e)
            {
               orderOperationStatus.LogFailedOperation(e,"An error has occurred saving the order");
            }
            return orderOperationStatus;
        }
Exemple #13
0
        public OrderOperationStatus Remove(int productId, int optionId)
        {
            var orderOperationStatus = new OrderOperationStatus();
            try
            {
                //get the product
                var productOperationStatus = _productRepository.GetProduct(productId, optionId);
                if (!productOperationStatus.Status)
                    return (OrderOperationStatus) orderOperationStatus.InjectFrom(productOperationStatus);

                Product product = productOperationStatus.Product;

                //get the contact
                var contactOperationStatus = _contactService.GetContact();
                if (!contactOperationStatus.Status)
                    return (OrderOperationStatus) new OrderOperationStatus().InjectFrom(contactOperationStatus);
                var contact = contactOperationStatus.Contact;

                //get the order
                orderOperationStatus = _orderCoordinator.GetOrder(contact,product.OrderIndex);
                var order = orderOperationStatus.Order;
                orderOperationStatus=order.Remove(product);
                var orderLine = orderOperationStatus.OrderLine;
                if (orderOperationStatus.Status)
                {
                    order = _orderCoordinator.UpdateOrderWithShippingAndDiscounts(order, contact);
                    orderOperationStatus = _orderCoordinator.SaveOrder(order,true);
                    orderOperationStatus.OrderLine = orderLine;
                    orderOperationStatus.OrderLineDeleted = true;
                    orderOperationStatus.Message = "Removed " + product.Title + " successfully!";
                }
            }
            catch (Exception e)
            {
                orderOperationStatus.LogFailedOperation(e,"An error has occurred saving the order");
            }
            return orderOperationStatus;
        }
Exemple #14
0
        public OrderOperationStatus GetOrder(int orderIndex)
        {
            var orderOperationStatus = new OrderOperationStatus();
            try
            {

                var contactOperationStatus = _contactService.GetContact();
                if (!contactOperationStatus.Status)
                    return (OrderOperationStatus) orderOperationStatus.InjectFrom(contactOperationStatus);

                var contact = contactOperationStatus.Contact;

                orderOperationStatus = _orderCoordinator.GetOrder(contactOperationStatus.Contact, orderIndex);

                if (orderOperationStatus.Status)
                {
                    var order = orderOperationStatus.Order;
                    order.ContactDetails = contact;
                    order.UserName = contact.UserName;
                    //update the shipping and discounts
                    order = _orderCoordinator.UpdateOrderWithShippingAndDiscounts(order, contact);
                    orderOperationStatus = _orderCoordinator.SaveOrder(order, false);
                    if (orderOperationStatus.Status)
                    {
                        //add the product options to the order
                        foreach (var orderLine in order.CurrentOrderLines)
                        {
                            var productOperationStatus = _productRepository.GetProductOptions(orderLine.ProductId);
                            if (productOperationStatus.Status)
                                orderLine.ProductOptions = productOperationStatus.ProductOptions;
                            var paymentOperationStatus = _productRepository.GetPaymentOptions(orderLine.ProductId,
                                orderLine.ProductOptionId, orderLine.ProductLineTotal, orderLine.Quantity);
                            if (paymentOperationStatus.Status)
                                orderLine.PaymentOptions = paymentOperationStatus.PaymentOptions;
                        }

                    }
                    orderOperationStatus.Order = order;
                }
            }
            catch (Exception e)
            {
                orderOperationStatus.LogFailedOperation(e, "An error has occurred retrieving the order");
            }
            return orderOperationStatus;
        }
Exemple #15
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="oldProduct"></param>
        /// <param name="newProduct"></param>
        /// <param name="quantity"></param>
        /// <param name="paymentType"></param>
        /// <param name="paymentAmount"></param>
        /// <returns>if product to be updated doesn't exist in order, </returns>
        public OrderOperationStatus Update(Product oldProduct, Product newProduct, int quantity, string paymentType,
                                decimal paymentAmount)
        {
            var orderOperationStatus = new OrderOperationStatus();
            // if the quantity is zero, do a remove instead
            if (quantity == 0)
                return Remove(oldProduct);

            if (newProduct.ChargedPrice == null)
            {
                orderOperationStatus.Message = "The item cannot be added because no price has been specified";
                orderOperationStatus.MessageCode = "CPX.NoPriceSpecified";
                orderOperationStatus.Status = false;
                return orderOperationStatus;
            }

            if (!ContainsProduct(oldProduct))
            {
                orderOperationStatus.Message = "The item cannot be updated because it does not exist in the order";
                orderOperationStatus.MessageCode = "CPX.ItemNotInOrder";
                orderOperationStatus.Status = false;
                return orderOperationStatus;
            }

            //check that the product to be udated to doesn't exist
            if (newProduct.OptionId > 0 && oldProduct.OptionId != newProduct.OptionId &&
                                    ContainsProduct(newProduct))
            {
                orderOperationStatus.Message = "There is already an item of this type in the order";
                orderOperationStatus.MessageCode = "CPX.ItemAlreadyInOrder";
                orderOperationStatus.Status = false;
                return orderOperationStatus;
            }

            if (paymentAmount > newProduct.ChargedPrice)
            {
                orderOperationStatus.Message = "The item cannot be updated because it would mean an over-payment";
                orderOperationStatus.MessageCode = "CPX.OverPayment";
                orderOperationStatus.Status = false;
                return orderOperationStatus;

            }

            //get the order line to update
            OrderLine orderLine = GetOrderLine(oldProduct);
            //merge in changes from the update
            orderLine.ProductPrice = (decimal)newProduct.ChargedPrice;
            orderLine.ProductOptionTitle = newProduct.OptionTitle;
            orderLine.ProductOptionId = newProduct.OptionId;
            orderLine.ProductOptionExternalId = newProduct.OptionExternalId;
            orderLine.StartDate = newProduct.StartDate;
            orderLine.FinishDate = newProduct.FinishDate;

            orderLine.Quantity = quantity;
            orderLine.PaymentType = paymentType;
            orderLine.PaymentAmount = paymentAmount;

            orderOperationStatus.Status = true;
            orderOperationStatus.Order = this;
            orderOperationStatus.OrderLine = orderLine;
            return orderOperationStatus;
        }
        private OrderResultSummary GetOrderResultSummary(OrderOperationStatus operationStatus)
        {
            var resultSummary=new OrderResultSummary();

            resultSummary.Status = operationStatus.Status;

            string umbracoCode = "";
            if (!String.IsNullOrEmpty(operationStatus.MessageCode))
                umbracoCode = UmbracoHelper.GetDictionaryItem(operationStatus.MessageCode);
            resultSummary.Message = String.IsNullOrEmpty(umbracoCode) ? operationStatus.Message : umbracoCode;

            if (operationStatus.Status)
            {
                resultSummary.NumberOfItems = operationStatus.Order.NumberOfItems;
                resultSummary.OrderId = operationStatus.Order.OrderId;
                resultSummary.PaymentSubTotal = string.Format("{0:C}",operationStatus.Order.PaymentSubTotal);
                resultSummary.PaymentSubTotalIncludingDiscountAndVoucher = string.Format("{0:C}",operationStatus.Order.PaymentSubTotalIncludingDiscountAndVoucher);
                resultSummary.PaymentTotal = string.Format("{0:C}",operationStatus.Order.PaymentTotal);
                resultSummary.ProductSubTotal = string.Format("{0:C}",operationStatus.Order.ProductSubTotal);
                resultSummary.ShippingInfo = operationStatus.Order.ShippingInfo;
                resultSummary.ShippingTotal = string.Format("{0:C}",operationStatus.Order.ShippingTotal);
                resultSummary.DiscountInfo = operationStatus.Order.DiscountInfo;
                resultSummary.DiscountTotal = string.Format("{0:C}",-operationStatus.Order.DiscountTotal);
                resultSummary.VoucherInfo = operationStatus.Order.VoucherInfo;
                resultSummary.VoucherTotal = string.Format("{0:C}",-operationStatus.Order.GetVoucherTotal());
                resultSummary.ContainsGiftAidableProducts = operationStatus.Order.ContainsGiftAidableProducts();
                //resultSummary.InjectFrom<IgnoreNulls>(operationStatus.Order);
                if (operationStatus.OrderLine!=null)
                {
                    resultSummary.OrderLine = operationStatus.OrderLine;
                    resultSummary.PaymentLineTotal = string.Format("{0:C}",operationStatus.OrderLine.PaymentLineTotal);

                }
                resultSummary.OrderId = operationStatus.Order.OrderId;
            }
            return resultSummary;
        }
Exemple #17
0
        private OrderOperationStatus AddProductToOrder(Product product, int quantity, string paymentType,
            decimal paymentAmount)
        {
            var orderOperationStatus = new OrderOperationStatus();
            //get the contact
            try
            {
                var contactOperationStatus = _contactService.GetContact();
                if (!contactOperationStatus.Status)
                    return (OrderOperationStatus) new OrderOperationStatus().InjectFrom(contactOperationStatus);

                var contact = contactOperationStatus.Contact;

                //get the current order
                orderOperationStatus = _orderCoordinator.GetOrder(contactOperationStatus.Contact, product.OrderIndex);
                if (orderOperationStatus.Status)
                {
                    var order = orderOperationStatus.Order;
                    //check the quantity
                    if (product.MaximumQuantity != 0 &&
                        quantity + order.GetQuantityOfProduct(product) > product.MaximumQuantity)
                        return new OrderOperationStatus
                        {
                            Message = "No more items of this type can be added!",
                            Status = false
                        };
                    //add the order line
                    orderOperationStatus = order.Add(product, quantity, paymentType, (decimal) paymentAmount);
                    var orderLine = orderOperationStatus.OrderLine;
                    if (orderOperationStatus.Status)
                    {
                        order = _orderCoordinator.UpdateOrderWithShippingAndDiscounts(order, contact);
                        orderOperationStatus = _orderCoordinator.SaveOrder(order, true);
                        if (orderOperationStatus.Status)
                        {
                            orderOperationStatus.OrderLine = orderLine;
                            orderOperationStatus.Message = "Added " + product.Title + " successfully!";
                        }
                    }
                }

            }

            catch (Exception e)
            {
                orderOperationStatus.LogFailedOperation(e, "An error has occurred adding the product to the order");
            }
            return orderOperationStatus;
        }