예제 #1
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;
        }
예제 #2
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;
 }
예제 #3
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;
        }
예제 #4
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);
        }
예제 #5
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;
        }
예제 #6
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;
        }
예제 #7
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;
        }
예제 #8
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;
        }