Exemplo n.º 1
0
        public void GetByPKTest()
        {
            OrderLineOption entity = Dao.OrderLineOption.GetByPK(1, 4); // OrderLineID, OptionID

            Assert.AreEqual(1, entity.OrderLineID);
            Assert.AreEqual(4, entity.OptionID);
        }
Exemplo n.º 2
0
        private void btnCheckOut_Click(object sender, EventArgs e)
        {
            var gridViewInformation = Dao.OrderLineOption.Search(Dao.Order.GetMaxKey());

            List <OrderLineOption> wantedList = new List <OrderLineOption>();

            foreach (var item in gridViewInformation)
            {
                OrderLineOption information = new OrderLineOption();
                information.OptionName = item.Option.Name;
                information.MenuName   = item.OrderLine.Menu.Name;
                information.MenuPrice  = item.OrderLine.Menu.Price;

                wantedList.Add(information);
            }
            bdsOrderLineOption.DataSource = wantedList;
        }
Exemplo n.º 3
0
        private void show()
        {
            var gridViewInformation = Dao.OrderLineOption.Search(Dao.Order.GetMaxKey()); //변수

            List <OrderLineOption> wantedList = new List <OrderLineOption>();

            foreach (var item in gridViewInformation)
            {
                OrderLineOption information = new OrderLineOption();
                information.OrderId    = item.OrderId;
                information.Quantity   = item.OrderLine.Quantity;
                information.MenuName   = item.OrderLine.Menu.Name;
                information.OptionName = item.Option.Name;
                information.MenuPrice  = item.OrderLine.Menu.Price;
                wantedList.Add(information);
            }
            bdsOrderLineOption.DataSource = wantedList;
        }
Exemplo n.º 4
0
        public void WrongGetByPKTest()
        {
            OrderLineOption entity = Dao.OrderLineOption.GetByPK(1, 10000); // OrderLineID, OptionID

            Assert.IsNull(entity);
        }
Exemplo n.º 5
0
        private ParseOrderLineResult ParseOrderLine(Organisation org, List <string> catalogIds, string orderLinesAsString)
        {
            var olElements = orderLinesAsString.Split(new string[] { " x " }, StringSplitOptions.None).ToList();

            if (olElements.Count != 2)
            {
                return(new ParseOrderLineResult(ParseOrderLineResultState.ParseError));
            }

            string quantityString = olElements[0].Trim();

            decimal quantity = 1;

            if (!decimal.TryParse(quantityString, out quantity))
            {
                return(new ParseOrderLineResult(ParseOrderLineResultState.ParseError));
            }



            string productName       = olElements[1].Trim();
            bool   productHasOptions = false;

            string[] productOptionElements = null;

            if (productName.Contains('?'))
            {
                var productNameElements = productName.Split('?').ToList();

                productName = productNameElements[0].Trim();

                productHasOptions     = true;
                productOptionElements = productNameElements[1].Split('&');
            }

            Product product = _Ctx.Product.FirstOrDefault(p => p.Name == productName && catalogIds.Contains(p.CatalogId));

            if (product == null)
            {
                string msg = string.Format("Product '{0}' not found for line: {1}", productName, orderLinesAsString);
                return(new ParseOrderLineResult(ParseOrderLineResultState.ProductNotFound, msg));
            }

            _Ctx.Entry(product).State = System.Data.Entity.EntityState.Detached;

            OrderLine orderLine = new OrderLine()
            {
                Quantity      = quantity,
                ProductId     = product.Id,
                Product       = product,
                PlanningOrder = product.PlanningOrder
            };

            if (productHasOptions)
            {
                orderLine.OrderLineOptions = new List <OrderLineOption>();

                for (int i = 0; i < productOptionElements.Length; i++)
                {
                    string optionString   = productOptionElements[i].Trim();
                    var    optionElements = optionString.Split('=');

                    string optionCode  = optionElements[0].Trim();
                    string optionValue = optionElements[1].Trim();

                    if (optionCode.ToLower() == "persons")
                    {
                        orderLine.Persons = optionValue;
                        continue;
                    }

                    ProductOption option = _Ctx.ProductOption.FirstOrDefault(po => po.Code == optionCode && po.OrganisationId == org.Id);

                    if (option == null)
                    {
                        string msg = string.Format("Product option '{0}' not found for line: {1}", optionCode, orderLinesAsString);
                        return(new ParseOrderLineResult(ParseOrderLineResultState.ProductOptionNotFound, msg));
                    }

                    /*
                     * OrderLineOption olOption = new OrderLineOption()
                     * {
                     *  ProductOptionId = option.Id
                     * };*/

                    OrderLineOption olOption = OrderLineOption.CreateNew();
                    olOption.ProductOptionId = option.Id;

                    if (option.HasValueObjects)
                    {
                        ProductOptionValue value = _Ctx.ProductOptionValue.FirstOrDefault(v => v.ProductOptionId == option.Id && v.Code == optionValue);

                        if (value != null)
                        {
                            olOption.ProductOptionValueId = value.Id;
                        }
                        else
                        {
                            throw new ApplicationException(string.Format("Product option value not found: {0}!", optionValue));
                        }
                    }
                    else
                    {
                        decimal optionNumValue = 0;

                        if (!decimal.TryParse(optionValue, out optionNumValue))
                        {
                            string msg = string.Format("Could not parse value '{0}' for option '{1}' for line: {2}", optionValue, optionCode, orderLinesAsString);
                            return(new ParseOrderLineResult(ParseOrderLineResultState.InvalidProductOptionValue));
                        }

                        olOption.ProductOptionValue = optionNumValue;
                    }

                    orderLine.OrderLineOptions.Add(olOption);
                }
            }

            return(new ParseOrderLineResult(orderLine));
        }