public async Task <IActionResult> UpdateCharacteristic(UpdatedCharacteristicDto updatedCharacteristic) { ServiceResponse <GetCharacteristicDto> response = await _characteristicService.UpdateCharacteristic(updatedCharacteristic); if (response.Data == null) { return(NotFound(response)); } else { return(Ok(response)); } }
public async Task <ServiceResponse <GetCharacteristicDto> > UpdateCharacteristic(UpdatedCharacteristicDto updatedCharacteristic) { ServiceResponse <GetCharacteristicDto> serviceResponse = new ServiceResponse <GetCharacteristicDto>(); try { Characteristic Characteristic = await _context.Characteristics.Include(c => c.User).AsNoTracking().FirstOrDefaultAsync(c => c.Id == updatedCharacteristic.Id); Characteristic mappedUpdated = _mapper.Map <Characteristic>(updatedCharacteristic); if (Characteristic.User.Id == GetUserId()) { Characteristic = Utility.Util.CloneJson <Characteristic>(mappedUpdated); _context.Characteristics.Update(Characteristic); await _context.SaveChangesAsync(); serviceResponse.Data = _mapper.Map <GetCharacteristicDto>(Characteristic); } else { serviceResponse.Success = false; serviceResponse.Message = "Record not found."; } } catch (Exception ex) { serviceResponse.Success = false; serviceResponse.Message = ex.Message; } return(serviceResponse); }