public async Task <IActionResult> Update([FromBody] HistoricalViewModel historicalViewModel) { var historicalEntity = historicalViewModel.ToEntity(); var historicalEntityUpdated = await historicalsService.Update(historicalEntity); var historicalViewModelUpdated = historicalEntityUpdated.ToViewModel(); return(StatusCode((int)StatusCodes.Status202Accepted, historicalViewModelUpdated)); }
public static HistoricalEntity ToEntity(this HistoricalViewModel viewModel) { if (viewModel?.Leader == null || viewModel?.Led == null) { return(null); } var entity = new HistoricalEntity { Id = viewModel.Id, Leader = viewModel.Leader.ToEntity(), Led = viewModel.Led.ToEntity(), Occurrence = viewModel.Occurrence, Commentary = viewModel.Commentary, }; return(entity); }
public static HistoricalViewModel ToViewModel(this HistoricalEntity entity) { if (entity == null) { return(null); } var viewModel = new HistoricalViewModel { Id = entity.Id, Leader = entity.Leader.ToViewModel(), Led = entity.Led.ToViewModel(), Occurrence = entity.Occurrence, Commentary = entity.Commentary, }; return(viewModel); }