示例#1
0
        public async Task <IHttpActionResult> PostOrder(OrderMeta orderMeta)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(new
                {
                    status = false,
                    data = "Có lỗi xảy ra"
                }));
            }

            var order = new Order()
            {
                OrderID    = orderMeta.OrderID,
                CustomerID = orderMeta.CustomerID,
                OrderDate  = DateTime.Now,
                EmployeeID = 1
            };

            db.Orders.Add(order);

            var rs = 0;

            try
            {
                rs = await db.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw;
            }

            if (rs > 0)
            {
                var listOrderDetail = new List <OrderDetail>();

                foreach (var item in orderMeta.Products)
                {
                    var orderDetail = new OrderDetail()
                    {
                        OrderID   = order.OrderID,
                        ProductID = item.ProductID,
                        UnitPrice = item.UnitPrice == null ? 0 : (decimal)item.UnitPrice,
                        Quantity  = 1,
                        Discount  = 0
                    };

                    listOrderDetail.Add(orderDetail);
                }

                db.OrderDetails.AddRange(listOrderDetail);
                await db.SaveChangesAsync();
            }

            return(Ok(new
            {
                status = true,
                data = "Tạo đơn hàng"
            }));
        }
示例#2
0
        public async Task <JsonResult> Order(OrderMeta order)
        {
            if (!ModelState.IsValid)
            {
                return(Json(GetErrorsInModelState()));
            }

            if (order.ListProduct == null)
            {
                return(Json(-1));
            }

            var jsonProduct = JsonConvert.SerializeObject(order.ListProduct);

            var apiService = _configuration.GetApiServiceInfo();

            var result = await _productService.OrderInsert(Guid.NewGuid().ToString(), apiService.TenantId, CultureInfo.CurrentCulture.Name,
                                                           order.FullName, order.PhoneNumber, order.Email, order.Address, order.Note, order.SessionId, jsonProduct);

            if (result > 0)
            {
                SessionHelper.SetObjectAsJson(HttpContext.Session, SessionParam.ShoppingCart, null);
            }

            return(Json(result));
        }
示例#3
0
 public async Task <IActionResult> Update(string id, [FromBody] OrderMeta OrderMeta, bool isBalanced)
 {
     //var result = await _orderService.Update(CurrentUser.TenantId, CurrentUser.Id, CurrentUser.FullName, CurrentUser.Avatar,
     //    id, OrderMeta, isBalanced);
     //if (result.Code <= 0)
     //    return BadRequest(result);
     return(Ok(1));
 }
示例#4
0
 public PresentationalOrderMeta MapToPresentational(OrderMeta orderMeta)
 {
     return(new PresentationalOrderMeta
     {
         Countries = MapToMultiplePresentationals(orderMeta.Countries),
         ShippingMethods = MapToMultiplePresentationals(orderMeta.ShippingMethods),
         PaymentMethods = MapToMultiplePresentationals(orderMeta.PaymentMethods),
     });
 }
示例#5
0
        public async Task <IActionResult> Insert([FromBody] OrderMeta OrderMeta)
        {
            var result = await _orderService.Insert(CurrentUser.TenantId, CurrentUser.Id, CurrentUser.FullName, OrderMeta);

            if (result.Code <= 0)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
示例#6
0
 public Task <ActionResultResponse> Update(string tenantId, string id, OrderMeta orderMeta)
 {
     throw new NotImplementedException();
 }
示例#7
0
        public async Task <ActionResultResponse <string> > Insert(string tenantId, string createUserId,
                                                                  string createFullName, OrderMeta orderMeta)
        {
            var now      = DateTime.Now;
            var quantity = await _orderRepository.Count(tenantId);

            var code = string.IsNullOrEmpty(orderMeta.Code) ? $"{now.ToString("DDMMyyyy")}{quantity.ToString("D5")}" : orderMeta.Code;

            var isExists = await _orderRepository.CheckExists(tenantId, null, code);

            if (isExists)
            {
                return(new ActionResultResponse <string>(-2,
                                                         _warehouseResourceService.GetString(ErrorMessage.AlreadyExists, "OrderCode")));
            }

            if (orderMeta.OrderDetails.Count(x => x.Quantity <= 0) > 0)
            {
                return(new ActionResultResponse <string>(-1, _warehouseResourceService.GetString("Product quantity must greater than.")));
            }

            var order = new Order()
            {
                Code            = code,
                TenantId        = tenantId,
                Name            = $"{orderMeta.CustomerName}_{orderMeta.PhoneNumber}",
                UnsignName      = $"{code} {orderMeta.CustomerName} {orderMeta.PhoneNumber}".StripVietnameseChars().ToUpper(),
                CusomerId       = orderMeta.CustomerId,
                CustomerName    = orderMeta.CustomerName?.Trim(),
                PhoneNumber     = orderMeta.PhoneNumber?.Trim(),
                Email           = orderMeta.Email?.Trim(),
                Address         = orderMeta.Address?.Trim(),
                Note            = orderMeta.Note?.Trim(),
                Discount        = orderMeta.Discount,
                DiscountType    = orderMeta.DiscountType,
                Transport       = orderMeta.Transport,
                Status          = orderMeta.Status,
                DeliveryDate    = orderMeta.DeliveryDate,
                CreatorFullName = createFullName,
                CreatorId       = createUserId
            };

            foreach (var detail in orderMeta.OrderDetails)
            {
                order.OrderDetails.Add(new OrderDetail()
                {
                    TenantId        = tenantId,
                    OrderId         = order.Id,
                    ProductId       = detail.ProductId,
                    ProductName     = detail.ProductName,
                    Quantity        = detail.Quantity,
                    UnitId          = detail.UnitId,
                    Price           = detail.Price,
                    Discount        = detail.Discount,
                    DiscountType    = detail.DiscountType,
                    CreatorId       = createUserId,
                    CreatorFullName = createFullName,
                    Amount          = detail.DiscountType == (byte)DiscountType.Money ? (detail.Price * detail.Quantity - detail.Discount ?? 0) : detail.Price * detail.Quantity * (1 - (detail.Discount ?? 0 / 100)),
                });
            }

            order.Quantity = order.OrderDetails.Count();
            var totalPrice = order.OrderDetails.Sum(x => x.Amount);

            order.TotalPrice  = totalPrice;
            order.TotalAmount = order.DiscountType == (byte)DiscountType.Money ? totalPrice - orderMeta.Discount ?? 0 : totalPrice * (1 - orderMeta.Discount ?? 0 / 100);

            var result = await _orderRepository.Insert(order);

            if (result <= 0)
            {
                return(new ActionResultResponse <string>(-3,
                                                         _warehouseResourceService.GetString(ErrorMessage.SomethingWentWrong)));
            }


            return(new ActionResultResponse <string>(result,
                                                     _warehouseResourceService.GetString(SuccessMessage.AddSuccessful), "", order.Id));
        }