コード例 #1
0
        public ActionResult Export([Bind("searchValue,searchOld")] VMSearchClient payload)
        {
            List <Client> list;

            if (string.IsNullOrEmpty(payload.searchOld) || string.IsNullOrWhiteSpace(payload.searchOld))
            {
                list = _clientService.GetAll();
            }
            else
            {
                list = _clientService.GetClientByNameOrRGOrCPF(payload.searchOld);
            }

            DataTable dt = GetDataTable(list);

            if (dt.Rows.Count == 0)
            {
                var mMessages = new VMMessages()
                {
                    Css  = "msg-sucesso",
                    Text = "Não há itens para serem exportados!"
                };
                TempData["_mensagem"] = JsonConvert.SerializeObject(mMessages);
                return(RedirectToAction("Index"));
            }



            Excel excel = new Excel();

            return(excel.ExportData("Clientes", dt));
        }
コード例 #2
0
 //[Authorize(Roles = "Recepcionista")]
 public ActionResult Index([Bind("searchValue,searchOld")] VMSearchClient payload)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState.GetErrorMessages()));
         }
         if (string.IsNullOrEmpty(payload.searchValue) || string.IsNullOrWhiteSpace(payload.searchValue))
         {
             return(View(_clientService.GetAll()));
         }
         else
         {
             ViewData["searchOld"] = payload.searchValue;
             return(View(_clientService.GetClientByNameOrRGOrCPF(payload.searchValue)));
         }
     }
     catch (CustomHttpException ex)
     {
         TempData["_mensagem"] = new VMMessages()
         {
             Css  = "alert alert-danger",
             Text = ex.ErrorMessage
         };
     }
     catch (Exception ex)
     {
         _logger.Log(LogLevel.Error, ex.Message);
         TempData["_mensagem"] = new VMMessages()
         {
             Css  = "alert alert-danger",
             Text = "Um erro insperado ocorreu"
         };
     }
     return(View(_clientService.GetAll()));
 }