public async Task <IActionResult> PutLocations(int id, Locations locations) { if (id != locations.Id) { return(BadRequest()); } _context.Entry(locations).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LocationsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutEmployee(int id, Employee employee) { if (id != employee.Id) { return(BadRequest()); } _context.Entry(employee).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <string> AddAsync(ScheduleLesson lesson) { ThrowIfNotValidate(lesson); await ThrowIdCantInsertAsync(lesson); var id = Guid.NewGuid().ToString(); lesson.Id = id; _context.Add(lesson); await _context.SaveChangesAsync(); return(id); }
public async Task ExecuteCommand(int id, int commandId) { // The client to execute command on is not connected any more so report to the caller that the command didn't executed var connectedClient = ConnectedClientsRegistry.Value.GetConnectedClients().FirstOrDefault(cc => cc.Client.Id == id); if (connectedClient == null) { Clients.Caller.commandExecutionInfo("failed", "Client is not reachable at this time"); return; } // Get the connectionId for the specific client device var connectionId = connectedClient.ConnectionId; using (var context = new SchedulerContext()) { var command = context.Commands.First(c => c.Id == commandId); // Store in the database info about the current execution var commandExecution = new CommandExecution { ClientId = id, Command = command, Type = MachineCommandType.ManualTriggered, Result = ExecutionResult.Pending }; context.CommandsExecutuions.Add(commandExecution); await context.SaveChangesAsync().ConfigureAwait(false); Clients.Client(connectionId).executeCommand(commandExecution); Clients.Group(Resources.WepAppClientsGroupName).commandExecutionInfo("started", commandExecution); } }
public async Task SendThankYouMail(SchedulerContext db, EmailRecipient item, EmailTrack track) { await SendThankYouMail(item, track); track.IsThankYouMailSent = true; await db.SaveChangesAsync(); }
public async Task Log(LogEntry logEntry) { using (var context = new SchedulerContext()) { logEntry.CreatedAt = DateTime.UtcNow; context.LogEntries.Add(logEntry); await context.SaveChangesAsync().ConfigureAwait(false); } }
public async Task SendReminderMail(SchedulerContext db, EmailRecipient item, EmailTrack track) { await SendReminderEmail(item, track); track.LastRemindedDate = DateTime.Today; track.ReminderCount++; await db.SaveChangesAsync(); }
public async Task <ActionResult <WorkItem> > AddWorkItemAsync(WorkItem workItem) { if (ModelState.IsValid) { await _context.WorkItems.AddAsync(workItem); await _context.SaveChangesAsync(); return(Ok(workItem)); } return(BadRequest(workItem)); }
public async Task UpdateTrack(SchedulerContext db, EmailRecipient item, String referenceCode) { db.EmailTracks.Add(new EmailTrack() { TrackId = Guid.NewGuid(), RecipientId = item.RecipientId, ReferenceCode = referenceCode, IsLinkOpened = false, IsThankYouMailSent = false, LastRemindedDate = DateTime.Today }); await db.SaveChangesAsync(); }
public async Task ReportCommandResult(CommandExecution commandExecution) { // Update the data for the supplied execution using (var context = new SchedulerContext()) { var executionToUpdate = context.CommandsExecutuions.First(ce => ce.Id == commandExecution.Id); executionToUpdate.Result = commandExecution.Result; executionToUpdate.StartExecution = commandExecution.StartExecution.HasValue ? commandExecution.StartExecution.Value : default(DateTime); executionToUpdate.FinishExecution = commandExecution.FinishExecution.HasValue ? commandExecution.FinishExecution.Value : default(DateTime); await context.SaveChangesAsync().ConfigureAwait(false); Clients.Group(Resources.WepAppClientsGroupName).commandExecutionInfo("finished", commandExecution); } }