Ejemplo n.º 1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 public void Dispose()
 {
     _db.Dispose();
 }