Пример #1
0
 public void SubmitForm(OrderEntity orderEntity, string keyValue)
 {
     if (!string.IsNullOrEmpty(keyValue))
     {
         orderEntity.F_ArtNo         = orderEntity.F_ArtNo01 + "-" + orderEntity.F_ArtNo02 + "-" + orderEntity.F_ArtNo03;
         orderEntity.F_WaybillNumber = null;
         orderEntity.F_CreatorTime   = null;
         orderEntity.F_CreatorUserId = null;
         orderEntity.F_EnabledMark   = null;
         orderEntity.Modify(keyValue);
         _service.Update(orderEntity);
     }
     else
     {
         orderEntity.Create();
         orderEntity.F_WaybillNumber = DateTime.Now.ToString("yyyyMMddHHmmssfff ");    //+ Common.RndNum(4);
         orderEntity.F_ArtNo         = orderEntity.F_ArtNo01 + "-" + orderEntity.F_ArtNo02 + "-" + orderEntity.F_ArtNo03;
         orderEntity.F_EnabledMark   = true;
         for (int i = orderEntity.OrderProduct.Count - 1; i >= 0; --i)
         {
             OrderProductEntity orderProducts = orderEntity.OrderProduct[i];
             orderProducts.Create();
             orderEntity.OrderProduct[i] = orderProducts;
         }
         _service.Insert(orderEntity);
         _orderQuantityApp.UpdateOrderQuantity();
     }
 }
Пример #2
0
        /// <summary>
        /// 加载产品明细
        /// </summary>
        /// <param name="info"></param>
        protected virtual void FillOrderProductsByProductIds(OrderEntity info)
        {
            if (string.IsNullOrEmpty(hfProducts.Value))
            {
                return;
            }
            var orderProducts = hfProducts.Value.DeserializeJson <List <OrderProductEntity> >();

            if (orderProducts != null)
            {
                foreach (var subOrderProduct in orderProducts)
                {
                    var orderProduct = new OrderProductEntity
                    {
                        Product = new ProductEntity {
                            Id = subOrderProduct.Id
                        },
                        Price       = subOrderProduct.Price,
                        Count       = subOrderProduct.Count,
                        Name        = subOrderProduct.Name,
                        Order       = info,
                        IsReturn    = subOrderProduct.IsReturn,
                        Description = subOrderProduct.Description,
                        Remark      = subOrderProduct.Remark,
                        SaveType    = SaveType.Add
                    };
                    info.OrderProducts.Add(orderProduct);
                }
            }
        }
        private static async Task InsertOrder(Order order)
        {
            var storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("TableStorage"));
            var tableClient    = storageAccount.CreateCloudTableClient();

            var orderEntity = new OrderEntity(order.Customer.Id.ToString(), order.Id.ToString())
            {
                CustomerId  = order.Customer.Id,
                Status      = order.Status,
                CreatedDate = order.CreatedDate,
                UpdatedDate = order.UpdatedDate
            };

            //Insert Order
            var orderTable           = tableClient.GetTableReference("Order");
            var insertOrderOperation = TableOperation.Insert(orderEntity);

            await orderTable.ExecuteAsync(insertOrderOperation);

            //Insert OrderProducts
            foreach (var product in order.Products)
            {
                var orderProductEntity = new OrderProductEntity(order.Id.ToString(), product.Id.ToString())
                {
                };
                var orderProductTable           = tableClient.GetTableReference("OrderProduct");
                var insertOrderProductOperation = TableOperation.Insert(orderProductEntity);

                await orderProductTable.ExecuteAsync(insertOrderProductOperation);
            }
        }
        public async Task <IActionResult> CreateNew([FromBody] ApiV1OrderCreateRequestModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                var userId = loginService.GetLoggedInUserId();

                var orderEntity = new OrderEntity
                {
                    CurrencyId = model.CurrencyId,
                    UserId     = userId
                };

                var orderProductList = new List <OrderProductEntity>();
                var totalPrice       = decimal.Zero;

                foreach (var keyValuePair in model.ProductList)
                {
                    if (!await productService.DoesProductExistByIdAsync(keyValuePair.Key))
                    {
                        logger.LogDebug(
                            $"Failed to add product with id {keyValuePair.Key} to the order. The given Product id doesn't exist at all.");
                        return(BadRequest("The product Id doesn't exist"));
                    }

                    var currentProduct = await productService.GetByIdAsync(keyValuePair.Key);

                    var orderProductEntity = new OrderProductEntity
                    {
                        Amount    = keyValuePair.Value,
                        OrderId   = orderEntity.Id,
                        ProductId = currentProduct.Id
                    };
                    orderProductList.Add(orderProductEntity);

                    totalPrice += currentProduct.Prices.Find(x => x.CurrencyId == model.CurrencyId).Price *
                                  keyValuePair.Value;
                }

                orderEntity.TotalPrice = totalPrice;
                await orderService.AddOrderAsync(orderEntity);

                orderProductList.ForEach(x => x.OrderId = orderEntity.Id);

                logger.LogInformation($"Successfully added new order.");

                await orderService.AddAllOrderProductsAsync(orderProductList);

                logger.LogInformation($"Successfully added new orderProductEntity.");
                return(Ok(orderEntity.ToApiV1OrderResponseModel()));
            }
            else
            {
                logger.LogWarning($"Erorr while adding Order. Validation failed");

                return(BadRequest(ModelState.ToApiV1ErrorResponseModel()));
            }
        }
Пример #5
0
 /// <summary>
 /// 填充发票
 /// </summary>
 /// <param name="info"></param>
 protected virtual void FillOrderProducts(OrderEntity info)
 {
     info.OrderProducts = new List <OrderProductEntity>();
     foreach (GridViewRow gvr in gvProduct.Rows)
     {
         if (gvr.RowType != DataControlRowType.DataRow)
         {
             continue;
         }
         var ckSelect = gvr.FindControl("hfId") as System.Web.UI.HtmlControls.HtmlInputHidden;
         if (ckSelect == null)
         {
             continue;
         }
         var txtCost       = gvr.FindControl("txtCost") as System.Web.UI.HtmlControls.HtmlInputText;
         var txtCount      = gvr.FindControl("txtCount") as System.Web.UI.HtmlControls.HtmlInputText;
         var hfName        = gvr.FindControl("hfName") as System.Web.UI.HtmlControls.HtmlInputHidden;
         var hfIsReturn    = gvr.FindControl("hfIsReturn") as System.Web.UI.HtmlControls.HtmlInputHidden;
         var hfDescription = gvr.FindControl("hfDescription") as System.Web.UI.HtmlControls.HtmlInputHidden;
         var txtSubRemark  = gvr.FindControl("txtRemark") as System.Web.UI.HtmlControls.HtmlInputText;
         if (txtCost == null || txtCount == null || hfName == null || hfIsReturn == null || hfDescription == null || txtSubRemark == null)
         {
             continue;
         }
         var orderProduct = new OrderProductEntity
         {
             Product = new ProductEntity {
                 Id = ckSelect.Value.Convert <long>()
             },
             Price       = txtCost.Value.Convert <decimal>(),
             Count       = ddlType.DropDownList.SelectedValue == "Return" ? 0 - txtCount.Value.Convert <int>() : txtCount.Value.Convert <int>(),
             Name        = hfName.Value,
             Order       = info,
             IsReturn    = hfIsReturn.Convert <bool>(),
             Description = hfDescription.Value,
             Promotion   = new PromotionEntity {
                 Id = 0
             },
             Remark   = txtSubRemark.Value,
             SaveType = SaveType.Add
         };
         info.OrderProducts.Add(orderProduct);
     }
     FillOrderProductsByProductIds(info);
 }
Пример #6
0
 /// <summary>
 /// 填充订单明细
 /// </summary>
 /// <param name="order"></param>
 protected virtual void FillOrderProduct(OrderEntity order)
 {
     order.OrderProducts = new List <OrderProductEntity>();
     if (Products != null)
     {
         foreach (var product in Products)
         {
             if (product.Product == null)
             {
                 continue;
             }
             var orderProduct = new OrderProductEntity
             {
                 Order   = order,
                 Count   = product.Count,
                 Price   = product.Price,
                 Name    = product.Product.Name,
                 Product = new ProductEntity {
                     Id = product.Product.Id
                 },
                 Promotion = new PromotionEntity {
                     Id = product.Product.Promotion == null ? 0 : product.Product.Promotion.Id
                 },
                 IsReturn    = product.Product.IsReturn,
                 FileName    = "",
                 Remark      = "",
                 IsInvoice   = true,
                 Description = product.Product.GoodsDetails == null ? "" : product.Product.GoodsDetails.FirstOrDefault(it => it.Name == "PackageDescription")?.Detail,
                 SaveType    = SaveType.Add
             };
             order.OrderProducts.Add(orderProduct);
             if (product.Product.DepositRate > 0)
             {
                 order.Deposit = order.OrderProducts.Sum(it => it.Count * it.Price) * product.Product.DepositRate;
             }
         }
     }
 }