public async Task <LogTimeRecordDto> LogTimeAsync(string userName, AddLogTimeRecordDto dto) { var record = await Repository.ReadAsync(dto.TimeRecordId); var user = await _userRepository.SingleAsync(s => s.UserName == userName); if (record == null || user == null) { throw new BadRequestException("Invalid time recoder or user."); } var logTimeEntity = dto.ToEntity(); logTimeEntity.Id = UUID; logTimeEntity.UserId = user.Id; logTimeEntity.User = user; var logTimeRecords = record.LogTimeRecords ?? new List <LogTimeRecord>(); logTimeRecords.Add(logTimeEntity); record.LogTimeRecords = logTimeRecords; await UpdateAsync(record); return(logTimeEntity?.ToDto()); }
public async Task <IActionResult> LogTime([FromBody] AddLogTimeRecordDto dto) { var validator = CheckValidation(dto); if (!validator.IsValid) { throw new BadRequestException(validator.Errors); } var result = await _timeRecordService.LogTimeAsync(User.Identity.Name, dto); return(ResultOk(result)); }
// Log time record public static LogTimeRecord ToEntity(this AddLogTimeRecordDto dto) { return(Mapper.Map <LogTimeRecord>(dto)); }