Beispiel #1
0
        //   public readonly string ConnectionStringLocalTransaction = ConfigurationManager.ConnectionStrings["ConnOracleWithAddress"] == null ? "Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 180.166.173.214)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = dswms)));Persist Security Info=True;User ID=c##dswms;Password=c##dswms;" : ConfigurationManager.ConnectionStrings["ConnOracleWithAddress"].ConnectionString;//防止空引用异常 modify by gzw 181227

        /// <summary>
        /// 数据库工厂构造函数
        /// </summary>
        /// <param name="dbtype">数据库枚举</param>
        public DbFactory(DbFactoryType dbtype)
        {
            switch (dbtype)
            {
            case DbFactoryType.SQLSERVER:
                dbF = new SqlServerFactory
                {
                    ConnStr = ConnectionStringLocalTransaction
                };    // 数据库连接字符
                //SqlConnection connection = (SqlConnection)dbF.CreateConnection();
                //SqlBulkCopy
                //connection.BulkCopy
                break;

            case DbFactoryType.ROACLE:
                dbF = new OracleFactory
                {
                    ConnStr = ConnectionStringLocalTransaction
                };
                break;

            case DbFactoryType.MYSQL:
                dbF = new MySqlFactory
                {
                    ConnStr = ConnectionStringLocalTransaction
                };

                MySqlConnection connection = (MySqlConnection)dbF.CreateConnection();

                break;
            }
        }
Beispiel #2
0
        public RootModule(IDBFactory dbFactory)
            : base(dbFactory)
        {
            Get["/"] = parameters =>
            {
                var photos = DB.Photos.FindAllByPublished(true).OrderByDatePublishedDescending().Take(2);
                List<Models.Photo> photoList = photos.ToList<Models.Photo>();

                if (photoList.Count > 0)
                {
                    var model = new Models.PhotoDetail();
                    model.Photo = photoList[0];
                    model.NextSlug = String.Empty;

                    if (photoList.Count > 1) model.PreviousSlug = photoList[1].Slug;
                    else model.PreviousSlug = String.Empty;

                    IEnumerable<Models.Comment> comments = DB.Comments.FindAll(DB.Comments.PhotoId == model.Photo.Id && DB.Comments.Approved == true).Cast<Models.Comment>();
                    if (comments != null) model.Comments = comments.ToList();

                    return View["photodetail", model];
                }
                else
                {
                    return View["nophoto"];
                }
            };
        }
        public AuthenticationModule(IAuthenticationService authenticationservice,IUsernameMapper usernameMapper,IDBFactory DBFactory)
            : base("/authentication",DBFactory)
        {
            Post["/login"] = x =>
            {
                var nerd = authenticationservice.GetLogin(Request.Form.Username, Request.Form.Password);

                if (nerd == null)
                    return Response.AsRedirect("/login?msg=Invalid%20username%20or%20password");

                DateTime? expiry = null;
                if (this.Request.Form.RememberMe.HasValue)
                {
                    expiry = DateTime.Now.AddDays(7);
                }

                Guid guid = Guid.Parse(nerd.Guid);
                return this.LoginAndRedirect(guid, expiry);
            };

            Get["/logout"] = x =>
            {
                return this.LogoutAndRedirect("/");
            };
        }
Beispiel #4
0
 public RootModule(IDBFactory DBFactory)
     : base(DBFactory)
 {
     Get["/"] = x => {
         return View["root_index",Model];
     };
 }
Beispiel #5
0
 public void connect(IDBFactory db_factory, string connection_string)
 {
     m_dbFactory  = db_factory;
     m_Connection = m_dbFactory.CreateConnection(connection_string);
     m_Connection.Open();
     dbPropertyInfoManager.Instance.setDbFactory(m_dbFactory);
 }
        public HomeModule(IDBFactory dbFactory) : base(dbFactory, "/api")
        {
            Get["/puntos/{empresa}/{id}/{extension}"] = x =>
            {
                Punto response = AccountHelper.GetPuntos(x, dbFactory.DB());

                if (x.extension == "json")
                {
                    return(Response.AsJson(response));
                }
                else
                {
                    return(Response.AsXml(response));
                }
            };

            Get["/movimientos/{empresa}/{id}/{extension}"] = x =>
            {
                IList <Movimiento> response = AccountHelper.GetMovimientos(x, dbFactory.DB());

                if (x.extension == "json")
                {
                    return(Response.AsJson(response));
                }
                else
                {
                    return(Response.AsXml(response));
                }
            };

            Get["/puntos/{origen}/{empresa}/{id}/{anio}/{extension}"] = x =>
            {
                return(GetPuntos(x));
            };

            Get["/movimientos/{origen}/{empresa}/{id}/{anio}/{extension}"] = x =>
            {
                return(GetMovimientos(x));
            };

            Get["/puntos/{origen}/{empresa}/{id}/{extension}"] = x =>
            {
                return(GetPuntos(x));
            };

            Get["/movimientos/{origen}/{empresa}/{id}/{extension}"] = x =>
            {
                return(GetMovimientos(x));
            };


            Get["/importador"] = x =>
            {
                return(string.Format("Directiorio de operaciones:{0}",
                                     string.Format(@"{0}{1}\", Path.GetDirectoryName(typeof(Bootstrapper).Assembly.CodeBase)
                                                   .Replace(@"file:\", string.Empty)
                                                   .Replace("bin", string.Empty), "inbox")));
            };
        }
Beispiel #7
0
 public EFUnitOfWork(IDBFactory dbFactory)
 {
     Context             = dbFactory.GetContext();
     _transactionOptions = new TransactionOptions
     {
         IsolationLevel = IsolationLevel.ReadCommitted
     };
 }
Beispiel #8
0
 public dbPropertyInfo(PropertyInfo p, object o, IDBFactory db_factory)
 {
     m_dbFactory    = db_factory;
     m_Object       = o;
     m_PropertyInfo = p;
     m_dbAttribute  = null;
     parse();
 }
Beispiel #9
0
 public ValueTask set_webkitIndexedDB(IDBFactory value)
 {
     __webkitIndexedDB = null;
     return(EventHorizonBlazorInterop.Set(
                this.___guid,
                "webkitIndexedDB",
                value
                ));
 }
Beispiel #10
0
        public AdminModule(IDBFactory dbFactory) : base(dbFactory, "/admin")
    {
        Get["/photos"] = parameters =>
        {
            return "A list of all the photo's.";
        };
 
        Get["/photos/add"] = parameters =>
        {
            return "Display the form to add a photo.";
        };
 
        Post["/photos/add"] = parameters =>
        {
            // Add the photo, then redirect
            string slug = "newPhoto";
            return Response.AsRedirect("/admin/photos/edit/" + slug);
        };
 
        Get["/photos/edit/{slug}"] = parameters =>
        {
            return String.Format("Display the form to edit a photo called '{0}'.",
                parameters.slug);
        };
 
        Post["/photos/edit/{slug}"] = parameters =>
        {
            // Edit the photo, then redirect
            string slug = Convert.ToString(parameters.slug);
            return Response.AsRedirect("/admin/photos/edit/" + slug);
        };
 
        Get["/photos/delete/{slug}"] = parameters =>
        {
            return String.Format("Are you sure you want to delete the photo called '{0}'?",
                parameters.slug);
        };
 
        Post["/photos/delete/{slug}"] = parameters =>
        {
            // Delete the photo, then redirect
            return Response.AsRedirect("/admin/photos");
        };
 
        Get["/comments"] = parameters =>
        {
            return "A list of all the comments.";
        };
 
        Post["/comments/delete/{id}"] = parameters =>
        {
            // Delete the comment, then redirect
            return Response.AsRedirect("/admin/comments");
        };
        
       }
Beispiel #11
0
        public AdminModule(IDBFactory dbFactory) : base(dbFactory, "/admin")
        {
            Get["/photos"] = parameters =>
            {
                return("A list of all the photo's.");
            };

            Get["/photos/add"] = parameters =>
            {
                return("Display the form to add a photo.");
            };

            Post["/photos/add"] = parameters =>
            {
                // Add the photo, then redirect
                string slug = "newPhoto";
                return(Response.AsRedirect("/admin/photos/edit/" + slug));
            };

            Get["/photos/edit/{slug}"] = parameters =>
            {
                return(String.Format("Display the form to edit a photo called '{0}'.",
                                     parameters.slug));
            };

            Post["/photos/edit/{slug}"] = parameters =>
            {
                // Edit the photo, then redirect
                string slug = Convert.ToString(parameters.slug);
                return(Response.AsRedirect("/admin/photos/edit/" + slug));
            };

            Get["/photos/delete/{slug}"] = parameters =>
            {
                return(String.Format("Are you sure you want to delete the photo called '{0}'?",
                                     parameters.slug));
            };

            Post["/photos/delete/{slug}"] = parameters =>
            {
                // Delete the photo, then redirect
                return(Response.AsRedirect("/admin/photos"));
            };

            Get["/comments"] = parameters =>
            {
                return("A list of all the comments.");
            };

            Post["/comments/delete/{id}"] = parameters =>
            {
                // Delete the comment, then redirect
                return(Response.AsRedirect("/admin/comments"));
            };
        }
Beispiel #12
0
        public HomeModule(IDBFactory dbFactory):base(dbFactory ,"/api")
        {

            Get["/puntos/{empresa}/{id}/{extension}"] = x =>
            {
                Punto response= AccountHelper.GetPuntos(x,dbFactory.DB());

                if (x.extension == "json")
                    return Response.AsJson(response);
                else
                    return Response.AsXml(response);
            };

            Get["/movimientos/{empresa}/{id}/{extension}"] = x =>
            {
                IList<Movimiento> response = AccountHelper.GetMovimientos(x, dbFactory.DB());

                if (x.extension == "json")
                    return Response.AsJson(response);
                else
                    return Response.AsXml(response);
            };
            
            Get["/puntos/{origen}/{empresa}/{id}/{anio}/{extension}"] = x =>
            {
                return GetPuntos(x);
            };

            Get["/movimientos/{origen}/{empresa}/{id}/{anio}/{extension}"] = x =>
            {
                return GetMovimientos(x);
            };

            Get["/puntos/{origen}/{empresa}/{id}/{extension}"] = x =>
            {
                return GetPuntos(x);
            };

            Get["/movimientos/{origen}/{empresa}/{id}/{extension}"] = x =>
            {
                return GetMovimientos(x);
            };


            Get["/importador"] = x =>
            {
                return string.Format("Directiorio de operaciones:{0}",
                    string.Format(@"{0}{1}\", Path.GetDirectoryName(typeof(Bootstrapper).Assembly.CodeBase)
                    .Replace(@"file:\", string.Empty)
                    .Replace("bin", string.Empty),"inbox"));
            };
           
        }
Beispiel #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParametrizedCommandBuilder"/> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        public CommandBuilder(IDBFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            _factory            = factory;
            _convertor          = factory.Convertor;
            command             = _factory.CreateCommand();
            command.CommandType = CommandType.Text;
        }
Beispiel #14
0
        static BaseBindings()
        {
            SettingsReader   = new SettingsLibReader();
            _DbFactory       = new MsSqlFactory(SettingsReader.GetDbAccessSettings());
            _CooksManager    = new CookieMananger();
            _UsrStateManager = new UserAuthenticateStateManager(_DbFactory, _CooksManager);

            _LogConfiguration = new BasicNLogConfig(SettingsReader.GetLogDirectory());
            _LogConfiguration.InitConfig();

            _Lg = LogManager.GetCurrentClassLogger();
            _Lg.Info("Basic bindings initialized successguly.");
        }
Beispiel #15
0
 /// <summary>Initialize a user's manager.</summary>
 /// <param name="dbFactory">Provider to database</param>
 /// <exception cref="ArgumentNullException">Passed an empty parameter.</exception>
 public UserAuthenticateStateManager(IDBFactory dbFactory, ICookiesManager cookiesManager)
 {
     if (dbFactory == null)
     {
         throw new ArgumentNullException(nameof(dbFactory));
     }
     if (cookiesManager == null)
     {
         throw new ArgumentNullException(nameof(cookiesManager));
     }
     _DatabaseFactory = dbFactory;
     _CookiesManager  = cookiesManager;
 }
Beispiel #16
0
        public MainModule(IDBFactory dbFactory)
            : base(dbFactory)
        {
            Get["/"] = _ =>
            {
                var postList = GetPostList(1);

                dynamic model = new
                {
                    postList = (dynamic) postList,
                    currentPage =(dynamic) 1,
                    hasNext = true,
                    hasPrevious = false,
                };

                return View["Home", model];
            };

            Get[@"/page/(?<id>[\d]{1,2})"] = _ =>
            {
                int page = (int) _.id;

                var postList = GetPostList(page);

                dynamic model = new
                {
                    postList,
                    currentPage = _.id,
                    hasNext = true,
                    hasPrevious = true,
                };

                return View["Home", model];
            };

            Get["/post/{slug}"] = _ =>
            {
                var model = (Post)DB.Post.FindBySlug(_.slug);
                model.Content = new Markdown().Transform(model.Content);
                return View["Post", model];
            };

            Get[@"/(?<page>[a-z]+)"] = _ =>
            {
                var model = DB.Post.FindBySlugAndType(_.page,"page");
                model.Content = new Markdown().Transform(model.Content);
                return View["Page", model];
            };
        }
Beispiel #17
0
 public async ValueTask <IDBFactory> get_msIndexedDB()
 {
     if (__msIndexedDB == null)
     {
         __msIndexedDB = await EventHorizonBlazorInterop.GetClass <IDBFactory>(
             this.___guid,
             "msIndexedDB",
             (entity) =>
         {
             return(new IDBFactory()
             {
                 ___guid = entity.___guid
             });
         }
             );
     }
     return(__msIndexedDB);
 }
Beispiel #18
0
 public static IDBFactory MakeDBFactory()
 {
     if (dbFactory == null)
     {
         for (int i = 0; i < Settings.UserSettings.DBProviders.Count; i++)
         {
             if (Settings.UserSettings.DBProviders[i].Name == Settings.UserSettings.ProviderName)
             {
                 Assembly asm = Assembly.Load(Settings.UserSettings.DBProviders[i].Assembly);
                 dbFactory = (IDBFactory)asm.CreateInstance(Settings.UserSettings.DBProviders[i].FactoryClassName);
             }
         }
     }
     if (dbFactory == null)
     {
         throw new Exception("dbProviderName " + Settings.UserSettings.ProviderName + "is misspelled or has not been added");
     }
     return(dbFactory);
 }
Beispiel #19
0
        /// <summary>
        /// 根据DBID获取数据库访问连接池对象
        /// </summary>
        /// <param name="dbid">数据库编号ID</param>
        /// <returns>数据库访问连接对象</returns>
        internal static DbConnectionPool GetConnectionPoolByDBID(int dbid)
        {
            DbConnectionPool dbConnectionPool;

            if (!_dbConnectionPoolDic.TryGetValue(dbid, out dbConnectionPool))
            {
                var            config        = DatabaseConfigManager.GetConfig(dbid);
                IDBFactory     dbFactory     = DBFactoryManager.GetDBFactory(config);
                IDBInteraction dbInteraction = dbFactory.GetDBInteraction();
                AddDbConnectionPool(config, dbInteraction);

                if (!_dbConnectionPoolDic.TryGetValue(dbid, out dbConnectionPool))
                {
                    throw new ApplicationException(string.Format("连接池中不包含数据库编号ID为:{0}的连接信息", dbid));
                }
            }

            return(dbConnectionPool);
        }
        public AuthenticationModule(IDBFactory dbFactory) : base(dbFactory)
        {
            Get["/login"] = parameters =>
            {
                return("Display the login form");
            };

            Post["/login"] = parameters =>
            {
                // Perform validation, then redirect
                return(Response.AsRedirect("/admin/photos"));
            };

            Post["/logout"] = parameters =>
            {
                // Logout and redirect
                return(Response.AsRedirect("/login"));
            };
        }
        public AuthenticationModule(IDBFactory dbFactory)
            : base(dbFactory)
        {
            Get["/login"] = parameters =>
            {
                return "Display the loginform";
            };

            Post["/login"] = parameters =>
            {
                // Perform validation then redirect
                return Response.AsRedirect("/admin/photos");

            };

            Post["/logout"] = parameters =>
            {
                // logout and redirect
                return Response.AsRedirect("/login");
            };
        }
Beispiel #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DBConnection"/> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="connectionString">The connection string.</param>
 public DBConnection(IDBFactory factory, string connectionString)
 {
     if (string.IsNullOrEmpty(connectionString))
     {
         throw new ArgumentException("connectionString is empty", "connectionString");
     }
     Factory                      = factory;
     _convertor                   = factory.CreateConvertor();
     _exceptionConverter          = factory.CreateExceptionConvertor();
     _connection                  = factory.CreateConnection();
     Transaction                  = new Transaction(_connection);
     _connection.ConnectionString = connectionString;
     try
     {
         _connection.Open();
     }
     catch (SqlException ex)
     {
         Log.Fatal("Error open cobbection to ::" + connectionString, ex);
     }
 }
Beispiel #23
0
        static void Main(string[] args)
        {
            {
                Console.WriteLine("***************** function3 *****************");
                User        user       = new User();
                IDBOperator dBOperator = DB.CreateDBOperator();
                dBOperator.AddUser(user);
            }

            {
                Console.WriteLine("***************** function2 *****************");
                User  user = new User();
                IUser iu   = DataAccess.CreateUser();
                iu.AddUser(user);
            }

            {
                Console.WriteLine("***************** function1 *****************");
                IDBFactory db = null;
                Console.WriteLine("plz choose the db type.");
                var dbType = Console.ReadLine();
                if (Convert.ToInt32(dbType) == (int)DBType.SQLServer)
                {
                    db = new SQLServerDB();
                }
                if (Convert.ToInt32(dbType) == (int)DBType.MySQL)
                {
                    db = new MySQLDB();
                }
                User user = new User {
                    Id = "001", Name = "bo"
                };
                db.AddUser(user);
                db.DeleteUserById(user.Id);
                db.UpdateUserById(user.Id);
                db.QueryUserById(user.Id);
            }
        }
        /// <summary>
        /// 获取数据库访问实例
        /// </summary>
        /// <param name="dbid">数据库编号ID</param>
        /// <returns>数据库访问实例</returns>
        public static IDBAccess GetDBAccessInstance(int dbid)
        {
            IDBAccess dbAccess;

            if (!_dbAccessDic.TryGetValue(dbid, out dbAccess))
            {
                lock (_dicDBAccessLock)
                {
                    if (!_dbAccessDic.TryGetValue(dbid, out dbAccess))
                    {
                        var        dbBConfigItem = DatabaseConfigManager.GetConfig(dbid);
                        IDBFactory dbFactory     = DBFactoryManager.GetDBFactory(dbBConfigItem);
                        dbAccess = dbFactory.CreateDBAccess(dbBConfigItem);

                        if (!_dbAccessDic.TryAdd(dbid, dbAccess))
                        {
                            Loger.Warn(string.Format("添加数据库编号ID为{0}数据库访问实例失败", dbid), null);
                        }
                    }
                }
            }

            return(dbAccess);
        }
Beispiel #25
0
        public RootModule(IDBFactory dbFactory) : base(dbFactory)
        {
            Get["/"] = parameters =>
            {
                var photos = DB.Photos.FindAllByPublished(true).OrderByDatePublishedDescending().Take(2);
                List <Models.Photo> photoList = photos.ToList <Models.Photo>();

                if (photoList.Count > 0)
                {
                    var model = new Models.PhotoDetail();
                    model.Photo    = photoList[0];
                    model.NextSlug = String.Empty;

                    if (photoList.Count > 1)
                    {
                        model.PreviousSlug = photoList[1].Slug;
                    }
                    else
                    {
                        model.PreviousSlug = String.Empty;
                    }

                    IEnumerable <Models.Comment> comments = DB.Comments.FindAll(DB.Comments.PhotoId == model.Photo.Id && DB.Comments.Approved == true).Cast <Models.Comment>();
                    if (comments != null)
                    {
                        model.Comments = comments.ToList();
                    }

                    return(View["photodetail", model]);
                }
                else
                {
                    return(View["nophoto"]);
                }
            };
        }
Beispiel #26
0
        public BeerEventModule(IDBFactory DBFactory)
            : base("/BeerEvents",DBFactory)
        {
            // Read single
            Get["/single/{Id}"] = x =>
            {
                int id = x.Id;
                IEnumerable<Nerd> subscribedNerds = DB.Nerds.FindAll(DB.Nerds.NerdSubscriptions.EventId == id).Cast<Nerd>();
                Model.BeerEvent = DB.BeerEvents.FindById(id);
                Model.Subscribers = subscribedNerds;
                Model.CanSubscribe = !subscribedNerds.Any(n=>n.Guid == Model.Nerd.Guid);
                Model.CanEdit = !subscribedNerds.Any();
                Model.Comments = DB.Comments.FindAllByEventId(id);
                return View["beerevents_detail",Model];
            };

            // Create
            Post["/create"] = x =>
            {
                var be = new BeerEvent()
                {
                    Name = Request.Form.Name,
                    Location = Request.Form.Location,
                    EventDate = Request.Form.EventDate
                };
                var res = DB.BeerEvents.Insert(be);
                return RedirectToBeerEvent(res.Id);
            };

            // Update
            Post["/update/{Id}"] = x =>
            {
                var be = new BeerEvent
                {
                    Id = x.Id,
                    Name = Request.Form.Name,
                    Location = Request.Form.Location,
                    EventDate = Request.Form.EventDate
                };
                DB.BeerEvents.Update(be);
                return RedirectToBeerEvent(be.Id);
            };

            // Delete
            Get["/delete/{Id}"] = x =>
            {
                int id = (int)x.Id;
                IEnumerable<dynamic> subs = DB.NerdSubscriptions.FindAllByEventId(id);
                if (!subs.Any())
                {
                    DB.Comments.DeleteByEventId(id);
                    DB.BeerEvents.DeleteById(id);
                }
                return Response.AsRedirect("/");
            };

            // Comments
            Post["/{Id}/comments/create"] = x =>
            {
                var be = new Comment
                {
                    NerdId = Model.Nerd.Id,
                    EventId = x.Id,
                    CommentText = Request.Form.Comment,
                    Created = DateTime.Now
                };
                DB.Comments.Insert(be);
                return RedirectToBeerEvent(x.Id);
            };

            Get["/comments/delete/{Id}"] = x =>
            {
                Comment cmt = DB.Comments.FindById((int)x.Id);
                if (cmt.NerdId == Model.Nerd.Id)
                    DB.Comments.DeleteById(cmt.Id);
                return RedirectToBeerEvent(cmt.EventId);
            };

            // Subscriptions
            Post["/subscribe/{eventid}"] = x =>
            {
                DB.Nerds.UpdateById(Id: Model.Nerd.Id, Name: (string)Request.Form.Name);
                DB.NerdSubscriptions.Insert(NerdId: Model.Nerd.Id, EventId: (int)x.eventid);
                return RedirectToBeerEvent(x.eventid);
            };

            Get["/unsubscribe/{eventid}"] = x =>
            {
                var s = DB.NerdSubscriptions.FindByNerdIdAndEventId(Model.Nerd.Id, (int)x.eventid);
                if (s != null) DB.NerdSubscriptions.DeleteById(s.Id);
                return RedirectToBeerEvent(x.eventid);
            };
        }
Beispiel #27
0
        public AdminModule(IDBFactory dbFactory)
            : base(dbFactory,"/admin")
        {
            this.RequiresAuthentication();

            Get["/"] = _ =>  View["AdminHome"];

            Get["/content/{type}/add"] = _ => View["ContentAdd"];

            Post["/content/{type}/add"] = _ =>
            {
                var post = this.Bind<Post>("title", "slug","created","content");
                post.Type = _.type;
                post.Author = "willerce";
                DB.Post.Insert(post);

                return Response.AsRedirect("/admin/content/" + post.Type + "/");
            };

            Get["/content/{type}/edit/{id}"] = _ =>
            {
                var post = DB.Post.Get(_.id);
                return View["cONTENTEdit", post];
            };

            Post["/content/{type}/edit/{id}"] = _ =>
            {
                var id = (int)_.id;
                string type = _.type;
                if(id!=0)
                {
                    var post = this.Bind<Post>("title", "slug", "content", "created");
                    post.Type = type;
                    DB.Post.Update(post);
                }
                return Response.AsRedirect("/admin/content/" + type);
            };

            Get["/content/{type}/del/{id}"] = _ =>
            {
                var post = DB.Post.Get(_.id);
                if (post == null)
                {
                    return Response.AsRedirect("/admin");
                }
                DB.Post.DeleteById(post.Id);
                return Response.AsRedirect("/admin/content/" + (string)post.Type);

            };

            Get["/content/{type}/"] = _ =>
            {
                var currentPage = Request.Query.page.HasValue ? (int)Request.Query.page : 1;
                var type = _.type;
                var postList = GetPostList(currentPage, type);

                dynamic model = new
                {
                    postList,
                    type,
                    currentPage,
                    hasNext = true,
                    hasPrevious = currentPage > 1
                };

                return View["ContentHome", model];
            };

            #region Convert Wp to willog

            /*
            Get["/convert"] = _ =>
            {

                var wbDB =
                    Database.OpenConnection(
                        "server=127.0.0.1;user=root;database=willerce_blog;password=root;Charset=utf8;Allow Zero Datetime=true");

                var postlist = wbDB.wp_posts.All();

                foreach (var p in postlist)
                {
                    if (p.post_status == "publish" & p.post_type == "post")
                    {
                        DB.Post.Insert(new
                        {
                            Slug = p.post_name,
                            Title = p.post_title,
                            Content = p.post_content,
                            Created = Convert.ToDateTime(p.post_date),
                            Author = "willerce"
                        });
                    }
                }

                return Response.AsRedirect("/");
            };*/

            #endregion
        }
 public EntryStockRepository(IDBFactory databaseFactory)
     : base(databaseFactory)
 {
 }
 public SalesBillAdjAmtDetailRepository(IDBFactory databaseFactory)
     : base(databaseFactory)
 {
 }
Beispiel #30
0
 public UsernameMapper(IDBFactory DBFactory)
 {
     this.DB = DBFactory.DB();
 }
 public PhotoblogModule(IDBFactory dbFactory, string modulePath)
     : base(modulePath)
 {
     DB = dbFactory.DB();
 }
Beispiel #32
0
 internal AdoHelper(IDBFactory newdb)
 {
     db = newdb;
 }
Beispiel #33
0
        public MainModule(IDBFactory dbFactory)
            : base(dbFactory)
        {
            Get["/"] = _ =>
            {
                var postList = GetPostList(1, 5);

                var maxPage = GetMaxPage(5);
                dynamic model = new
                {
                    postList = (dynamic) postList,
                    currentPage =(dynamic) 1,
                    hasNext = maxPage > 1,
                    hasPrevious = false,
                    maxPage = maxPage
                };

                return View["Home", model];
            };

            Get[@"/page/(?<id>[\d]{1,2})"] = _ =>
            {

                int page = (int) _.id;

                var postList = GetPostList(page, 5);
                var maxPage = GetMaxPage(5);

                dynamic model = new
                {
                    postList,
                    currentPage = _.id,
                    hasNext = page < maxPage,
                    hasPrevious = page > 1,
                    maxPage = maxPage
                };

                return View["Home", model];
            };

            Get["/post/{slug}"] = _ =>
            {
                var model = DB.Post.FindBySlug(_.slug);
                var lastPostList = GetPostList(1, 5);
                model.Content = new Markdown().Transform(model.Content);
                model.LastPost = lastPostList;
                return View["Post", model];
            };

            Get["/feed"] = _ =>
            {
                var markDown = new Markdown();
                var list = GetPostList(1, 15);

                return View["Feed", list].WithContentType("application/xml");
            };

            Get[@"/(?<page>[a-z]+)"] = _ =>
            {
                var model = DB.Post.FindBySlugAndType(_.page, "page");
                model.Content = new Markdown().Transform(model.Content);
                return View["Page", model];
            };
        }
 public SqlPlayerRepository(IDBFactory dbFactory)
 {
     DB = dbFactory.DB();
 }
Beispiel #35
0
 public UnitOfWork(IDBFactory databaseFactory)
 {
     this._databaseFactory = databaseFactory;
 }
Beispiel #36
0
        public AdminModule(IDBFactory dbFactory) : base(dbFactory, "/admin")
        {
            this.RequiresAuthentication();

            Get["/"] = _ => View["AdminHome"];

            Get["/content/{type}/add"] = _ => View["ContentAdd"];

            Post["/content/{type}/add"] = _ =>
            {
                var post = this.Bind <Post>("title", "slug", "created", "content");
                post.Type   = _.type;
                post.Author = "willerce";
                DB.Post.Insert(post);

                return(Response.AsRedirect("/admin/content/" + post.Type + "/"));
            };

            Get["/content/{type}/edit/{id}"] = _ =>
            {
                var post = DB.Post.Get(_.id);
                return(View["cONTENTEdit", post]);
            };

            Post["/content/{type}/edit/{id}"] = _ =>
            {
                var    id   = (int)_.id;
                string type = _.type;
                if (id != 0)
                {
                    var post = this.Bind <Post>("title", "slug", "content", "created");
                    post.Type = type;
                    DB.Post.Update(post);
                }
                return(Response.AsRedirect("/admin/content/" + type));
            };

            Get["/content/{type}/del/{id}"] = _ =>
            {
                var post = DB.Post.Get(_.id);
                if (post == null)
                {
                    return(Response.AsRedirect("/admin"));
                }
                DB.Post.DeleteById(post.Id);
                return(Response.AsRedirect("/admin/content/" + (string)post.Type));
            };

            Get["/content/{type}/"] = _ =>
            {
                var currentPage = Request.Query.page.HasValue ? (int)Request.Query.page : 1;
                var type        = _.type;
                var postList    = GetPostList(currentPage, type);

                dynamic model = new
                {
                    postList,
                    type,
                    currentPage,
                    hasNext     = true,
                    hasPrevious = currentPage > 1
                };

                return(View["ContentHome", model]);
            };

            #region Convert Wp to willog

            /*
             * Get["/convert"] = _ =>
             * {
             *
             *  var wbDB =
             *      Database.OpenConnection(
             *          "server=127.0.0.1;user=root;database=willerce_blog;password=root;Charset=utf8;Allow Zero Datetime=true");
             *
             *  var postlist = wbDB.wp_posts.All();
             *
             *  foreach (var p in postlist)
             *  {
             *      if (p.post_status == "publish" & p.post_type == "post")
             *      {
             *          DB.Post.Insert(new
             *          {
             *              Slug = p.post_name,
             *              Title = p.post_title,
             *              Content = p.post_content,
             *              Created = Convert.ToDateTime(p.post_date),
             *              Author = "willerce"
             *          });
             *      }
             *  }
             *
             *  return Response.AsRedirect("/");
             * };*/

            #endregion
        }
Beispiel #37
0
 public GetCashRowsBySORepository(IDBFactory databaseFactory)
     : base(databaseFactory)
 {
 }
 public SalesOrderRepository(IDBFactory databaseFactory)
     : base(databaseFactory)
 {
 }
 public SqlLeagueRepository(IDBFactory factory)
 {
     DB = factory.DB();
 }
Beispiel #40
0
 public BaseModule(IDBFactory dbFactory,string path ):base(path)
 {
     DB=dbFactory.DB();
 }
Beispiel #41
0
 public UnitOfWork(IDBFactory databaseFactory)
 {
     this._databaseFactory = databaseFactory;
 }
 public PhotoblogModule(IDBFactory dbFactory)
     : base()
 {
     DB = dbFactory.DB();
 }
Beispiel #43
0
 public FakeUserMapper(IDBFactory DBFactory)
 {
     this.DB = DBFactory.DB();
 }
Beispiel #44
0
 public WillogModule(IDBFactory dbFactory)
 {
     DB = dbFactory.DB();
 }
Beispiel #45
0
 public NerdBeerModule(IDBFactory DBFactory)
 {
     DB = DBFactory.DB();
     SetupModelDefaults();
 }
Beispiel #46
0
        public ArchivesModule(IDBFactory dbFactory): base(dbFactory, "/archives")
        {
           Get[""] = parameters =>
        {
           List<DateTime> allDates = DB.Photos
                                .Query()
                                .Select(DB.Photos.DatePublished)
                                .Where(DB.Photos.Published == true)
                                .OrderByDatePublishedDescending()
                                .ToScalarList<DateTime>();
 
         var model = new GeneralArchives
                    {
                        Years = (from date in allDates
                                 group date by date.Year
                                 into yearGroup
                                 select new YearInfo
                                            {
                                                Year = yearGroup.Key,
                                                NumberOfPhotos = yearGroup.Count(),
                                                Months = (from yearDate in yearGroup
                                                          group yearDate by yearDate.Month
                                                          into monthGroup
                                                          select new MonthInfo
                                                                     {
                                                                         Month = monthGroup.Key,
                                                                         MonthName = monthGroup.First().ToString("MMMM"),
                                                                         NumberOfPhotos = monthGroup.Count()
                                                                     }).ToList()
                                            }).ToList()
                    };
 
        return View["general-archives", model];
      };
       
       Get[@"/(?<year>19[0-9]{2}|2[0-9]{3})"] = parameters =>
        {
        int year = Convert.ToInt32((string)parameters.year);
        DateTime start = new DateTime(year, 1, 1);
        DateTime end = start.AddYears(1);
 
        List<Photo> photos = DB.Photos
                           .FindAllByDatePublishedAndPublished(start.ToString("yyyy-MM-dd").to(end.ToString("yyyy-MM-dd")), true)
                           .OrderByDatePublished()
                           .ToList<Photo>();
 
       var model = new YearlyArchives
                    {
                        Photos = photos,
                        Year = year
                    };
 
        return View["yearly-archives", model];
    };
         Get[@"/(?<year>19[0-9]{2}|2[0-9]{3})/(?<month>[1-9]|1[012])"] = parameters =>
            {
                int year = Convert.ToInt32((string)parameters.year);
                int month = Convert.ToInt32((string)parameters.month);
                DateTime start = new DateTime(year, month, 1);
                DateTime end = start.AddMonths(1);

                List<Photo> photos = DB.Photos.FindAllByDatePublishedAndPublished(start.ToString("yyyy-MM-dd").to(end.ToString("yyyy-MM-dd")), true).OrderByDatePublished().ToList<Photo>();

                var model = new MonthlyArchives
                {
                    Photos = photos,
                    Month = start.ToString("MMMM yyyy")
                };

                return View["monthly-archives", model];
           };
        }
Beispiel #47
0
 public NerdBeerModule(string modulepath, IDBFactory DBFactory)
     : base(modulepath)
 {
     DB = DBFactory.DB();
     SetupModelDefaults();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="InsertCommandBuilder"/> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 public InsertCommandBuilder(IDBFactory factory)
     : base(factory)
 {
 }
 public PetaPocoUnitOfWork(IDBFactory dbFactory)
 {
     _dbFactory = dbFactory;
 }
 public OrderDetailRepository(IDBFactory dBFactory) : base(dBFactory)
 {
 }
Beispiel #51
0
        public AdminModule(IDBFactory dbFactory)
            : base(dbFactory,"/admin")
        {
            this.RequiresAuthentication();

            Get["/"] = _ =>
            {
                return View["AdminHome"];
            };

            Get["/post"] = _ =>
            {
                var page = Request.Query.page;

                var posts = GetPostList(Convert.ToInt32(page));
                return View["PostHome", posts];
            };

            Get["/post/add"] = _ => View["PostAdd"];

            Post["/post/add"] = _ =>
            {
                var post = this.Bind<Post>("title", "slug","created","content");
                post.Author = "willerce";
                DB.Post.Insert(post);

                return View["PostAdd"];
            };

            Get["/post/edit/{id}"] = _ =>
            {
                var post = DB.Post.Get(_.id);
                return View["PostEdit", post];
            };

            Post["/post/edit/{id}"] = _ =>
            {
                var id = (int)_.id;
                if(id!=0)
                {
                    var post = this.Bind<Post>("title", "slug", "content", "created");
                    DB.Post.Update(post);
                }
                return Response.AsRedirect("/admin/post");
            };

            Get["/convert"] = _ =>
            {

                var wbDB =
                    Database.OpenConnection(
                        "server=127.0.0.1;user=root;database=willerce_blog;password=root;Charset=utf8;Allow Zero Datetime=true");

                var postlist = wbDB.wp_posts.All();

                foreach (var p in postlist)
                {
                    if (p.post_status == "publish" & p.post_type == "post")
                    {
                        DB.Post.Insert(new
                        {
                            Slug = p.post_name,
                            Title = p.post_title,
                            Content = p.post_content,
                            Created = Convert.ToDateTime(p.post_date),
                            Author = "willerce"
                        });
                    }
                }

                return Response.AsRedirect("/");
            };
        }
Beispiel #52
0
 public BillPaymentItemRepository(IDBFactory databaseFactory)
     : base(databaseFactory)
 {
 }
 public AuthenticationService(IDBFactory DBFactory)
 {
     this.DB = DBFactory.DB();
 }
Beispiel #54
0
 public StateRepository(IDBFactory databaseFactory)
     : base(databaseFactory)
 {
 }
Beispiel #55
0
        public BeerEventModule(IDBFactory DBFactory)
            : base("/BeerEvents",DBFactory)
        {
            // Read single
            Get["/single/{Id}"] = x =>
            {
                int id = x.Id;
                List<dynamic> nerdssubscriptions = DB.NerdSubscriptions.FindAllByEventId(id).ToList();
                List<Nerd> subscribedNerds = new List<Nerd>();
                if (nerdssubscriptions.Count > 0)
                {
                    subscribedNerds = DB.Nerds.FindAllById(nerdssubscriptions.Select(y=>(int)y.NerdId).ToArray()).ToList<Nerd>();
                }
                Model.BeerEvent = DB.BeerEvents.FindById(id);
                Model.Subscribers = subscribedNerds;
                Model.CanSubscribe = !subscribedNerds.Any(n=>n.Guid == Model.Nerd.Guid);
                Model.CanEdit = !subscribedNerds.Any();
                List<Comment> comments =DB.Comments.FindAllByEventId(id).ToList<Comment>();
                List<Nerd> commentnerds =new List<Nerd>();
                if (comments.Count>0)
                {
                    commentnerds = DB.Nerds.FindAllById(comments.Select(y => y.NerdId).ToArray()).ToList<Nerd>();
                }
                foreach (var cmt in comments)
                    cmt.Nerd = commentnerds.Where(y => y.Id == cmt.NerdId).FirstOrDefault();
                Model.Comments = comments;
                return View["beerevents_detail",Model];
            };

            // Create
            Post["/create"] = x =>
            {
                BeerEvent be = this.Bind();
                var res = DB.BeerEvents.Insert(be);
                return RedirectToBeerEvent(res.Id);
            };

            // Update
            Post["/update/{Id}"] = x =>
            {
                BeerEvent be = this.Bind("id");
                be.Id = x.Id;
                DB.BeerEvents.Update(be);
                return RedirectToBeerEvent(be.Id);
            };

            // Delete
            Get["/delete/{Id}"] = x =>
            {
                int id = (int)x.Id;
                IEnumerable<dynamic> subs = DB.NerdSubscriptions.FindAllByEventId(id);
                if (!subs.Any())
                {
                    DB.Comments.DeleteByEventId(id);
                    DB.BeerEvents.DeleteById(id);
                }
                return Response.AsRedirect("/");
            };

            // Comments
            Post["/{Id}/comments/create"] = x =>
            {
                Comment comment = this.Bind("EventId", "NerdId", "Created");
                comment.EventId = x.Id;
                comment.Created = DateTime.Now;
                comment.NerdId = Model.Nerd.Id;
                DB.Comments.Insert(comment);
                return RedirectToBeerEvent(x.Id);
            };

            Get["/comments/delete/{Id}"] = x =>
            {
                Comment cmt = DB.Comments.FindById((int)x.Id);
                if (cmt.NerdId == Model.Nerd.Id)
                    DB.Comments.DeleteById(cmt.Id);
                return RedirectToBeerEvent(cmt.EventId);
            };

            // Subscriptions
            Post["/subscribe/{eventid}"] = x =>
            {
                DB.Nerds.UpdateById(Id: Model.Nerd.Id, Name: (string)Request.Form.Name);
                DB.NerdSubscriptions.Insert(NerdId: Model.Nerd.Id, EventId: (int)x.eventid);
                return RedirectToBeerEvent(x.eventid);
            };

            Get["/unsubscribe/{eventid}"] = x =>
            {
                var s = DB.NerdSubscriptions.FindByNerdIdAndEventId(Model.Nerd.Id, (int)x.eventid);
                if (s != null) DB.NerdSubscriptions.DeleteById(s.Id);
                return RedirectToBeerEvent(x.eventid);
            };
        }
Beispiel #56
0
 public InwardItemFromGodownRepository(IDBFactory databaseFactory)
     : base(databaseFactory)
 {
 }
Beispiel #57
0
        public PhotoModule(IDBFactory dbFactory)
            : base(dbFactory, "/photo")
        {
            Get["/{slug}"] = parameters =>
            {
                string slug = (string)parameters.slug;
                Models.Photo photo = DB.Photos.FindBySlug(slug);

                if (photo == null)
                {
                    // No photo found with this slug, we'll just redirect to the homepage
                    return Response.AsRedirect("/");
                }
                else
                {
                    var model = new Models.PhotoDetail();
                    model.Photo = photo;

                    model.PreviousSlug = DB.Photos.Query().Select(DB.Photos.Slug).Where(DB.Photos.Published == true && DB.Photos.DatePublished < photo.DatePublished.Value).OrderByDatePublishedDescending().Take(1).ToScalarOrDefault<string>();
                    model.NextSlug = DB.Photos.Query().Select(DB.Photos.Slug).Where(DB.Photos.Published == true && DB.Photos.DatePublished > photo.DatePublished.Value).OrderByDatePublished().Take(1).ToScalarOrDefault<string>();

                    IEnumerable<Models.Comment> comments = DB.Comments.FindAll(DB.Comments.PhotoId == model.Photo.Id && DB.Comments.Approved == true).Cast<Models.Comment>();
                    if (comments != null) model.Comments = comments.ToList();

                    bool commenterror = false;
                    if (Boolean.TryParse(Convert.ToString(Session["commenterror"]), out commenterror))
                    {
                        model.ErrorMessage = "Please fill out all required fields and make sure the email address you enter is valid.";
                        Session.Delete("commenterror");
                    }

                    return View["photodetail", model];
                }
            };

            Post["/{slug}/addcomment"] = parameters =>
            {
                string photoSlug = (string)parameters.slug;

                int? photoId = DB.Photos.Query().Select(DB.Photos.Id).Where(DB.Photos.Slug == photoSlug).ToScalarOrDefault<int?>();

                if (photoId.HasValue)
                {
                    Models.Comment comment = this.Bind<Models.Comment>("Id", "PhotoId", "Approved");
                    comment.PhotoId = photoId.Value;
                    comment.Approved = true;

                    if (comment.IsValid())
                    {
                        DB.Comments.Insert(comment);
                    }
                    else
                    {
                        Session["commenterror"] = true;
                    }

                    return Response.AsRedirect(String.Format("/photo/{0}#comments", photoSlug));
                }
                else
                {
                    // No photo found with this slug, we'll just redirect to the homepage
                    return Response.AsRedirect("/");
                }
            };
        }
 public PurchaseItemDetailRepository(IDBFactory databaseFactory)
     : base(databaseFactory)
 {
 }
 public UnitOfWork(IDBFactory dbFactory)
 {
     this.dbFactory = dbFactory;
 }