コード例 #1
0
        public ActionResult Add(PurchaseOrderItem request)
        {
            //check exist ordercarid in table PurchaseOrder

            if (_purchaseOrderDa.CheckExistByOrderCarId(request.OrderCarID))
            {
                return(Json(new JsonMessage()
                {
                    Erros = true, Message = "Đơn hàng đã được nhập vào kho"
                }));
            }

            var order = _orderCarDa.GetById(request.OrderCarID);

            var mode = new PurchaseOrder()
            {
                Quantity    = request.Quantity,
                Weight      = request.Weight,
                OrderCarId  = request.OrderCarID,
                UserCreated = Userid,
                CreateDate  = ConvertDate.TotalSeconds(DateTime.Now),
                Note        = request.Note
            };

            //lay item dua vao kho
            var products = _da.GetItemByOrderCarId(request.OrderCarID);

            List <Cate_Value> lst = new List <Cate_Value>();
            var p = new PurchaseOrder();

            //using (var transaction = new System.Transactions.TransactionScope())
            //{
            _purchaseOrderDa.Add(mode);

            lst.AddRange(products.Select(product => new Cate_Value()
            {
                Quantity        = 1,
                CateID          = order.ProductId,
                Code            = product.Code,
                PriceCost       = product.Quantity * order.Price,
                DateCreated     = ConvertDate.TotalSeconds(DateTime.Now),
                PurchaseOrderId = mode.ID,
                Weight          = product.Quantity,
                PriceUnit       = order.Price,
                IsDelete        = false,
                QuantityOut     = 0,
                Status          = request.ItemID.Any(m => m == product.ID) ? (int)CateValueStatus.Active : (int)CateValueStatus.NoneActive
            }));
            mode.Cate_Value.AddRange(lst);
            _purchaseOrderDa.Save();
            order.Status = (int)OrderCarStatus.Done;
            _orderCarDa.Save();



            //    transaction.Complete();
            //}

            return(Json(new JsonMessage()
            {
                Erros = false
            }));
        }