Beispiel #1
0
        public bool Put(OrderModel model)
        {
            var entity = _OrderService.GetOrderById(model.Id);
            if (entity == null)
                return false;

            entity.OrderNum = model.OrderNum;

            entity.TotalPrice = model.TotalPrice;

            entity.TransCost = model.TransCost;

            entity.ProductCost = model.ProductCost;

            entity.Discount = model.Discount;

            entity.Status = model.Status;

            entity.DeliveryAddress = model.DeliveryAddress;

            entity.IsPrint = model.IsPrint;

            entity.PhoneNumber = model.PhoneNumber;

            entity.Upduser = (UserBase)_workContext.CurrentUser;

            entity.Updtime = DateTime.Now;

            //			entity.Details = model.Details;

            //			entity.Coupon = model.Coupon;

            entity.Type = model.Type;

            entity.PayType = model.PayType;

            entity.LocationX = model.LocationX;

            entity.LocationY = model.LocationY;

            if (_OrderService.Update(entity) != null)
                return true;
            return false;
        }
Beispiel #2
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;
        }
Beispiel #3
0
        public HttpResponseMessage Get(int id)
        {
            var entity = _OrderService.GetOrderById(id);
            var model = 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
                }).ToList()

            };
            return PageHelper.toJson(new { List = model });
        }