Exemplo n.º 1
0
        public async Task <IActionResult> Create2(OrderCreate2ViewModel vm2)
        {
            IEnumerable <Product> productList = _productDataService.Query(p => p.CategoryId == vm2.CategoryId);
            // Get the user Id
            IdentityUser u = await _userManagerService.FindByNameAsync(User.Identity.Name);

            Order o = new Order
            {
                CategoryId   = vm2.CategoryId,
                OrderStateId = 1,
                Date         = System.DateTime.Now,
                BranchId     = 1,
                UserCreateId = u.Id
            };

            _orderDataService.Create(o);

            foreach (string key in HttpContext.Request.Form.Keys)
            {
                string field = key;
                string s     = HttpContext.Request.Form[key];
                if (s == ",,")
                {
                    //Go new iteration
                }
                else if (field == "CategoryId" || field == "__RequestVerificationToken")
                {
                    //Go new iteration
                }
                else
                {
                    var    ss       = s.Split(',').Select(x => int.Parse(x)).Take(2).ToArray();
                    int    Stock    = ss[0];
                    int    Cantidad = ss[1];
                    string Obs      = s.Split(',').Select(x => x).Last();

                    if (Cantidad <= 0)
                    {
                        //Go new iteration
                    }
                    else
                    {
                        int         fieldInt = Convert.ToInt32(key);
                        OrderDetail od       = new OrderDetail
                        {
                            OrderId     = o.OrderId,
                            SubCategory = 1,
                            Category    = vm2.CategoryId,
                            Quantity    = Cantidad,
                            ProductId   = fieldInt,
                            Stock       = Stock,
                            ObsOrder    = Obs
                        };
                        _orderDetailDataService.Create(od);
                    }
                }
            }
            return(RedirectToAction("Index", "Order"));
        }
Exemplo n.º 2
0
        public IActionResult Create2(int id)
        {
            IEnumerable <Product> productList = _productDataService.Query(p => p.CategoryId == id).OrderBy(s => s.SubCategoryId);
            //     IEnumerable<Product> productList = _productDataService.Query(p => p.CategoryId == id);
            Category category = _categoryDataService.GetSingle(c => c.CategoryId == id);
            IEnumerable <SubCategory> subCategoryiesList = _subCategoryDataService.Query(s => s.CategoryId == id);
            OrderCreate2ViewModel     vm2 = new OrderCreate2ViewModel
            {
                Products      = productList,
                Total         = productList.Count(),
                Category      = category.Name,
                CategoryId    = id,
                Subcategories = subCategoryiesList
            };

            return(View(vm2));
        }