コード例 #1
0
        public bool Order(OrderDeskInfo orderDesk, List <OrderMenuInfo> lOrderMenu)
        {
            DateTime dtOperDate = DateTime.Now;
            Guid     userId     = Guid.Empty;

            try
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    if (!orderDesk.UserId.HasValue)
                    {
                        throw new WebFaultException <string>("无“" + orderDesk.UserName + "”操作员信息", HttpStatusCode.MethodNotAllowed);
                    }
                    userId = orderDesk.UserId.Value;

                    DXInfo.Models.OrderDishes orderDish = uow.OrderDishes.GetById(g => g.Id == orderDesk.OrderDishId);

                    if (orderDish == null)
                    {
                        throw new WebFaultException <string>("无此订单", HttpStatusCode.MethodNotAllowed);
                    }
                    if (orderDish.Status == 1 || orderDish.Status == 2)
                    {
                        throw new WebFaultException <string>("已结账或撤销的不能提交", HttpStatusCode.MethodNotAllowed);
                    }
                    foreach (OrderMenuInfo omi in lOrderMenu)
                    {
                        int lackCount = (from d in uow.MenuStatus.GetAll()
                                         where d.Dept == localDeptId && d.Inventory == omi.InvId &&
                                         d.Status == (int)DXInfo.Models.OrderMenuStatus.Lack
                                         select d).Count();
                        if (lackCount > 0)
                        {
                            throw new WebFaultException <string>(omi.InvName + "缺菜不能提交", HttpStatusCode.MethodNotAllowed);
                        }

                        if (omi.IsAdd && !omi.OrderMenuId.HasValue)
                        {
                            DXInfo.Models.OrderMenus orderMenu = new DXInfo.Models.OrderMenus();
                            orderMenu.UserId      = userId;
                            orderMenu.OrderId     = orderDesk.OrderDishId.Value;
                            orderMenu.InventoryId = omi.InvId;
                            orderMenu.Price       = omi.SalePrice;
                            orderMenu.Quantity    = omi.Quantity;
                            orderMenu.Amount      = omi.Amount;
                            orderMenu.Comment     = omi.Comment;
                            orderMenu.CreateDate  = dtOperDate;
                            orderMenu.IsPackage   = omi.IsPackage;
                            orderMenu.PackageId   = omi.PackageId;
                            orderMenu.PackageSn   = omi.PackageSn;
                            orderMenu.Status      = (int)DXInfo.Models.OrderMenuStatus.Normal;
                            uow.OrderMenus.Add(orderMenu);
                            uow.Commit();

                            DXInfo.Models.OrderMenusHis omHis = Mapper.Map <DXInfo.Models.OrderMenusHis>(orderMenu);
                            omHis.LinkId = orderMenu.Id;
                            uow.OrderMenusHis.Add(omHis);
                        }
                        else
                        {
                            if (omi.OrderMenuId.HasValue)
                            {
                                DXInfo.Models.OrderMenus orderMenu =
                                    (from d in uow.OrderMenus.GetAll()
                                     where d.Id == omi.OrderMenuId select d)
                                    .FirstOrDefault();

                                if (orderMenu != null && orderMenu.Status == (int)DXInfo.Models.OrderMenuStatus.Normal)
                                {
                                    if (omi.IsDelete)
                                    {
                                        uow.OrderMenus.Delete(orderMenu);
                                    }
                                    else
                                    {
                                        orderMenu.Quantity = omi.Quantity;
                                        orderMenu.Price    = omi.SalePrice;
                                        orderMenu.Amount   = omi.Amount;
                                        orderMenu.Comment  = omi.Comment;
                                        uow.OrderMenus.Update(orderMenu);
                                    }
                                    DXInfo.Models.OrderMenusHis omHis = Mapper.Map <DXInfo.Models.OrderMenusHis>(orderMenu);
                                    omHis.LinkId     = orderMenu.Id;
                                    omHis.UserId     = userId;
                                    omHis.CreateDate = dtOperDate;
                                    uow.OrderMenusHis.Add(omHis);
                                }
                            }
                        }
                    }
                    uow.Commit();
                    transaction.Complete();
                }
            }
            catch (Exception ex)
            {
                throw new WebFaultException <string>(ex.Message, HttpStatusCode.MethodNotAllowed);
            }
            return(true);
        }
コード例 #2
0
 public OrderInfo()
 {
     OrderDesk  = new OrderDeskInfo();
     lOrderMenu = new List <OrderMenuInfo>();
     lLackMenu  = new List <DXInfo.Models.MenuStatus>();
 }