예제 #1
0
        private void createOrder()
        {
            Console.WriteLine("\t~*~ ~*~ ~*~ \tCreating New Order\t ~*~ ~*~ ~*~\n");
            Console.WriteLine("Input ID of the customer: ");
            long _customerID = Convert.ToInt64(Console.ReadLine());

            Console.WriteLine("Input Status ID for order: ");
            short _status = Convert.ToInt16(Console.ReadLine());

            Console.WriteLine("Input Comments for the order: ");
            string _comments = Console.ReadLine();

            OrderDTO myOrder = new OrderDTO
            {
                Date             = DateTime.UtcNow,
                CustomerID       = _customerID,
                StatusID         = _status,
                Comments         = _comments,
                LastUpdate       = DateTime.UtcNow,
                LastStaffUpdated = 1 //ID of user admin
            };

            try
            {
                myOrder = dalorder.CreateOrder(myOrder);
                Console.WriteLine($"New OrderID is {myOrder.MainOrderID}");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.WriteLine("Data inputted incorrectly. Order failed.");
            }
        }
예제 #2
0
        public ErrorCodes CreateOrder(OrderFullViewModel model)
        {
            ErrorCodes errorCodes = ErrorCodes.Success;

            try
            {
                var user = _userService.GetUserLogin().UserName;
                model.DeliverDate = DateTime.ParseExact(model.DeliverDateStr, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);
                if (model.Code == Guid.Empty)
                {
                    model.Code = Guid.NewGuid();
                }
                ///------- bỏ Code thay bằng OrderCode
                if (string.IsNullOrEmpty(model.OrderCode))
                {
                    model.OrderCode = StringUtils.GenerateUniqueId();
                }
                model.CreatedBy        = user;
                model.ModifiedBy       = user;
                model.CustomerNote     = string.IsNullOrEmpty(model.CustomerNote) ? string.Empty : model.CustomerNote;
                model.OrderPrice       = int.Parse(model.OrderPriceStr.Replace(".", ""));
                model.OrderOriginPrice = int.Parse(model.OrderOriginPriceStr.Replace(".", ""));
                var result     = 0;
                var change_log = "";
                if (model.OrderId == 0)
                {
                    result     = _orderDal.CreateOrder(model);
                    change_log = "Tạo đơn hàng";
                }
                else
                {
                    result     = _orderDal.UpdateOrder(model);
                    change_log = "Sửa đơn hàng";
                }
                if (result <= 0)
                {
                    errorCodes = ErrorCodes.BusinessError;
                }
                else
                {
                    _orderHistoryBo.Insert(new OrderHistory
                    {
                        change_log = change_log,
                        created_by = user,
                        order_id   = result,
                        status     = model.Status
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                errorCodes = ErrorCodes.Exception;
            }
            return(errorCodes);
        }