Пример #1
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);
        }
Пример #2
0
        private void updateOrder()
        {
            Console.WriteLine("\t~*~ ~*~ ~*~ \tUpdating Order\t ~*~ ~*~ ~*~\n");
            Console.WriteLine("Input OrderID: ");
            long id = Convert.ToInt64(Console.ReadLine());

            OrderDTO myOrder = dalorder.GetOrderByID(id);

            if (myOrder is null) //check if such order exists
            {
                Console.WriteLine("Invalid input! No such order in database.\n");
                return;
            }

            bool flag = true;

            while (flag)
            {
                Console.WriteLine("~ Updating Order:\n\tID: {0}\tCustomer: {1} {2} \tStatus: {3} \n\tComments: {4}\n",
                                  myOrder.MainOrderID, myOrder.CustomerID, getFullNameById(myOrder.CustomerID), getStatusById(myOrder.StatusID), myOrder.Comments);
                Console.WriteLine("Items in order: ");
                printItemsInOrder(myOrder.MainOrderID);

                Console.WriteLine("\nChoose an option:" +
                                  "\n\t1. Change customer" +
                                  "\n\t2. Chnage status" +
                                  "\n\t3. Change comments" +
                                  "\n\t0. Exit");
                try
                {
                    int opt = Convert.ToInt32(Console.ReadLine());
                    if (opt == 0)
                    {
                        flag = false;
                    }
                    switch (opt)
                    {
                    case 1:
                        Console.WriteLine("Input new CustomerID: ");
                        myOrder.CustomerID = Convert.ToInt64(Console.ReadLine());
                        break;

                    case 2:
                        Console.WriteLine("Input new StatusID: ");
                        myOrder.StatusID = Convert.ToInt16(Console.ReadLine());
                        break;

                    case 3:
                        Console.WriteLine("Input comment: ");
                        myOrder.Comments = Console.ReadLine();
                        break;

                    case 0:
                        flag = false;
                        break;

                    default:
                        throw new Exception("Invalid input.");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Console.WriteLine("Try again, or input 0 to exit.");
                }
                myOrder.LastUpdate       = DateTime.UtcNow;
                myOrder.LastStaffUpdated = 1; //id of admin
                try
                {
                    myOrder = dalorder.UpdateOrder(myOrder);
                    Console.WriteLine($"Updated Item ID: {myOrder.MainOrderID}");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Console.WriteLine("Data inputted incorrectly. Order update failed.");
                }
            }
        }
Пример #3
0
 public bool UpdateOrder(OrderViewModel model)
 {
     return(_orderDal.UpdateOrder(model));
 }
Пример #4
0
 public bool UpdateOrder(Order order)
 {
     return(_orderDal.UpdateOrder(new OrderDto(order.Id, order.Client.Id, order.Location, order.Creator.Id, order.Accu.Id, order.Info, order.Done)));
 }