示例#1
0
 public void Delete <TPropertyValueEntity>(DeletePropertyValueContext <TPropertyValueEntity> context)
     where TPropertyValueEntity : PropertyValueEntity
 {
     using (var db = context.ContextProvider.Provide())
     {
         var predicate = context.CreatePredicate();
         var values    = db.Set <TPropertyValueEntity>()
                         .Where(s => s.UserId == context.UserId)
                         .Where(predicate)
                         .ToList();
         OnBefore(new RepositoryEventArgs
         {
             AccessDbContext = context,
             Instances       = values
         });
         if (context.IsCancel)
         {
             return;
         }
         if (values.Any())
         {
             db.Set <TPropertyValueEntity>().RemoveRange(values);
         }
         var count = db.SaveChanges();
         OnComplete(new RepositoryEventArgs
         {
             AccessDbContext = context,
             Count           = count,
             Instances       = values
         });
         if (count > 0)
         {
             OnSuccess(new RepositoryEventArgs
             {
                 AccessDbContext = context,
                 Count           = count,
                 Instances       = values
             });
         }
         else
         {
             OnFail(new RepositoryEventArgs
             {
                 AccessDbContext = context,
                 Count           = count,
                 Instances       = values
             });
         }
     }
 }
        private void DeleteProperty_SuccessEvent(object sender, RepositoryEventArgs args)
        {
            var successContext = args.AccessDbContext as DeletePropertyContext <TPropertyEntity>;
            var context        = new DeletePropertyValueContext <TPropertyValueEntity>
            {
                ContextProvider = _contextProvider,
                InstanceId      = successContext.Id,
                IsCancel        = false,
                KeyProperty     = _propertyValueKeyProviderSelector.Select().Provide <TPropertyValueEntity>(),
                UserId          = UserContext.Current.UserId
            };
            var repository = _repositoryProviderProvider.Provide <IPropertyValueDeleteRepository>().Provide();

            repository.Delete(context);
        }