Пример #1
0
        public Task <Result <Guid> > Add(CreateFeatureModel model)
        => Result <Guid> .TryAsync(async() =>
        {
            var duplicateFeature =
                await _repository.FirstOrDefaultAsNoTrackingAsync <Feature>(f => f.Name == model.Name);
            if (duplicateFeature.Success && duplicateFeature.Data != null)
            {
                return(Result <Guid> .Failed(Error.WithData(1000, new[] { "Duplicate Feature Name" })));
            }

            var permissionIds = model.Permissions;
            var resultList    = await _repository.ListAsync <Permission>(f => permissionIds.Contains(f.Id));
            if (!resultList.Success || resultList.Data == null)
            {
                return(Result <Guid> .Failed(Error.WithCode(ErrorCodes.InvalidModel)));
            }

            var permissions = resultList.Data;
            if (permissions.Count != permissionIds.Count())
            {
                return(Result <Guid> .Failed(Error.WithCode(ErrorCodes.InvalidModel)));
            }

            var featureId = Guid.NewGuid();
            var feature   = new Feature
            {
                Id = featureId, Name = model.Name,
                FeaturePermission = permissions.Select(f => new FeaturePermission
                {
                    FeatureId = featureId, PermissionId = f.Id, Id = Guid.NewGuid()
                }).ToList()
            };
            _repository.Add(feature);
            await _repository.CommitAsync();
            return(Result <Guid> .Successful(featureId));
        });
 public async Task <Result <Guid> > Add(CreateFeatureModel model)
 => await _membershipServiceApi.MembershipFeatureApiService.Add(model);
Пример #3
0
 public async Task <Result <Guid> > Add(CreateFeatureModel model)
 => await _featureBiz.Add(model);