Пример #1
0
        public async Task <IActionResult> CreateOrUpdate([FromBody] OrderItemModel order)
        {
            //order.Price = _productService.Get(order.IdProductPiece).Price;

            var result = await _Service.CreateOrUpdate(order);

            return(Ok(result));
        }
Пример #2
0
        public async Task <BaseResult> CreateOrUpdate(OrderModel model, int updateBy = 0, string updateByUserName = "")
        {
            var ward = _wardService.Get(model.WardId);

            model.Address = ward.Name + ward.District.Name + ward.District.City.Name;
            List <OrderItemModel> order_Items = null;

            if (model.ListOrderItem != null)
            {
                order_Items         = model.ListOrderItem;
                model.ListOrderItem = null;
            }
            var order = model.ToOrder();

            if (order.Id > 0)
            {
                if (order_Items != null)
                {
                    List <int> listInDTB         = _orderItemService.GetOrderItemByOrderId(model.Id).ToList();
                    List <int> orderItemUpdateID = new List <int> {
                    };
                    foreach (OrderItemModel orderItemModel2 in order_Items)
                    {
                        await _orderItemService.CreateOrUpdate(orderItemModel2);

                        orderItemUpdateID.Add(orderItemModel2.Id);
                    }

                    foreach (int a in listInDTB)
                    {
                        if (!orderItemUpdateID.Contains(a))
                        {
                            await _orderItemService.Delete(a);
                        }
                    }

                    order_Items = null;
                }
                //Cập nhật
                return(await Update(order));
            }
            else
            {
                order.CreatedTime = DateTime.Now;
                CreateOrUpdateResultInt rs = await Create(order);

                if (order_Items != null)

                {
                    foreach (OrderItemModel orderItemModel2 in order_Items)
                    {
                        orderItemModel2.OrderId = rs.Id;

                        await _orderItemService.CreateOrUpdate(orderItemModel2);
                    }
                }


                return(rs);
            }
        }