Ejemplo n.º 1
0
        public string SaveOrderAsChangeOrder(Guid userId, Guid cartId)
        {
            try
            {
                PurchaseOrder po = GetPurchaseOrder(userId, cartId);

                PipelineHelper pipeLineHelper = new PipelineHelper(Extensions.SiteHelper.GetSiteName());
                pipeLineHelper.RunPipeline(og: po,
                                           transacted: true,
                                           loggingEnabled: Configuration.EnableLoggingPipeline,
                                           pipelineName: "Checkout",
                                           pipelinePath: string.Format
                                               ("{0}\\pipelines\\checkout.pcf",
                                               HttpContext.Current.Server.MapPath(".")));

                po.TrackingNumber = GetNextControlNumber();
                po.Status         = "Submitted";
                po.Save();

                return(po.TrackingNumber);
            }
            catch (Exception ex)
            {
                EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl(applicationNameForLogging);
                eventLog.WriteErrorLog("Error in SaveOrderAsChangeOrder: ", ex);

                throw ex;
            }
        }
Ejemplo n.º 2
0
        public void CleanUpChangeOrder(Guid userId, Guid cartId)
        {
            try {
                PurchaseOrder po = GetPurchaseOrder(userId, cartId);

                List <LineItem> lineItemIndexesToRemove = new List <LineItem>();

                foreach (LineItem li in po.OrderForms[0].LineItems)
                {
                    if (li.Status == "deleted")
                    {
                        lineItemIndexesToRemove.Add(li);
                    }
                    li.Status = string.Empty;
                }

                foreach (LineItem item in lineItemIndexesToRemove)
                {
                    po.OrderForms[0].LineItems.Remove(item);
                }

                po.Save();
            } catch (Exception ex) {
                EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl(applicationNameForLogging);
                eventLog.WriteErrorLog("Error in CleanUpChangeOrder: ", ex);

                throw ex;
            }
        }
Ejemplo n.º 3
0
        public string SaveCartAsOrder(Guid userId, Guid cartId)
        {
            try
            {
                var context = Extensions.SiteHelper.GetOrderContext();

                var basket = context.GetBasket(userId, cartId);

                bool reorder = false;
                foreach (LineItem lineItem in basket.OrderForms[0].LineItems)
                {
                    if (lineItem["LinePosition"] == null)
                    {
                        reorder = true;
                    }
                    else
                    {
                        if (lineItem["LinePosition"].Equals("0"))
                        {
                            reorder = true;
                        }
                    }
                }
                if (reorder)
                {
                    EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl(applicationNameForLogging);
                    eventLog.WriteInformationLog("SaveCartAsOrder : reorder");
                    int startIndex = 1; // main frame needs lineposition to not be null
                    foreach (LineItem lineItem in basket.OrderForms[0].LineItems)
                    {
                        lineItem["LinePosition"] = startIndex;
                        startIndex++;
                    }
                }

                PipelineHelper pipeLineHelper = new PipelineHelper(Extensions.SiteHelper.GetSiteName());
                pipeLineHelper.RunPipeline(og: basket,
                                           transacted: true,
                                           loggingEnabled: Configuration.EnableLoggingPipeline,
                                           pipelineName: "Checkout",
                                           pipelinePath: string.Format
                                               ("{0}\\pipelines\\checkout.pcf",
                                               HttpContext.Current.Server.MapPath(".")));

                basket.TrackingNumber         = GetNextControlNumber();
                basket["OriginalOrderNumber"] = basket.TrackingNumber;
                var purchaseOrder = basket.SaveAsOrder();

                return(purchaseOrder.TrackingNumber);
            }
            catch (Exception ex)
            {
                EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl(applicationNameForLogging);
                eventLog.WriteErrorLog("Error in SaveCartAsOrder: ", ex);

                throw ex;
            }
        }
Ejemplo n.º 4
0
        private static PurchaseOrder GetPurchaseOrder(Guid userId, Guid cartId)
        {
            try {
                CommerceServer.Core.Runtime.Orders.OrderContext context = Extensions.SiteHelper.GetOrderContext();
                return(context.GetPurchaseOrder(userId, cartId));
            } catch (Exception ex) {
                EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl(applicationNameForLogging);
                eventLog.WriteErrorLog("Error in GetPurchaseOrder: ", ex);

                throw ex;
            }
        }
Ejemplo n.º 5
0
            public void GoodErrorLogNoException_CallsPublishToQueue()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);

                // act
                log.WriteErrorLog("test");

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.IsAny <LogMessage>()), Times.Once, "Not called with expected LogMessage");
            }
Ejemplo n.º 6
0
        public void UpdatePurchaseOrderStatus(Guid userId, Guid orderId, string status)
        {
            try {
                var context = Extensions.SiteHelper.GetOrderContext();
                var po      = context.GetPurchaseOrder(userId, orderId);
                //CommerceServer.Core.Runtime.Orders.PurchaseOrder po = GetPurchaseOrder(userId, orderId);
                po.Status = status;
                po.Save();
            } catch (Exception ex) {
                EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl(applicationNameForLogging);
                eventLog.WriteErrorLog("Error Updating Purchase Order Status: ", ex);

                throw;
            }
        }
Ejemplo n.º 7
0
        public string CancelPurchaseOrder(Guid userId, Guid orderId)
        {
            try {
                CommerceServer.Core.Runtime.Orders.PurchaseOrder po = GetPurchaseOrder(userId, orderId);
                po.Status         = "Cancelled";
                po.TrackingNumber = GetNextControlNumber();
                po.Save();
                return(po.TrackingNumber);
            } catch (Exception ex) {
                EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl(applicationNameForLogging);
                eventLog.WriteErrorLog("Error in CancelPurchaseOrder: ", ex);

                throw ex;
            }
        }
Ejemplo n.º 8
0
            public void GoodErrorLog_CallsPublishToQueueAndSetsMachineName()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                var exception = MakeException();

                // act
                log.WriteErrorLog("Oops!", exception);

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.Machine.Name.Length > 0)),
                        Times.Once(),
                        "Machine name did not get set");
            }
Ejemplo n.º 9
0
            public void GoodErrorLog_CallsPublishToQueueAndSetsStackTrace()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                var exception = MakeException();

                // act
                log.WriteErrorLog("Ooops!", exception);

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.Exception.StackTrace.Length > 0)),
                        Times.Once,
                        "StackTrace is not being set");
            }
Ejemplo n.º 10
0
            public void GoodErrorLog_CallsPublishToQueueWithExceptionMessage()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                string expected = "Something went wrong!";

                // act
                log.WriteErrorLog(expected, MakeException());

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.Message.Equals(expected))),
                        Times.Once,
                        "Message did not match");
            }
Ejemplo n.º 11
0
            public void GoodErrorLogNoException_HasProperEnvironment()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                var expected = ConfigurationHelper.GetActiveConfiguration();

                // act
                log.WriteErrorLog("test");

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.Application.Environment.Equals(expected))),
                        Times.Once,
                        "Application Environment not set properly");
            }
Ejemplo n.º 12
0
            public void GoodErrorLogNoException_HasApplicationName()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                var expected = ConfigurationManager.AppSettings["AppName"];

                // act
                log.WriteErrorLog("test");

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.Application.Name.Equals(expected))),
                        Times.Once,
                        "Application Name not set properly");
            }
Ejemplo n.º 13
0
            public void GoodErrorLogNoException_HasMachineName()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                var expected = Environment.MachineName;

                // act
                log.WriteErrorLog("test");

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.Machine.Name.Equals(expected))),
                        Times.Once,
                        "Machine.Name not set properly");
            }
Ejemplo n.º 14
0
            public void GoodErrorLogNoException_HasProperSeverity()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                var expected = 3;

                // act
                log.WriteErrorLog("test");

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.EntryType.Id.Equals(expected))),
                        Times.Once,
                        "Severity level not set properly");
            }
Ejemplo n.º 15
0
            public void GoodErrorLog_HasTheProperSeverity()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                var exception        = MakeException();
                var expectedSeverity = 3;

                // act
                log.WriteErrorLog("Oops!", exception);

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.EntryType.Id.Equals(expectedSeverity))),
                        Times.Once(),
                        "Severity level not set to information");
            }
Ejemplo n.º 16
0
        private static string GetNextControlNumber()
        {
            try {
                string controlNumber = string.Empty;
                // get tracking number from DB
                using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["BEKDBContext"].ConnectionString)) {
                    using (SqlCommand cmd = new SqlCommand("Orders.usp_GetNextControlNumber", conn)) {
                        cmd.CommandType = CommandType.StoredProcedure;
                        SqlParameter parm = new SqlParameter();
                        parm.Direction = ParameterDirection.ReturnValue;
                        cmd.Parameters.Add(parm);
                        conn.Open();
                        cmd.ExecuteNonQuery();
                        controlNumber = (int.Parse(cmd.Parameters[0].Value.ToString())).ToString("0000000.##"); // format to main frame of 7 digits
                    }
                }
                return(controlNumber);
            } catch (Exception ex) {
                EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl(applicationNameForLogging);
                eventLog.WriteErrorLog("Error in GetNextControlNumber: ", ex);

                throw ex;
            }
        }
Ejemplo n.º 17
0
        public string UpdatePurchaseOrder(Guid userId, Guid orderId, string requestedShipDate, List <PurchaseOrderLineItemUpdate> lineItemUpdates)
        {
            try
            {
                CommerceServer.Core.Runtime.Orders.PurchaseOrder po        = GetPurchaseOrder(userId, orderId);
                CommerceServer.Core.Runtime.Orders.LineItem[]    lineItems = new CommerceServer.Core.Runtime.Orders.LineItem[po.OrderForms[0].LineItems.Count];
                po.OrderForms[0].LineItems.CopyTo(lineItems, 0);
                po["RequestedShipDate"] = requestedShipDate;

                foreach (PurchaseOrderLineItemUpdate i in lineItemUpdates)
                {
                    CommerceServer.Core.Runtime.Orders.LineItem lineItem = lineItems.Where(x => x.ProductId == i.ItemNumber).FirstOrDefault();
                    // find existing item based on item number
                    if (i.Status == "changed" && lineItem != null)
                    {
                        lineItem.Quantity       = i.Quantity;
                        lineItem["Each"]        = i.Each;
                        lineItem["CatchWeight"] = i.CatchWeight;
                        lineItem.Status         = "changed";
                    }
                    if (i.Status == "deleted" && lineItem != null)
                    {
                        lineItem.Status = "deleted";
                    }
                    if (i.Status == "added" && lineItem == null)
                    {
                        CommerceServer.Core.Runtime.Orders.LineItem li = new CommerceServer.Core.Runtime.Orders.LineItem()
                        {
                            ProductId = i.ItemNumber, Quantity = i.Quantity, Status = "added"
                        };
                        li["CatchWeight"]  = i.CatchWeight;
                        li["Each"]         = i.Each;
                        li["Notes"]        = string.Empty;
                        li.ProductCatalog  = i.Catalog;
                        li.Status          = "added";
                        li["LinePosition"] = po.OrderForms[0].LineItems.Count + 1;
                        po.OrderForms[0].LineItems.Add(li);
                    }
                    if (i.Status == "added" && lineItem != null)
                    {
                        lineItem.Quantity       = i.Quantity;
                        lineItem["Each"]        = i.Each;
                        lineItem["CatchWeight"] = i.CatchWeight;
                    }
                }

                if (po.Status.StartsWith("confirmed", StringComparison.InvariantCultureIgnoreCase))
                {
                    po.Status = "Confirmed with un-submitted changes";
                }

                PipelineHelper pipeLineHelper = new PipelineHelper(Extensions.SiteHelper.GetSiteName());
                pipeLineHelper.RunPipeline(og: po,
                                           transacted: true,
                                           loggingEnabled: false,
                                           pipelineName: "Checkout",
                                           pipelinePath: string.Format
                                               ("{0}\\pipelines\\checkout.pcf",
                                               HttpContext.Current.Server.MapPath(".")));

                po.Save();
                return(po.TrackingNumber);
            }
            catch (Exception ex)
            {
                EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl(applicationNameForLogging);
                eventLog.WriteErrorLog("Error in UpdatePurchaseOrder: ", ex);

                throw ex;
            }
        }