public async Task <IActionResult> Create([FromBody] AddTimeRecordDto dto)
        {
            var validator = CheckValidation(dto);

            if (!validator.IsValid)
            {
                throw new BadRequestException(validator.Errors);
            }

            var result = await _timeRecordService.CreateAsync(User.Identity.Name, dto);

            return(ResultOk(result));
        }
예제 #2
0
        public async Task <TimeRecordDto> CreateAsync(string userName, AddTimeRecordDto dto)
        {
            var project = await _projectRepository.SingleAsync(s => s.Name == dto.ProjectId);

            var user = await _userRepository.SingleAsync(s => s.UserName == userName);

            if (project == null ||
                user == null)
            {
                throw new BadRequestException("Invalid project or user.");
            }

            ILocationService locationService = new LocationService();

            var location = await locationService.GetLocactionAsync(AppContext.Value.Connection.RemoteIpAddress.MapToIPv4().ToString());

            var entity = dto.ToEntity();

            entity.SetAudit(AppContext.Value);

            entity.ProjectId = project.Id;

            entity.Project = project;

            entity.UserId = user.Id;

            entity.User = user;

            entity.LogTimeRecords = new List <LogTimeRecord>();

            entity.CapturedInfo = location?.ObjToJson();

            entity = await CreateAsync(entity);

            return(entity?.ToDto());
        }
 public static TimeRecord ToEntity(this AddTimeRecordDto dto)
 {
     return(Mapper.Map <TimeRecord>(dto));
 }