예제 #1
0
        public async Task <IActionResult> ExecuteAsync(SaveSystemSetting saveSystemSetting, CancellationToken cancellationToken)
        {
            if (await _systemSettingGroupRepository.Get(saveSystemSetting.GroupId, cancellationToken) == null)
            {
                return(new NotFoundResult());
            }

            var systemSetting = await _systemSettingRepository.GetByKey(saveSystemSetting.Key, cancellationToken);

            if (systemSetting != null)
            {
                return(new NotFoundResult());
            }
            systemSetting = _saveSystemSettingToSystemSettingMapper.Map(saveSystemSetting);

            //var user = _httpContextAccessor.HttpContext.User;
            //if (user == null)
            //    return new NotFoundResult();

            //var claims = user.Claims.ToList();
            //if (claims.Count < 1)
            //    return new NotFoundResult();
            //// Lấy Id của người dùng
            //var userId = claims.FirstOrDefault(claimRecord => claimRecord.Type == "sub")?.Value;

            //systemSetting.CreatedBy = userId;
            //systemSetting.ModifiedBy = userId;

            systemSetting = await _systemSettingRepository.Add(systemSetting, cancellationToken);

            var systemSettingViewModel = _systemSettingToSystemSettingMapper.Map(systemSetting);

            return(new CreatedAtRouteResult(
                       SystemSettingsControllerRoute.GetSystemSetting,
                       new { systemSettingViewModel.Key },
                       systemSettingViewModel));
        }
 public Task <IActionResult> Post(
     [FromServices] IPostSystemSettingCommand command,
     [FromBody] SaveSystemSetting systemSetting,
     CancellationToken cancellationToken) => command.ExecuteAsync(systemSetting);