Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPut("{id}")]
- public async Task<object> EditEventOccurrence(int id, [FromBody] EventOccurrenceResource eventOccurrenceResource)
- {
- if (!ModelState.IsValid)
- return BadRequest(ModelState);
- var eventOccurrence = await _context.EventOccurrences
- .Where(eo => eo.Id == id)
- .Include(eo => eo.DeviceOperation)
- .ThenInclude(devop => devop.Codes)
- .ThenInclude(co => co.Code)
- .Include(eo => eo.DeviceOperation)
- .ThenInclude(devop => devop.Breaker.SupplySubstation)
- .Include(eo => eo.Outage)
- .ThenInclude(o => o.Codes)
- .ThenInclude(co => co.Code)
- .Include(eo => eo.Outage)
- .ThenInclude(o => o.Substation)
- .SingleOrDefaultAsync();
- if (eventOccurrence == null)
- {
- return NotFound($"Event Occurrence {id} was not found");
- }
- _mapper.Map<EventOccurrenceResource, EventOccurrence>(eventOccurrenceResource, eventOccurrence);
- await _context.SaveChangesAsync();
- var result = _mapper.Map<EventOccurrence, EventOccurrenceResource>(eventOccurrence, eventOccurrenceResource);
- return Ok(result);
- }
- public class EventOccurrenceResource
- {
- public int Id { get; set; }
- [Required]
- public int EventId { get; set; }
- public EventResource Event { get; set; }
- public DeviceOperationResource DeviceOperation { get; set; }
- public OutageResource Outage { get; set; }
- }
- public class EventOccurrence
- {
- public int Id { get; set; }
- public Event Event { get; set; }
- public int EventId { get; set; }
- public DeviceOperation DeviceOperation { get; set; }
- public int? DeviceOperationId { get; set; }
- public Outage Outage { get; set; }
- public int? OutageId { get; set; }
- }
- CreateMap<EventOccurrenceResource, EventOccurrence>()
- .ForMember(eo => eo.Id, opt => opt.Ignore())
- .ForMember(eo => eo.OutageId, opt => opt.MapFrom(eor => eor.Outage.Id));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement