コード例 #1
0
 public static async Task <int> GetNextIdConfigItemExtentionValueAsync(AddConfigGenericItemExtentionValueRequestDto request, ColonyManagerDbContext dbContext)
 {
     return(await dbContext.Set <ConfigGenericItemExtensionValue>()
            .Where(x => x.GroupId == request.GroupId && x.ItemId == request.ItemId && x.ExtentionId == request.ExtentionId)
            .DefaultIfEmpty()
            .MaxAsync(x => (int?)x.Id) + 1 ?? 1);
 }
 public async Task <ConfigGenericItemExtentionValueDto> AddConfigGenericItemExtentionValueAsync([FromBody] AddConfigGenericItemExtentionValueRequestDto request)
 {
     return(await _configGenericItemExtentionValueService.AddConfigGenericItemExtentionValueAsync(request, Account?.FullName));
 }
        public async Task <ConfigGenericItemExtentionValueDto> AddConfigGenericItemExtentionValueAsync(AddConfigGenericItemExtentionValueRequestDto request, string userName)
        {
            _logger.LogDebug($"Add new config generic item extention value. Request : {JsonConvert.SerializeObject(request)}");

            await _addValidator.ValidateAndThrowAsync(request);

            var entity = _mapper.Map <ConfigGenericItemExtensionValue>(request);

            entity.Id = await GetNextIdHelper.GetNextIdConfigItemExtentionValueAsync(request, _dbContext);

            entity.CreatedDate         = DateTime.Now;
            entity.LastUpdatedUserName = userName;

            _dbContext.ConfigGenericItemExtensionValues.Add(entity);
            await _dbContext.SaveChangesAsync();

            return(_mapper.Map <ConfigGenericItemExtentionValueDto>(entity));
        }