コード例 #1
0
ファイル: StoreWriteBase.cs プロジェクト: drmturhan/psg
        public async virtual Task <Sonuc <TEntity> > SilAsync(TEntity entity, CancellationToken cancellationToken = default(CancellationToken))
        {
            KayitSonuc <TEntity> sonuc = null;

            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            try
            {
                Context.Remove(entity);
                await SaveChanges(cancellationToken);

                //sonuc = Sonuc<TEntity>.Tamam;
                sonuc.DonenNesne = entity;
            }
            catch (DbUpdateConcurrencyException)
            {
                return(Sonuc <TEntity> .Basarisiz(HataTanimlayici.ConcurrencyFailure()));
            }
            catch (Exception hata)
            {
                return(Sonuc <TEntity> .Basarisiz(new List <Hata> {
                    new Hata {
                        Kod = "KimligeGoreKisiBulma", Tanim = $"Kayıt aranırken hata oluştu:{hata.Message}"
                    }
                }.ToArray()));
            }
            return(sonuc);
        }
コード例 #2
0
        public static KayitSonuc <TSource> ShapeData <TSource>(this KayitSonuc <TSource> source, string fields = null)
        {
            if (source == null)
            {
                throw new ArgumentNullException("kaynak boş olamaz1");
            }
            var dataShapedObject = new ExpandoObject();

            if (string.IsNullOrWhiteSpace(fields))
            {
                return(source);
            }
            var propertyInfoList = new List <PropertyInfo>();
            var fieldsAfterSplit = fields.Split(',');

            foreach (var field in fieldsAfterSplit)
            {
                var propertyName = field.Trim();
                var propertyInfo = typeof(TSource).GetProperty(propertyName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
                if (propertyInfo == null)
                {
                    throw new Exception($"Proeprty {propertyName} wasn't found on {typeof(TSource)}.");
                }
                propertyInfoList.Add(propertyInfo);
            }

            foreach (var propertyInfo in propertyInfoList)
            {
                var propertyValue = propertyInfo.GetValue(source.DonenNesne);
                dataShapedObject.TryAdd(propertyInfo.Name, propertyValue);
            }
            source.DonenNesne            = default(TSource);
            source.DonenSekillenmisNesne = dataShapedObject;
            return(source);
        }
コード例 #3
0
        public new static KayitSonuc <TEntity> Basarisiz(params Hata[] errors)
        {
            var result = new KayitSonuc <TEntity> {
                Basarili = false
            };

            if (errors != null)
            {
                result._errors.AddRange(errors);
            }
            return(result);
        }