public async Task <ActionResult> LancaPlanilhaPost(ImportacaoPlanilhaAtividadesViewModel planmodel) { CarregaTipos(); CarregaProjetos(); CarregaUsuarios(); if (ModelState.IsValid && planmodel != null && planmodel.Itens.Count > 0) { try { ImportaPlanilhaApplication app = new ImportaPlanilhaApplication(this.db); int linhas = await app.LancarAsync(planmodel); MensagemParaUsuarioViewModel.MensagemSucesso(string.Format("Planilha importada com sucesso! {0} linhas da planilha importadas.", linhas), TempData); return(View("Index")); } catch (Exception err) { MensagemParaUsuarioViewModel.MensagemErro(err.Message, TempData, ModelState); LogServices.LogarException(err); } } return(View(planmodel)); }
public ActionResult Index(FormCollection formCollection) { CarregaTipos(); CarregaProjetos(); CarregaUsuarios(); if (Request != null) { HttpPostedFileBase file = Request.Files["UploadedFile"]; if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName) && (Path.GetExtension(file.FileName).ToUpper() == ".XLSX")) { string fileName = file.FileName; string fileContentType = file.ContentType; using (var package = new ExcelPackage(file.InputStream)) { try { ImportaPlanilhaApplication app = new ImportaPlanilhaApplication(this.db); var planilha = app.TransformarPlanilhaAdmin(package); return(View("LancaPlanilha", planilha)); } catch (Exception err) { MensagemParaUsuarioViewModel.MensagemErro(err.ToString(), TempData, ModelState); LogServices.LogarException(err); } } } else { MensagemParaUsuarioViewModel.MensagemErro("Faça o upload de uma planilha de horários em excel .xlsx no padrão da Tecnun.", TempData, ModelState); } } else { MensagemParaUsuarioViewModel.MensagemErro("Ocorreu algum erro e o request está nulo", TempData, ModelState); } return(View("Index")); }
public ActionResult Index(FormCollection formCollection) { CarregaTipos(); CarregaProjetos(); CarregaUsuarios(); if (Request != null) { if (formCollection["IdUsuario"] != null) { int IdUsuario = TFWConvert.ToInteger(formCollection["IdUsuario"]); if (IdUsuario > 0) { HttpPostedFileBase file = Request.Files["UploadedFile"]; if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName) && (Path.GetExtension(file.FileName).ToUpper() == ".XLSX")) { string fileName = file.FileName; string fileContentType = file.ContentType; //byte[] fileBytes = new byte[file.ContentLength]; //var data = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength)); using (var package = new ExcelPackage(file.InputStream)) { try { ImportaPlanilhaApplication app = new ImportaPlanilhaApplication(this.db); var planilha = app.TransformarPlanilhaUsuario(IdUsuario, package); return(View("LancaPlanilha", planilha)); } catch (Exception err) { MensagemParaUsuarioViewModel.MensagemErro(err.Message, TempData, ModelState); LogServices.LogarException(err); } } } else { MensagemParaUsuarioViewModel.MensagemErro("Faça o upload de uma planilha de horários em excel .xlsx no padrão da Tecnun.", TempData, ModelState); } } else { MensagemParaUsuarioViewModel.MensagemErro("Selecione um usuário válido", TempData, ModelState); } } else { MensagemParaUsuarioViewModel.MensagemErro("Não foi encontrado o Id do Usuário", TempData, ModelState); } } else { MensagemParaUsuarioViewModel.MensagemErro("Ocorreu algum erro e o request está nulo", TempData, ModelState); } return(View("Index")); }