コード例 #1
0
        public async Task EditAsync(T model, bool saved = true)
        {
            _db.Configuration.ValidateOnSaveEnabled = false;//关掉自动校验(ValidateOnSaveEnabled)
            _db.Entry(model).State = EntityState.Modified;
            if (saved)
            {
                await _db.SaveChangesAsync();

                _db.Configuration.ValidateOnSaveEnabled = true;
            }
        }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "ClientId,FirstName,LastName,Phone,PickupAddress,ItemDescription,ItemQuantity,FullName,ReceiverPhone,ReceiverAddress")] Client client)
 {
     if (ModelState.IsValid)
     {
         db.Entry(client).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(client));
 }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "AdminId,Name,Email,Username,Password,ConfirmPassword,Phone,Address")] Admin admin)
 {
     if (ModelState.IsValid)
     {
         db.Entry(admin).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(admin));
 }
コード例 #4
0
 public ActionResult Edit([Bind(Include = "PackageId,TrackingId,PackageStatus,ClientId")] Package package)
 {
     if (ModelState.IsValid)
     {
         db.Entry(package).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ClientId = new SelectList(db.ClientTable, "ClientId", "FirstName", package.ClientId);
     return(View(package));
 }
コード例 #5
0
        public async Task <ActionResult> Edit([Bind(Include = "CustomerID,Name,Budget,Cargo,OrderDate,DriverID")] Customers customers)
        {
            if (ModelState.IsValid)
            {
                db.Entry(customers).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.DriverID = new SelectList(db.Drivers, "ID", "FullName", customers.DriverID);
            return(View(customers));
        }
コード例 #6
0
        public async Task <ActionResult> Edit([Bind(Include = "ID,CustomerID,DriverID,DeparturePoint,ArrivalPoint,Distance,DepartureDate,ArrivalDate")] Logistics logistics)
        {
            if (ModelState.IsValid)
            {
                db.Entry(logistics).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "Name", logistics.CustomerID);
            ViewBag.DriverID   = new SelectList(db.Drivers, "ID", "FullName", logistics.DriverID);
            return(View(logistics));
        }
コード例 #7
0
        /// <summary>
        /// 生成运货单
        /// </summary>
        /// <param name="code">货物id</param>
        /// <param name="truckId">卡车id</param>
        /// <returns></returns>
        public async Task <bool> ToWayBill(string code, Guid truckId)
        {
            //查询状态是否正确--->修改订单中的状态--->生成waybill--->生成waybillLink
            bool  flag = true;
            Order order;

            using (var orderservice = new OrderService())
            {
                order = orderservice.GetAll().Where(p => p.BarCode == code).FirstOrDefault();
                if (order == null || order.Status != "2")
                {
                    flag = false;
                }
            }

            if (flag)
            {
                var context = new LogisticsContext();

                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        //修改订单的状态
                        order.Status = "3";
                        context.Entry(order).State = EntityState.Modified;
                        await context.SaveChangesAsync();

                        //创建waybill
                        WayBill wayBill = new WayBill()
                        {
                            FinishTime = DateTime.Now,
                            PlanPath   = "NULL"
                        };
                        context.Set <WayBill>().Add(wayBill);
                        await context.SaveChangesAsync();

                        //创建truck waybill联系
                        WaybillTransportLink transportLink = new WaybillTransportLink()
                        {
                            TransportInfoId = truckId,
                            WayBillId       = wayBill.Id
                        };
                        context.Set <WaybillTransportLink>().Add(transportLink);
                        await context.SaveChangesAsync();

                        //创建order waybill联系
                        OrderWaybillLink orderWaybillLink = new OrderWaybillLink()
                        {
                            OrderId   = order.Id,
                            WaybillId = wayBill.Id
                        };
                        context.Set <OrderWaybillLink>().Add(orderWaybillLink);
                        await context.SaveChangesAsync();

                        transaction.Commit();
                    }
                    catch (Exception errer)
                    {
                        transaction.Rollback();
                        flag = false;
                        throw errer;
                    }
                    finally
                    {
                        context.Dispose();
                    }
                }
            }

            return(flag);
        }