//edit
        public async Task <IActionResult> Edit(string id)
        {
            var orderTag = await _orderTagService.GetOrderTagById(id);

            if (orderTag == null)
            {
                return(RedirectToAction("List"));
            }

            var model = new OrderTagModel {
                Id         = orderTag.Id,
                Name       = orderTag.Name,
                OrderCount = await _orderTagService.GetOrderCount(orderTag.Id, "")
            };

            return(View(model));
        }
        public async Task <IActionResult> Edit(OrderTagModel model)
        {
            var orderTag = await _orderTagService.GetOrderTagById(model.Id);

            if (orderTag == null)
            {
                //No product tag found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                orderTag.Name = model.Name;
                await _orderTagService.UpdateOrderTag(orderTag);

                ViewBag.RefreshPage = true;
                return(View(model));
            }
            //If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <IActionResult> List(DataSourceRequest command)
        {
            var tags          = (await _orderTagService.GetAllOrderTags());
            var orderTagsList = new List <OrderTagModel>();

            foreach (var tag in tags)
            {
                var item = new OrderTagModel();
                item.Id         = tag.Id;
                item.Name       = tag.Name;
                item.OrderCount = await _orderTagService.GetOrderCount(tag.Id, "");

                orderTagsList.Add(item);
            }

            var gridModel = new DataSourceResult {
                Data  = orderTagsList.OrderByDescending(x => x.OrderCount).PagedForCommand(command),
                Total = tags.Count()
            };

            return(Json(gridModel));
        }