示例#1
0
        public IHttpActionResult CreateShip([FromBody] ShipCreateModel shipToCreate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateShipService();

            service.CreateShip(shipToCreate);
            return(Ok());
        }
示例#2
0
        public void CreateShip(ShipCreateModel shipToCreate)
        {
            var entity = new Ship()
            {
                ShipName         = shipToCreate.ShipName,
                ShipClass        = shipToCreate.ShipClass,
                ShipModel        = shipToCreate.ShipModel,
                ShipManufacturer = shipToCreate.ShipManufacturer,
                ShipHyperdrive   = shipToCreate.ShipHyperdrive,
                ShipLength       = shipToCreate.ShipLength,
                ShipMaxSpeed     = shipToCreate.ShipMaxSpeed,
                ShipPrice        = shipToCreate.ShipPrice
            };

            _ctx.Ships.Add(entity);
            _ctx.SaveChanges();
        }
        public ActionResult 出貨單建立(ShipCreateModel ShipList)
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();

            if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] != null)
            {
                tEmployee employee = Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] as tEmployee;
                tShipList Shiplist = new tShipList();
                Shiplist.sEmployeeId      = employee.EmployeeId;
                Shiplist.sShipSerialValue = ShipList.sShipSerialValue;
                Shiplist.sOrderId         = ShipList.SelectOrder;
                Shiplist.sShipDate        = ShipList.sShipDate;
                Shiplist.sShipNote        = ShipList.sShipNote;
                dbContext.tShipLists.Add(Shiplist);
                dbContext.SaveChanges();
                for (int i = 0; i < ShipList.WareHouseId.Count; i++)
                {
                    if (ShipList.ShipProductQty[i] != 0)
                    {
                        tShipDetail tShipdetail = new tShipDetail();
                        tShipdetail.ShipId           = dbContext.tShipLists.OrderByDescending(s => s.ShipId).First().ShipId;
                        tShipdetail.sOrderDetailId   = ShipList.OrderDetailId[i];
                        tShipdetail.sProductId       = ShipList.ProductId[i];
                        tShipdetail.sQuantity        = ShipList.ShipProductQty[i];
                        tShipdetail.sWarehouseNameId = ShipList.WareHouseId[i];
                        dbContext.tShipDetails.Add(tShipdetail);
                        //倉儲變動
                        tWarehouse Warehouse = dbContext.tWarehouses.Where(w => w.WarehouseNameId == tShipdetail.sWarehouseNameId && w.wProductId == tShipdetail.sProductId).FirstOrDefault();
                        if (Warehouse != null)
                        {
                            Warehouse.wPQty -= ShipList.ShipProductQty[i];
                        }
                    }
                }
                tOrder order = dbContext.tOrders.Where(o => o.OrderId == Shiplist.sOrderId).FirstOrDefault();
                order.oDeliverDate = ShipList.sShipDate;
                dbContext.SaveChanges();
            }
            return(RedirectToAction("出貨單查詢"));
        }