public async Task <ActionResult <OrderStatusVM> > Post(OrderStatusVM statusVM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var data = repository.Add(statusVM);

            return(CreatedAtAction(nameof(data), new { id = data.ID }, data));
        }
        private async Task AddStatusToHistory(long orderId, OrderStatusVM statusVM)
        {
            await _fuelContext.StatusHistory.AddAsync(new OrderStatusHistory
            {
                ChangeTime = DateTime.Now,
                OrderId    = orderId,
                Status     = (Model.Enums.OrderStatus)statusVM
            });

            await _fuelContext.SaveChangesAsync();
        }
        public dynamic PutOrderStatus(OrderStatusVM o)
        {
            var orderStatus = db.OrderStatus.Find(o.id);

            orderStatus.StatusAr = o.orderStatusAr;
            orderStatus.StatusEn = o.orderStatusEn;

            var result = db.SaveChanges() > 0 ? true : false;

            return(new
            {
                result = result
            });
        }
        public ActionResult Orders()
        {
            List <OrderStatusVM> orders = new List <OrderStatusVM>();

            foreach (OrderStatus orderStatus in orderStatusFactory.GetAll())
            {
                OrderStatusVM vm = new OrderStatusVM();
                vm.OrderStatus = orderStatus;
                vm.Status      = statusFactory.Get(orderStatus.StatusID);

                orders.Add(vm);
            }

            return(View(orders));
        }
 public async Task <ActionResult <OrderStatusVM> > Put(OrderStatusVM statusVM)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     else
     {
         var mainData = repository.Get(statusVM.ID);
         if (mainData == null)
         {
             return(NotFound());
         }
         var data = repository.Update(statusVM);
         return(data);
     }
 }
        public async Task <ActionResult> getOrder(long id)
        {
            var     order  = _orderService.GetOrder(id);
            OrderVM result = order.Adapt <OrderVM>();

            foreach (var item in order.OrderDetails)
            {
                var orderDetail = item.Adapt <OrderDetailVM>();
                orderDetail.Image       = item.Product.Images.FirstOrDefault(p => p.IsHighLight).FilePath;
                orderDetail.ProductName = item.Product.Name;
                result.OrderDetailVMs.Add(orderDetail);
            }
            foreach (var status in order.OrderStatuses)
            {
                OrderStatusVM data = new OrderStatusVM();
                data.DateCreated = status.DateCreate;
                data.Name        = status.Status.Name;
                data.Priority    = status.Status.Priority;
                result.StatusVMs.Add(data);
            }

            return(Ok(result));
        }
        public async Task <OrderPutResponse> PutOne(ApplicationUser currentUser, long orderId, OrderStatusVM status)
        {
            var response = new OrderPutResponse {
                IsSuccess = false
            };

            // данным методом нельзя назначать следующие статусы, для этого есть отдельные методы
            if (status == OrderStatusVM.Created || status == OrderStatusVM.DriverAssigned || status == OrderStatusVM.Paid)
            {
                response.AddError(_stringLocalizer[CustomStringLocalizer.NO_RIGHTS_TO_ASSIGN_DRIVER]);
                return(response);
            }

            if (currentUser is Driver && status == OrderStatusVM.Cancelled)
            {
                response.AddError(_stringLocalizer[CustomStringLocalizer.NO_RIGHTS_TO_CANCEL_ORDER]);
                return(response);
            }

            await AddStatusToHistory(orderId, status);

            response.IsSuccess = true;
            return(response);
        }
        public async Task <OrderPutResponse> Put(long id, OrderStatusVM status)
        {
            var currentUser = await _userManager.GetUserAsync(User);

            return(await _orderModel.PutOne(currentUser, id, status));
        }