public async Task <IActionResult> OrderErrorList() { //var user = await _workContext.GetCurrentUser(); /*var rolesNames = _userRepository.Query() * .Where(x => x.UserGuid == user.UserGuid) * .Include(x => x.Roles) * .ThenInclude(x => x.Role) * .Select(x => x.Roles.SelectMany(y => y.Role.Name)).ToList();*/ var rolesNames = _workContext.GetRolesForCurrentUser(); var orders = (await _orderRepository.List().ToListAsync()) .Where(x => rolesNames.Contains(x.ORDER_TYPE, StringComparer.InvariantCultureIgnoreCase)) .Select(x => new OrderDetailVm { Id = x.Id, OrderType = x.ORDER_TYPE, OrderLegacy = x.PEDIDO_LEGADO, Attendence = x.LOTE_ATENDIMENTO, UpdateTimeSap = x.UPDATE_TIME_SAP, Error = x.ERRO, DocumentNumber = x.CNPJ, ClientName = x.Cliente, OrderIssue = x.REGRA_LIBERACAO, Selected = false }) .OrderByDescending(x => x.UpdateTimeSap); var model = new OrderSelecionViewModel(); model.Order.AddRange(orders); return(View(model)); }
public async Task <IActionResult> SubmitSelected(OrderSelecionViewModel model) { // get the ids of the items selected: var selectedIds = model.getSelectedIds(); // Use the ids to retrieve the records for the selected people // from the database: var selectedOrder = await _orderRepository.List().Where(x => selectedIds.Contains(x.Id)).ToListAsync(); var user = await _workContext.GetCurrentUser(); var userName = user.UserName; // Process according to your requirements: foreach (var orderId in selectedOrder.Where(x => x.Id.HasValue).Select(s => s.Id.Value)) { _orderRepository.ResendOrder(orderId, userName); } // Redirect somewhere meaningful (probably to somewhere showing // the results of your processing): return(RedirectToAction(nameof(OrderErrorList))); }