public IncidentUpdateModel(IncidentUpdate update) { Id = update.Id; Message = update.Message; CreatedAt = update.CreatedAt; State = update.State; IncidentId = update.IncidentId; }
public IncidentUpdate UpdateIncidentUpdate(IncidentUpdate incidentUpdate) { var model = new IncidentUpdateModel(incidentUpdate); using var ctx = CreateContext(); ctx.IncidentUpdates.Update(model); ctx.SaveChanges(); return(new IncidentUpdate(model)); }
public async Task <IActionResult> Edit([FromRoute] int id, [FromBody] IncidentUpdate incidentUpdate) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var incident = await _context.Incident .FirstOrDefaultAsync(m => m.IncidentId == id); if (incident == null) { return(NotFound()); } if (incidentUpdate.Type != null) { incident.Type = incidentUpdate.Type; } if (incidentUpdate.Description != null) { incident.Description = incidentUpdate.Description; } if (incidentUpdate.Person != null) { incident.Person = incidentUpdate.Person; } _context.Entry(incident).State = EntityState.Modified; try { _context.Update(incident); var save = await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!_context.Incident.Any(e => e.IncidentId == id)) { return(NotFound()); } else { throw; } } return(Ok(incident)); }
public static IncidentUpdateResource FromIncidentUpdate(IncidentUpdate update) { if (update == null) { return(null); } return(new IncidentUpdateResource { Id = update.Id, IncidentId = update.IncidentId, Status = update.Status, StatusText = EnumTextService.GetIncidentStatus(update.Status), Message = update.Message, CreatedAt = update.CreatedAt, UpdatedAt = update.UpdatedAt }); }
public async Task <IncidentUpdateResource> Handle(UpdateIncidentUpdateCommand request, CancellationToken cancellationToken) { var update = new IncidentUpdate { Id = request.Id, Status = request.Status, Message = request.Message }; _dataContext.Attach(update); _dataContext.Entry(update).Property(x => x.Status).IsModified = true; _dataContext.Entry(update).Property(x => x.Message).IsModified = true; try { await _dataContext.SaveChangesAsync(cancellationToken); } catch (DbUpdateConcurrencyException) when(!IncidentUpdateExists(request.Id)) { return(null); } return(IncidentUpdateResource.FromIncidentUpdate(update)); }