public async Task <IActionResult> Edit(Hour hour, IFormFile Document, IFormFile Attachment, int?approval, int?description, int?clients, int?projects, int?month, int?year) { GetSessions(); if (ViewBag.Email == null) { return(ExpiredSession()); } try { int empId = ViewBag.Id; if (ModelState.IsValid) { try { if (Document != null) { string nomeArquivo = string.Concat(hour.Id, "-", Document.FileName); _files.EnviarArquivo(Document, nomeArquivo, storage); hour.File = nomeArquivo; } if (Attachment != null) { string nomeArquivoAttachment = string.Concat(hour.Id, "-", Attachment.FileName); _files.EnviarArquivo(Attachment, nomeArquivoAttachment, storageAttachment); hour.Attachment = nomeArquivoAttachment; } await _hourService.UpdateAsync(hour); } catch (DbUpdateConcurrencyException e) { if (!HourExists(hour.Id)) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } else { throw; } } return(RedirectToAction(nameof(Index), new { approval, description, clients, projects, month, year })); } return(View(hour)); } catch (Exception e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }
public async Task <IActionResult> Edit(Hour hour, IFormFile Document) { GetSessions(); if (ViewBag.Email == null) { return(ExpiredSession()); } try { if (ModelState.IsValid) { try { if (Document != null) { string nomeArquivo = string.Concat(hour.Id, "-", Document.FileName); _files.EnviarArquivo(Document, nomeArquivo, storage); } await _hourService.UpdateAsync(hour); } catch (DbUpdateConcurrencyException) { if (!HourExists(hour.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(hour)); } catch (Exception e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }