public async Task <IActionResult> Edit(Guid id, Employee employee) { if (id != employee.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(employee); await _context.SaveChangesAsync(); await _hubContext.Clients.All.BroadcastMessage(); var message = new EmailSender.Message(new string[] { "*****@*****.**" }, "NetCore Application", $"The Employee ${employee.FirstName} was updated."); _emailSender.SendEmail(message); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(employee.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(employee)); }
public async Task <IActionResult> DeleteConfirmed(Guid id) { var employee = await _context.Employees.FindAsync(id); _context.Employees.Remove(employee); await _context.SaveChangesAsync(); await _hubContext.Clients.All.BroadcastMessage(); var message = new EmailSender.Message(new string[] { "*****@*****.**" }, "NetCore Application", $"The Employee ${employee.FirstName} was deleted."); _emailSender.SendEmail(message); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(Employee employee) { if (ModelState.IsValid) { employee.Id = Guid.NewGuid(); _context.Add(employee); await _context.SaveChangesAsync(); await _hubContext.Clients.All.BroadcastMessage(); try { var message = new EmailSender.Message(new string[] { "*****@*****.**" }, "NetCore Application", $"The Employee ${employee.FirstName} was added."); _emailSender.SendEmail(message); } catch (Exception ex) { int x = 12; throw; } return(RedirectToAction(nameof(Index))); } return(View(employee)); }