public async Task <HistoricalEntity> Update(HistoricalEntity historical) { var requestErrors = new string[] { Guid.TryParse(historical.Id, out var _) ? null : GlobalMessages.InvalidId(historical.Id), historical.Occurrence == DateTime.MinValue ? HistoricalsMessages.InvalidOccurrence(historical.Occurrence) : null, }.Where(e => e != null);
public async Task <HistoricalEntity> Insert(HistoricalInputEntity historicalInput) { if (historicalInput.Occurrence == DateTime.MinValue) { throw new ApiException(HttpStatusCode.BadRequest, HistoricalsMessages.InvalidOccurrence(historicalInput.Occurrence)); } var(leader, led) = await employeesService.ObtainPair(historicalInput?.LeaderId, historicalInput?.LedId); var historicalList = await historicalsRepository.ObtainByPair(historicalInput.LeaderId, historicalInput.LedId); var occurrenceObtained = historicalList?.FirstOrDefault(historical => historical.Occurrence.Date == historicalInput.Occurrence.Date); if (occurrenceObtained != null) { throw new ApiException(HttpStatusCode.Conflict, HistoricalsMessages.Conflict(leader.Email, led.Email, historicalInput.Occurrence)); } _ = await oneononesService.ObtainByPair(leader.Id, led.Id); var historical = new HistoricalEntity(leader, led, historicalInput.Occurrence, historicalInput.Commentary); var inserted = await historicalsRepository.Insert(historical); if (!inserted) { throw new ApiException(HttpStatusCode.InternalServerError, HistoricalsMessages.Insert(historical.Leader.Email, historical.Led.Email, historical.Occurrence)); } return(historical); }
public async Task <bool> Update(HistoricalEntity historicalEntity) { var historicalModel = historicalEntity.ToModel(); var rowsAffected = await historicalsDatabase.Update(historicalModel); return(rowsAffected == 1); }
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); }