public async Task <IActionResult> Update([FromBody] MaintenanceHistoryRequestDto maintenanceHistory) { //Before updating find maintenance history by id var maintenanceHistoryData = await _uow.MaintenanceHistories.GetAsync(maintenanceHistory.ID); if (maintenanceHistoryData != null && maintenanceHistoryData.ID > 0) { //Map update data _mapper.Map(maintenanceHistory, maintenanceHistoryData); //Change Modified Data maintenanceHistoryData.ModifyDate = DateTime.Now; _uow.MaintenanceHistories.Update(maintenanceHistoryData); var result = await _uow.CompleteAsync(); if (result > 0) { //get maintenance history proper data var maintenanceHistoryDetails = await _uow.MaintenanceHistories.GetWithAllRelationsAsync(maintenanceHistory.ID); //Before returning updated Maintenance History data, map Maintenacne History => MaintenanceHistorySharedDto return(Ok(_mapper.Map <MaintenanceHistorySharedDto>(maintenanceHistoryDetails))); } else { return(new JsonResult(new { Success = false, Message = "Maintenance History type changes are not updated" })); } } else { return(NotFound(new { Success = false, Message = "Maintenance History not found with sended details." })); } }
public async Task <MaintenanceHistorySharedDto> Create([FromBody] MaintenanceHistoryRequestDto maintenanceHistory) { //Map dto Maintenance History object var mappedMaintenanceHistoryData = _mapper.Map <MaintenanceHistory>(maintenanceHistory); //Add not mapped fields mappedMaintenanceHistoryData.CreateDate = DateTime.Now; mappedMaintenanceHistoryData.ModifyDate = DateTime.Now; mappedMaintenanceHistoryData.IsDeleted = false; var maintenanceHistoryDetails = await _uow.MaintenanceHistories.AddAsync(mappedMaintenanceHistoryData); var result = await _uow.CompleteAsync(); if (result > 0) { //Get proper maintenance history data var properModelForMapping = await _uow.MaintenanceHistories.GetWithAllRelationsAsync(maintenanceHistoryDetails.ID); //Map Maintenance History => MaintenanceHistorySharedDto var resultVehicleType = _mapper.Map <MaintenanceHistorySharedDto>(properModelForMapping); return(resultVehicleType); } else { return(null); } }