Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, UpdateOrderViewModel model)
        {
            if (ModelState.IsValid)
            {
                var order = await _orderService.GetById(id);

                var result = await _orderService.Update(id, order, model.SelectedProductIds);

                if (result.Succeeded)
                {
                    TempData["OrderCreated"] = true;
                    return(RedirectToAction(nameof(Index)));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(error.Code, error.Description);
                }
            }

            model.Products = await GetProductList();

            model.Clients = await GetClientList();

            return(View(model));
        }
Ejemplo n.º 2
0
        public void Update(string id, UpdateOrderViewModel model)
        {
            validateUpdate(model);

            if (Valid)
            {
                Order order = getOrder(id);
                if (order == null)
                {
                    AddNotification("Pedido", "Nenhum pedido com este código pode ser encontrado!");
                    return;
                }

                if (Valid)
                {
                    clearItems(model, order);
                }

                if (Valid)
                {
                    addOrUpdateItems(model, order);
                }
            }

            if (Valid)
            {
                _context.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        public void Update(UpdateOrderViewModel model)
        {
            _unitOfWork.BeginTransaction();
            var order = _orderRepository.GetById(model.OrderId);

            if (order == null)
            {
                _unitOfWork.Commit();
                throw new Exception(ExceptionMessages.OrderException.NOT_FOUND);
            }

            var user = _userRepository.GetById(model.UserId);

            if (user == null)
            {
                _unitOfWork.Commit();
                throw new Exception(ExceptionMessages.UserException.NOT_FOUND);
            }
            order.User   = user;
            order.Status = Order.MapToOrderStatus(Convert.ToInt32(model.Status));
            //order.DateOrdered = Convert.ToDateTime(model.DateOrdered);
            //order.OrderPrice = model.Price;

            _orderRepository.Update(order);
            _unitOfWork.Commit();
        }
Ejemplo n.º 4
0
        public ActionResult UpdateProcess(UpdateOrderViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.TransactionStatus = Helper.OrderStatus;

                return(View("Update", viewModel));
            }

            var orderInDb = _context.Orders.Find(viewModel.OrderId);

            if (orderInDb == null)
            {
                ModelState.AddModelError("", "Something went wrong.");
                viewModel.TransactionStatus = Helper.OrderStatus;

                return(View("Update", viewModel));
            }

            orderInDb.Status   = viewModel.TransactionStatusId;
            orderInDb.ETHTXNNo = viewModel.EthTxnNo;

            _context.Entry(orderInDb).State = EntityState.Modified;
            _context.SaveChanges();

            return(RedirectToAction("Index", "Orders"));
        }
Ejemplo n.º 5
0
 private void validateUpdate(UpdateOrderViewModel order)
 {
     if (order.Items == null || order.Items.Count == 0)
     {
         AddNotification("Itens", "Pedido inválido! Os pedidos devem conter ao meno um item.");
         return;
     }
 }
        public async Task <IActionResult> UpdateOrderAsync([FromRoute] int id, [FromBody] UpdateOrderViewModel model)
        {
            var command = mapper.Map <UpdateOrderViewModel, UpdateOrderCommandModel>(model);

            command.Id = id;
            await bus.SendAsync(command);

            return(Accepted());
        }
Ejemplo n.º 7
0
 public IActionResult Put(string id, [FromBody] UpdateOrderViewModel value)
 {
     _orderService.Update(id, value);
     if (_orderService.Valid)
     {
         return(Ok());
     }
     return(BadRequest(_orderService.Notifications));
 }
Ejemplo n.º 8
0
        public IHttpActionResult Put(UpdateOrderViewModel modifiedModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _service.Update(_mapper.Map <Order>(modifiedModel));
            return(Ok());
        }
Ejemplo n.º 9
0
        public ActionResult Update(UpdateOrderViewModel model)
        {
            if (!ModelState.IsValid)
            {
                Helpers.InvalidModelState(ModelState);
            }

            _orderService.Update(model);
            return(Json(true));
        }
Ejemplo n.º 10
0
        public ActionResult Update(int id)
        {
            var viewModel = new UpdateOrderViewModel()
            {
                OrderId             = id,
                TransactionStatus   = Helper.OrderStatus,
                TransactionStatusId = _context.Orders.FirstOrDefault(x => x.Id == id).Status
            };

            return(View("Update", viewModel));
        }
Ejemplo n.º 11
0
        private void clearItems(UpdateOrderViewModel model, Order order)
        {
            var itemCmd = new DeleteItemCommand(_itemRepository, _itemValidator);

            foreach (var item in order.Items)
            {
                if (!model.Items.Any(i => i.Description == item.Description))
                {
                    itemCmd.Execute(item);
                    AddNotifications(itemCmd);
                }
            }
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Edit(int id)
        {
            var order = await _orderService.GetById(id);

            var model = new UpdateOrderViewModel
            {
                Id            = order.Id,
                Date          = order.OrderedDate,
                InvoiceNumber = order.InvoiceNumber,
                ClientId      = order.ClientId,
                Clients       = await GetClientList(),
                Products      = await GetProductList()
            };

            return(View(model));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Details(UpdateOrderViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var order = await this.ordersRepository.Get(model.Id).ConfigureAwait(false);

            order.Status          = model.Status;
            order.DeliveryComment = model.DeliveryComment;

            await this.ordersRepository.Update(order).ConfigureAwait(false);

            return(this.RedirectToAction("List"));
        }
 public IActionResult Update(int Id)
 {
     try
     {
         var orderViewModel = new UpdateOrderViewModel()
         {
             Customers = customerService.GetCustomers(),
             Products  = productService.AllProducts(),
             Order     = orderService.FindByOrderId(Id)
         };
         return(View(orderViewModel));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 15
0
        public ActionResult Edit(int id = 0)
        {
            Order order = orderRepo.GetSingleEntity(x => x.OrderId == id);

            if (order == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new UpdateOrderViewModel();

            viewModel.Status   = statusRepo.GetWithFilterAndOrder();
            viewModel.Order    = order;
            viewModel.StatusId = order.StatusId;

            return(View(viewModel));
        }
Ejemplo n.º 16
0
        private void addOrUpdateItems(UpdateOrderViewModel model, Order order)
        {
            var itemCmd = new SaveItemCommand(_itemRepository, _itemValidator);

            foreach (var item in model.Items)
            {
                var entity = item.Adapt <Item>();
                entity.PedidoId = order.Id;
                itemCmd.Execute(entity);
                AddNotifications(itemCmd);

                if (Invalid)
                {
                    break;
                }
            }
        }
        public IActionResult Update(string id)
        {
            var order    = orderService.GetById(id);
            var senderId = order.Sender.Id.ToString();

            UpdateOrderViewModel newOrderViewModel = new UpdateOrderViewModel()
            {
                UpdateId             = order.Id.ToString(),
                PickupLocation       = GetLocationsList(senderId),
                DeliveryLocation     = GetLocationsList(senderId),
                UpDeliveryLocationId = order.DeliveryAddress.Id.ToString(),
                UpPickupLocationId   = order.PickUpAddress.Id.ToString(),
                UpPrice = order.Price,
            };

            return(PartialView("_Update", newOrderViewModel));
        }
Ejemplo n.º 18
0
        public async Task <ActionResult <OrderViewModel> > PutAsync(int id, UpdateOrderViewModel pe)
        {
            _logger.LogDebug("Put {0} {1} {2} {3}", id, pe.Paid, pe.Cancelled, pe.Reason);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _repository.UpdateOrderAsync(id, pe.Paid, pe.Cancelled, pe.Reason);

            if (!result)
            {
                return(BadRequest(new ProblemDetails()
                {
                    Detail = result.Message
                }));
            }

            return(Ok(_mapper.Map <OrderViewModel>(result.Data)));
        }
Ejemplo n.º 19
0
        public ActionResult Edit(UpdateOrderViewModel viewModel)
        {
            Order order = null;

            if (ModelState.IsValid)
            {
                order = orderRepo.GetSingleEntity(x => x.OrderId == viewModel.Order.OrderId);

                order.StatusId = viewModel.StatusId;
                order.Comment  = viewModel.Order.Comment;

                orderRepo.Update(order);
                orderRepo.SaveChanges();

                return(RedirectToAction("Index"));
            }

            viewModel.Status = statusRepo.GetWithFilterAndOrder();
            viewModel.Order  = order;

            return(View(viewModel));
        }
        public IActionResult Update([FromForm] UpdateOrderViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_Update", viewModel));
            }

            try
            {
                orderService.Update(viewModel.UpdateId,
                                    viewModel.UpPickupLocationId,
                                    viewModel.UpDeliveryLocationId,
                                    viewModel.UpPrice);
                return(PartialView("_Update", viewModel));
            }
            catch (Exception e)
            {
                logger.LogError("Failed to update order {@Exception}", e.Message);
                logger.LogDebug("Failed to update order {ExceptionMessage}", e);
                return(BadRequest(e.Message));
            }
        }
 public PartialViewResult UpdateOrder(UpdateOrderViewModel model)
 {
     return(PartialView("UpdateOrder", model));
 }
Ejemplo n.º 22
0
        public async Task <ActionResult <OrderViewModel> > Update(Guid id, [FromBody] UpdateOrderViewModel body)
        {
            var result = await Mediator.Send(new UpdateOrderCommand { Id = id, Order = body });

            return(Ok(result));
        }
Ejemplo n.º 23
0
 public OrderPackage CreateOrder(IModalDialogService modalDialogService, IServiceFactory serviceFactory)
 {
     var viewModel = new UpdateOrderViewModel(modalDialogService, serviceFactory);
       viewModel.OrderPackage = new OrderPackage();
       viewModel.DialogMode = DialogMode.Create;
       ModalDialogHelper<UpdateOrder>.ShowDialog(viewModel);
       if (!viewModel.IsCanceled)
       {
     return viewModel.OrderPackage;
       }
       return null;
 }
Ejemplo n.º 24
0
        public HttpResponseMessage UpdateOrderStatus(HttpRequestMessage request, UpdateOrderViewModel orderVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var dbOrder = this.orderService.GetById(orderVm.Id);

                    var orderDetail = this.orderService.GetDetailOrderByOrderId(orderVm.Id);

                    if (orderDetail != null && orderVm.Status == OrderStatus.Cancelled && dbOrder.Status != orderVm.Status)
                    {
                        int[] ArrQuantity = orderDetail.Quantities.ToArray();
                        int i = 0;
                        foreach (var item in orderDetail.Products)
                        {
                            if (i == orderDetail.Products.Count())
                            {
                                break;
                            }
                            var dbProduct = this.productService.GetById(item.Id);
                            if (dbProduct != null)
                            {
                                dbProduct.Quantity += ArrQuantity[i];
                                this.productService.Update(dbProduct);
                                this.productService.Save();
                            }

                            i++;
                        }

                        string title = "Huỷ thành công đơn hàng từ Electrolic Store";
                        StringBuilder builder = new StringBuilder();
                        BuildSendMailContent(title, builder, orderDetail);
                        this.mailService.SendMail(orderDetail.Email, title, builder.ToString());
                    }

                    if (orderDetail != null && orderVm.PaymentStatus == PaymentStatus.Paid && dbOrder.PaymentStatus != orderVm.PaymentStatus)
                    {
                        string title = "Thanh toán thành công đơn hàng từ Electrolic Store";
                        StringBuilder builder = new StringBuilder();
                        BuildSendMailContent(title, builder, orderDetail);
                        this.mailService.SendMail(orderDetail.Email, title, builder.ToString());
                    }

                    dbOrder.ShipDate = orderVm.ShipDate;
                    dbOrder.PaymentStatus = orderVm.PaymentStatus;
                    dbOrder.ShipStatus = orderVm.ShipStatus;
                    dbOrder.Status = orderVm.Status;
                    this.orderService.Update(dbOrder);
                    this.orderService.Save();
                    response = request.CreateResponse(HttpStatusCode.Created, dbOrder);
                }

                return response;
            }));
        }