示例#1
0
        public void DeleteProductFromSession(int productId)
        {
            List <SessionProduct> sessionProducts = (List <SessionProduct>)Session["Products"];
            SessionProduct        s = sessionProducts.Where(x => x.productId == productId).FirstOrDefault();

            sessionProducts.Remove(s);
        }
示例#2
0
        public void AddToQuantityProduct(int productId)
        {
            List <SessionProduct> sessionProducts = (List <SessionProduct>)Session["Products"];
            SessionProduct        s = sessionProducts.Where(x => x.productId == productId).FirstOrDefault();

            s.quantity += 1;
        }
示例#3
0
        public void UpdateBasketQuantity(int productId, int quantity)
        {
            List <SessionProduct> sessionProducts = (List <SessionProduct>)Session["Products"];
            SessionProduct        s = sessionProducts.Where(x => x.productId == productId).FirstOrDefault();

            s.quantity = quantity;
        }
示例#4
0
        /// <summary>
        /// Log the products associated with this scenario.
        /// </summary>
        public void LogAssociatedProducts()
        {
            using (var enterpriseTestContext = new EnterpriseTestContext())
            {
                using (var dataLogContext = DbConnect.DataLogContext())
                {
                    TraceFactory.Logger.Debug($"Inserting {Ticket.AssociatedProductList.Count} products used in scenario.");
                    foreach (var ap in Ticket.AssociatedProductList)
                    {
                        if (ap.Active)
                        {
                            if (string.IsNullOrWhiteSpace(ap.Version))
                            {
                                TraceFactory.Logger.Debug($"Skipping insert of version information for {ap.Vendor} {ap.Name}.  No version was provided.");
                            }
                            else
                            {
                                string msg = $"associated product version '{ap.Vendor} {ap.Name} {ap.Version}' for session {Ticket.SessionId}...(AssociatedProductId: {ap.AssociatedProductId})";

                                if (dataLogContext.DbSessionProducts.Any(rec => rec.EnterpriseTestAssociatedProductId == (Guid)ap.AssociatedProductId && rec.SessionId == Ticket.SessionId))
                                {
                                    TraceFactory.Logger.Debug($"Skipping...User entered information twice for {msg}");
                                }
                                else
                                {
                                    try
                                    {
                                        TraceFactory.Logger.Debug($"Adding {msg}");
                                        TraceFactory.Logger.Debug($"Session:{Ticket.SessionId}, {ap.AssociatedProductId}, {ap.Version}, {ap.Name}, {ap.Vendor}");
                                        SessionProduct sessionProduct = new SessionProduct
                                        {
                                            SessionId = Ticket.SessionId,
                                            EnterpriseTestAssociatedProductId = ap.AssociatedProductId,
                                            Version = ap.Version,
                                            Name    = ap.Name,
                                            Vendor  = ap.Vendor
                                        };
                                        dataLogContext.DbSessionProducts.Add(sessionProduct);
                                        int rowCount = dataLogContext.SaveChanges();
                                        TraceFactory.Logger.Debug($"Database reports {rowCount} records inserted.");
                                    }
                                    catch (Exception x)
                                    {
                                        string msg2 = $"Could not add {msg}";
                                        TraceFactory.Logger.Debug(msg2);
                                        throw new DataException(msg2, x);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#5
0
        public void AddToBasket(int productId, int quantity)
        {
            List <SessionProduct> products = (List <SessionProduct>)Session["Products"];

            if (products.Exists(x => x.productId == productId))
            {
                SessionProduct s = products.Where(x => x.productId == productId).FirstOrDefault();
                s.quantity += quantity;
            }

            else
            {
                SessionProduct product = new SessionProduct(productId, quantity);
                products.Add(product);
            }
        }
示例#6
0
        private void add_Button_Click(object sender, EventArgs e)
        {
            if (addNewProduct_ComboBox.SelectedValue != null)
            {
                try
                {
                    string product = (string)addNewProduct_ComboBox.SelectedValue;

                    SessionProduct template = _dataLogContext.DbSessionProducts.Where(x => x.Name == product && _sessionSummary.SessionId == x.SessionId).FirstOrDefault();
                    if (template == null)
                    {
                        template = _dataLogContext.DbSessionProducts.Where(x => x.Name == product).FirstOrDefault();
                        SessionProduct sessionProduct = new SessionProduct();
                        sessionProduct.SessionId = _sessionSummary.SessionId;
                        sessionProduct.EnterpriseTestAssociatedProductId = template.EnterpriseTestAssociatedProductId;
                        sessionProduct.Name      = template.Name;
                        sessionProduct.Vendor    = template.Vendor;
                        sessionProduct.Version   = string.Empty;
                        sessionProduct.IsDeleted = false;

                        _dataLogContext.DbSessionProducts.Add(sessionProduct);
                    }
                    else
                    {
                        template.IsDeleted = false;
                        template.Version   = string.Empty;
                        _dataLogContext.Entry(template).Property("IsDeleted").IsModified = true;
                    }


                    _dataLogContext.SaveChanges();
                    RefreshDataGrid();
                }
                catch
                {
                    MessageBox.Show("Failed to add the Product", "Product Add Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }