示例#1
0
 public OrderEntity Create(OrderEntity entity)
 {
     try
     {
         _orderRepository.Insert(entity);
         return entity;
     }
     catch (Exception e)
     {
         _log.Error(e,"数据库操作出错");
         return null;
     }
 }
示例#2
0
 public bool Delete(OrderEntity entity)
 {
     try
     {
         entity.Status = EnumOrderStatus.Canceled;
         _orderRepository.Update(entity);
         return true;
     }
     catch (Exception e)
     {
         _log.Error(e,"数据库操作出错");
         return false;
     }
 }
示例#3
0
        public OrderModel CreateOrder([FromBody]CreateOrderModel model)
        {
            var OrderEntity = new OrderEntity
            {
                TotalPrice=model.TotalPrice,

                OrderNum = GetNewOrderNum(),

                TransCost = GetTransCost(model.LocationX, model.LocationY),           //Todo:use db data

                //Discount = model.Discount,          //Todo:use db data

                Status = EnumOrderStatus.Created,

                DeliveryAddress = model.DeliveryAddress,

                IsPrint = false,

                PhoneNumber = model.PhoneNumber,

                Adduser = model.Type == EnumOrderType.OffLine ? _userService.GetUserByName("admin") : (UserBase)_workContext.CurrentUser,

                Addtime = DateTime.Now,

                Upduser = model.Type == EnumOrderType.OffLine ? _userService.GetUserByName("admin") : (UserBase)_workContext.CurrentUser,

                Updtime = DateTime.Now,

                //				Details = model.Details,

                //				Coupon = model.Coupon,

                Type = model.Type,

                PayType = model.PayType,

                LocationX = model.LocationX,

                LocationY = model.LocationY,

            };
            #region ��ϸ
            var details = (from detail in model.Details
                           let product = _productService.GetProductById(detail.ProductId)
                           where product != null
                           select new OrderDetailEntity
                           {
                               Count = detail.Count,
                               Product = _productService.GetProductById(detail.ProductId),
                               TotalPrice = detail.Count * product.Price,
                               Order = OrderEntity,
                               Remark = detail.Remark
                           }).ToList();

            OrderEntity.ProductCost = details.Sum(d => d.TotalPrice);
            OrderEntity.TotalPrice = OrderEntity.ProductCost - OrderEntity.Discount + OrderEntity.TransCost;
            OrderEntity.Details = details;
            #endregion
            var OETemp = _OrderService.Create(OrderEntity);
            var entity = _OrderService.GetOrderById(OETemp.Id);
            var oe = new OrderModel
            {

                Id = entity.Id,

                OrderNum = entity.OrderNum,

                TotalPrice = entity.TotalPrice,

                TransCost = entity.TransCost,

                ProductCost = entity.ProductCost,

                Discount = entity.Discount,

                Status = entity.Status,

                DeliveryAddress = entity.DeliveryAddress,

                IsPrint = entity.IsPrint,

                PhoneNumber = entity.PhoneNumber,

                Adduser = new UserModel{Id = entity.Adduser.Id,UserName = entity.Adduser.UserName},

                Addtime = entity.Addtime,

                Upduser = new UserModel { Id = entity.Upduser.Id, UserName = entity.Upduser.UserName },

                Updtime = entity.Updtime,

                //		        Details = entity.Details,

                //		        Coupon = entity.Coupon,

                Type = entity.Type,

                PayType = entity.PayType,

                LocationX = entity.LocationX,

                LocationY = entity.LocationY,

                Details = entity.Details.Select(d => new OrderDetailModel()
                {
                    Count = d.Count,
                    Id = d.Id,
                    ProductId = d.Product.Id,
                    ProductName = d.Product.Name,
                    TotalPrice = d.TotalPrice,
                    UnitPrice = d.Product.Price,
                    Remark = d.Remark
                }).ToList()

            };
            return oe;
        }
示例#4
0
        public bool Post([FromBody]CreateOrderModel model)
        {
            var entity = new OrderEntity
            {

                OrderNum = GetNewOrderNum(),

                TransCost = GetTransCost(model.LocationX, model.LocationY),           //Todo:use db data

                //Discount = model.Discount,          //Todo:use db data

                Status = EnumOrderStatus.Created,

                DeliveryAddress = model.DeliveryAddress,

                IsPrint = false,

                PhoneNumber = model.PhoneNumber,

                Adduser = model.Type == EnumOrderType.OffLine?_userService.GetUserByName("admin"):(UserBase)_workContext.CurrentUser,

                Addtime = DateTime.Now,

                Upduser = model.Type == EnumOrderType.OffLine ? _userService.GetUserByName("admin") : (UserBase)_workContext.CurrentUser,

                Updtime = DateTime.Now,

                //				Details = model.Details,

                //				Coupon = model.Coupon,

                Type = model.Type,

                PayType = model.PayType,

                LocationX = model.LocationX,

                LocationY = model.LocationY,

            };
            #region ��ϸ
            var details = (from detail in model.Details
                           let product = _productService.GetProductById(detail.ProductId)
                           where product != null
                           select new OrderDetailEntity
                           {
                               Count = detail.Count,
                               Product = _productService.GetProductById(detail.ProductId),
                               TotalPrice = detail.Count * product.Price,
                               Order = entity,
                               Remark = detail.Remark
                           }).ToList();

            entity.ProductCost = details.Sum(d => d.TotalPrice);
            entity.TotalPrice = entity.ProductCost - entity.Discount + entity.TransCost;
            entity.Details = details;

            #endregion
            if (_OrderService.Create(entity).Id > 0)
            {
                return true;
            }
            return false;
        }