예제 #1
0
 public IQueryable <T> FindBy(Expression <Func <T, bool> > predicate)
 {
     try
     {
         using (var ctx = MMHContext.Create())
         {
             IQueryable <T> query = ctx.Set <T>().Where(predicate);
             return(query);
         }
     }
     catch (Exception ex)
     {
         //TODO:Logar exception
         throw new Exception(ex.ToString());
     }
 }
예제 #2
0
 public IQueryable <T> GetAll()
 {
     try
     {
         using (var ctx = MMHContext.Create())
         {
             IQueryable <T> query = ctx.Set <T>();
             return(query);
         }
     }
     catch (Exception ex)
     {
         //TODO:Logar exception
         throw new Exception(ex.ToString());
     }
 }
예제 #3
0
        /// <summary>
        /// Registers the type mappings with the Unity container.
        /// </summary>
        /// <param name="container">The unity container to configure.</param>
        /// <remarks>
        /// There is no need to register concrete types such as controllers or
        /// API controllers (unless you want to change the defaults), as Unity
        /// allows resolving a concrete type even if it was not previously
        /// registered.
        /// </remarks>
        public static void RegisterTypes(IUnityContainer container)
        {
            // NOTE: To load from web.config uncomment the line below.
            // Make sure to add a Unity.Configuration to the using statements.
            // container.LoadConfiguration();

            // TODO: Register your type's mappings here.
            // container.RegisterType<IProductRepository, ProductRepository>();

            container.RegisterType <MMHContext>();
            container.RegisterType <ApplicationSignInManager>();
            container.RegisterType <ApplicationUserManager>();
            container.RegisterType <IAuthenticationManager>(
                new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication));
            container.RegisterType <IUserStore <Advertiser>, UserStore <Advertiser> >(
                new InjectionConstructor(MMHContext.Create()));
            container.RegisterType <IDonnationAdRepository, DonnationAdRepository>();
            container.RegisterType <IDonnationAdService, DonnationAdService>();
        }
예제 #4
0
        public virtual bool Delete(T entity)
        {
            if (entity == null)
            {
                return(false);
            }

            try
            {
                using (var ctx = MMHContext.Create())
                {
                    ctx.Set <T>().Remove(entity);
                    return(ctx.SaveChanges() > 0);
                }
            }
            catch (Exception ex)
            {
                //TODO: log exception
                throw new Exception(ex.ToString());
            }
        }
예제 #5
0
        public virtual bool Update(T entity)
        {
            if (entity == null)
            {
                return(false);
            }

            try
            {
                using (var ctx = MMHContext.Create())
                {
                    ctx.Entry(entity).State = EntityState.Modified;
                    return(ctx.SaveChanges() > 0);
                }
            }
            catch (Exception ex)
            {
                //TODO: log exception
                throw new Exception(ex.ToString());
            }
        }