Пример #1
0
        public async Task <Guid> CreateAsync(ClaimTypeParam model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var items = await _repository.ListAsync(new ClaimTypeByName(model.Name));

            var entity = items.Count > 0 ? items[0] : null;

            if (entity == null)
            {
                // create new entity
                var newEntity = ClaimType.Create(
                    model.Name,
                    model.ClaimValueType,
                    model.Description
                    );
                await _repository.AddAsync(newEntity);

                return(newEntity.Id);
            }

            // update existing entity
            model.Id = entity.Id;
            SimpleMapper.Map(model, entity);
            await _repository.UpdateAsync(entity);

            return(entity.Id);
        }
Пример #2
0
        public async Task UpdateAsync(ClaimTypeParam model)
        {
            if (!model.Id.HasValue)
            {
                throw new InvalidOperationException(nameof(model.Id));
            }

            var entity = await _repository.GetByIdAsync(model.Id.Value);

            SimpleMapper.Map(model, entity);

            await _repository.UpdateAsync(entity);
        }