Beispiel #1
0
 public virtual Guid Add <TProperty>(AddPropertyContext <TProperty> context) where TProperty : PropertyEntity
 {
     OnBefore(new RepositoryEventArgs {
         AccessDbContext = context
     });
     using (var db = context.ContextProvider.Provide())
     {
         if (context.Property.Id == Guid.Empty)
         {
             context.Property.Id = Guid.NewGuid();
         }
         context.Property.UserId = context.UserId;
         db.Set <TProperty>().Add(context.Property);
         var count = db.SaveChanges();
         OnComplete(new RepositoryEventArgs {
             AccessDbContext = context, Count = count
         });
         if (count > 0)
         {
             OnSuccess(new RepositoryEventArgs {
                 AccessDbContext = context, NewEntityId = context.Property.Id
             });
         }
         else
         {
             OnFail(new RepositoryEventArgs {
                 AccessDbContext = context, ErrorMessage = "添加失败"
             });
         }
         return(context.Property.Id);
     }
 }
        public Guid Add(TPropertyEntity model)
        {
            var repository = _repositoryProviderProvider.Provide <IPropertyAddRepository>().Provide();
            var property   = Mapper.Map <TPropertyEntity>(model);
            var context    = new AddPropertyContext <TPropertyEntity>
            {
                ContextProvider = _contextProvider,
                Property        = property,
                UserId          = UserContext.Current.UserId
            };

            return(repository.Add(context));
        }