protected void Page_Load(object sender, EventArgs e) { dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.AppSettings["dbConnStr"], MySqlDialect.Provider); var action = Request["Action"]; var id = Request["Id"]; List<allen_news> result = null; if (action == "PullDown") { var db = dbFactory.Open(); result = db.SelectFmt<allen_news>("select * from allen_news where news_id > {0} order by news_id desc limit 0,30",id); db.Dispose(); } else if(action == "PullUp") { var db = dbFactory.Open(); result = db.SelectFmt<allen_news>("select * from allen_news where news_id < {0} order by news_id desc limit 0,30", id); db.Dispose(); } else if(action == "CheckVersion") { Response.Write("1.0.2"); Response.End(); return; } else { var db = dbFactory.Open(); result = db.Select<allen_news>("select * from allen_news order by news_id desc limit 0,30"); db.Dispose(); } Response.Write(JsonConvert.SerializeObject(result)); Response.End(); }
public void Create_Sqlite_Database() { var dbPath = "~/App_Data/db.sqlite".MapAbsolutePath(); var dbFactory = new OrmLiteConnectionFactory( dbPath, SqliteDialect.Provider); if (File.Exists(dbPath)) File.Delete(dbPath); NorthwindData.LoadData(); using (var db = dbFactory.Open()) { db.CreateTables(overwrite:false, tableTypes:NorthwindFactory.ModelTypes.ToArray()); db.SaveAll(NorthwindData.Categories); db.SaveAll(NorthwindData.Customers); db.SaveAll(NorthwindData.CustomerCustomerDemos); db.SaveAll(NorthwindData.Employees); db.SaveAll(NorthwindData.EmployeeTerritories); db.SaveAll(NorthwindData.OrderDetails); db.SaveAll(NorthwindData.Orders); db.SaveAll(NorthwindData.Products); db.SaveAll(NorthwindData.Products); db.SaveAll(NorthwindData.Regions); db.SaveAll(NorthwindData.Shippers); db.SaveAll(NorthwindData.Suppliers); db.SaveAll(NorthwindData.Territories); } }
public void GetUsers_Test() { using (var appHost = new BasicAppHost(typeof(GetUsersService).Assembly).Init()) { var request = new GetUsers { UserIds = new ArrayOfLong(1, 2), UserNames = new ArrayOfString("User3", "User4") }; var factory = new OrmLiteConnectionFactory( InMemoryDb, SqliteDialect.Provider); using (var db = factory.Open()) { db.DropAndCreateTable<User>(); db.Insert(new User { Id = 1, UserName = "******" }); db.Insert(new User { Id = 2, UserName = "******" }); db.Insert(new User { Id = 3, UserName = "******" }); db.Insert(new User { Id = 4, UserName = "******" }); var handler = appHost.Resolve<GetUsersService>(); var response = handler.Any(request); Assert.That(response.Users.Count, Is.EqualTo(4)); } } }
public void SaveExtensionInfo([FromBody] string xmlString) { IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider); using (IDbConnection db = dbFactory.Open()) { var doc = XDocument.Parse(xmlString); var dataNode = doc.Root.Elements("data").Elements("ext_install_stats_request").Elements("client_info"); UserInfo items = (from r in dataNode select new UserInfo() { AppId = r.Element("appid").Value.ToString(), BrowserName = r.Element("bname").Value.ToString(), BrowserVersion = r.Element("bver").Value.ToString(), ClientId = r.Element("clid").Value.ToString(), ExtId = r.Element("extid").Value.ToString(), ExtType = r.Element("extype").Value.ToString(), // Id = (string)r.Element("linksclicked"), // Ip = (string)r.Element("linksclicked"), // Location = (string)r.Element("linksclicked"), OsVersion = r.Element("osver").Value.ToString(), Platform = r.Element("ostype").Value.ToString(), SysId = r.Element("sysid").Value.ToString() }).FirstOrDefault(); UserInfo model = new UserInfo(); db.Insert<UserInfo>(items); } }
protected override void Load(ContainerBuilder builder) { OrmLiteConfig.DialectProvider = PostgreSQLDialectProvider.Instance; ServiceStack.OrmLite.OrmLiteConfig.DialectProvider.NamingStrategy = new LowercaseNamingStrategy(); var connectionFactory = new OrmLiteConnectionFactory("Server=127.0.0.1;Port=5432;Database=transactions;User Id=postgres;Password=canada;", false, PostgreSqlDialect.Provider); using (var db = connectionFactory.OpenDbConnection()) { DbSetup.Setup(db); } builder.Register(c => connectionFactory).As<IDbConnectionFactory>(); builder.Register(c => connectionFactory.Open()).As<IDbConnection>().InstancePerLifetimeScope(); builder.RegisterType<UserRepository>().As<IUserRepository>().As<IRepository<User>>().InstancePerLifetimeScope(); builder.RegisterType<BudgetRepository>().As<IBudgetRepository>().As<IRepository<Budget>>().InstancePerLifetimeScope(); builder.RegisterType<CategoryRepository>().As<ICategoryRepository>().As<IRepository<Category>>().InstancePerLifetimeScope(); builder.RegisterType<TransactionRepository>().As<ITransactionRepository>().As<IRepository<Transaction>>().InstancePerLifetimeScope(); //builder.RegisterType<UserRepository>().As<IRepository<User>>().InstancePerLifetimeScope(); //builder.RegisterType<BudgetRepository>().As<IRepository<Budget>>().InstancePerLifetimeScope(); //builder.RegisterType<CategoryRepository>().As<IRepository<Category>>().InstancePerLifetimeScope(); //builder.RegisterType<TransactionRepository>().As<IRepository<Transaction>>().InstancePerLifetimeScope(); builder.RegisterType<BillRepository>().As<IBillRepository>().As<IRepository<Bill>>().InstancePerLifetimeScope(); builder.RegisterType<RepositoryUnitOfWork>().As<IRepositoryUnitOfWork>().InstancePerLifetimeScope(); builder.RegisterType<SimpleBudgetService>().As<ISimpleBudgetService>().InstancePerLifetimeScope(); // make sure our mock provider is accessible through IVoiceProvider and MockProvider for when we need to fake validation for things. //builder.RegisterType<MockProvider>().As<IVoiceProvider>().As<MockProvider>().InstancePerLifetimeScope(); //builder.RegisterType<VoiceCore>().As<IVoiceCore>().As<VoiceCore>().InstancePerLifetimeScope(); }
protected void Page_Load(object sender, EventArgs e) { var pageSize = 8; var Index = Request["Index"]; if (string.IsNullOrWhiteSpace(Index)) { Index = "0"; } var start = Convert.ToInt32(Index); var dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.AppSettings["dbConnStr"], MySqlDialect.Provider); var db = dbFactory.Open(); List<allen_news> obj; if(start == 0) { obj = db.Select<allen_news>("select * from allen_news order by news_id desc limit 0,"+(pageSize*2).ToString()); } else { obj = db.Select<allen_news>("select * from allen_news where news_id < "+start.ToString()+" order by news_id desc limit 0," + pageSize.ToString()); } db.Close(); db.Dispose(); if (obj.Count < 1) { Response.Write("Sorry...我们不打算把不算“新”闻的内容提供给您,您收藏的内容可以在“我的收藏”中找到。"); Response.End(); return; } Response.Write(JsonConvert.SerializeObject(obj)); Response.End(); }
static void Main(string[] args) { string ConnectionString = ConfigurationManager.ConnectionStrings["p2pfDB"].ConnectionString; var dbFactory = new OrmLiteConnectionFactory(ConnectionString, PostgreSQLDialectProvider.Instance); using (IDbConnection db = dbFactory.Open()) { db.CreateTableIfNotExists<Investor>(); Console.WriteLine(db.GetLastSql()); db.CreateTableIfNotExists<Borrower>(); Console.WriteLine(db.GetLastSql()); db.CreateTableIfNotExists<Investor1>(); Console.WriteLine(db.GetLastSql()); db.CreateTableIfNotExists<Investor2>(); Console.WriteLine(db.GetLastSql()); db.CreateTableIfNotExists<Investor3>(); Console.WriteLine(db.GetLastSql()); db.CreateTableIfNotExists<Investor4>(); Console.WriteLine(db.GetLastSql()); db.CreateTableIfNotExists<Investor5>(); Console.WriteLine(db.GetLastSql()); db.CreateTableIfNotExists<Investor6>(); Console.WriteLine(db.GetLastSql()); db.CreateTableIfNotExists<Investor7>(); Console.WriteLine(db.GetLastSql()); db.CreateTableIfNotExists<Investor8>(); Console.WriteLine(db.GetLastSql()); db.CreateTableIfNotExists<Investor9>(); Console.WriteLine(db.GetLastSql()); db.CreateTableIfNotExists<Investor10>(); Console.WriteLine(db.GetLastSql()); } }
public void CreateDatabase(bool recreate = false) { Operation = "Creating database"; var dbconn = new OrmLiteConnectionFactory(Bootstrapper.NoDBConnectionString); using (var db = dbconn.Open()) { if (recreate) { try { db.ExecuteSql("DROP DATABASE CS431PROJECT;"); } catch (Exception) { // Log throw; } } try { db.ExecuteSql("CREATE DATABASE CS431PROJECT;"); } catch (Exception) { // Log throw; } } Status = "Probably succeeded"; }
public void GetUsers_Test() { var request = new GetUsers { UserIds = new ArrayOfLong(1, 2), UserNames = new ArrayOfString("User3", "User4") }; var factory = new OrmLiteConnectionFactory( InMemoryDb, false, SqliteDialect.Provider); using (var db = factory.Open()) { db.DropAndCreateTable<User>(); db.Insert(new User { Id = 1, UserName = "******" }); db.Insert(new User { Id = 2, UserName = "******" }); db.Insert(new User { Id = 3, UserName = "******" }); db.Insert(new User { Id = 4, UserName = "******" }); var handler = new GetUsersService { ConnectionFactory = factory }; var response = (GetUsersResponse)handler.Execute(request); Assert.That(response.Users.Count, Is.EqualTo(4)); } }
public void Setup() { _connectionString = ConfigurationManager.ConnectionStrings["Database"].ConnectionString; var dbFactory = new OrmLiteConnectionFactory(_connectionString, SqlServerDialect.Provider); _connection = dbFactory.Open(); _connection.DropAndCreateTable<AzureTraceMessage>(); }
public ActionResult Index(string msg) { ViewBag.Message = msg; ServiceStack.Data.IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider); using (IDbConnection db = dbFactory.Open()) { ViewBag.GroupList = db.Select<Group>().ToList(); } return View(); }
public void Database() { IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider); using (IDbConnection db = dbFactory.Open()) { db.DropAndCreateTable<SessionDetail>(); db.DropAndCreateTable<UserInfo>(); db.DropAndCreateTable<UserTrack>(); } }
public InMemoryDbBase() { b = new OrmLiteConnectionFactory(":memory:", SqliteOrmLiteDialectProvider.Instance, true); b.AutoDisposeConnection = false; using (var db = b.Open()) { db.DropAndCreateTable<Movie>(); db.DropAndCreateTable<Customer>(); db.DropAndCreateTable<Showing>(); db.DropAndCreateTable<Purchase>(); db.DropAndCreateTable<Promotion>(); } }
private void SaveTwitterInfo(Profile model) { ServiceStack.Data.IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider); using (IDbConnection db = dbFactory.Open()) { //Check user Exits var alreadyExist = db.Select<Profile>().Where(u => u.UserId == model.UserId).FirstOrDefault(); if (alreadyExist != null) { return; } db.Insert<Profile>(model); } }
public ActionResult Delete(int id = 0) { try { ServiceStack.Data.IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider); using (IDbConnection db = dbFactory.Open()) { db.DeleteById<Profile>(id); } return RedirectToAction("Index"); } catch (Exception ex) { throw ex; } }
public void Database() { IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider); using (IDbConnection db = dbFactory.Open()) { db.DropAndCreateTable<ProfileType>(); db.DropAndCreateTable<Profile>(); db.InsertAll<ProfileType>(GetProfileTypes()); //db.DropAndCreateTable<Config>(); db.DropAndCreateTable<Group>(); db.DropAndCreateTable<Post>(); db.DropAndCreateTable<PostImage>(); db.DropAndCreateTable<PostText>(); db.DropAndCreateTable<ProfileImageGroup>(); db.DropAndCreateTable<ProfileTextGroup>(); //db.InsertAll<Post>(GetPhotos()); } }
public WikipediaIndexingPluginTests(string path) { CompositionContainer pluginContainer = Factories.PluginContainer(false).Value; Interface.IFactoryCollection factoryCollection = new Factories.FactoryCollection(pluginContainer); Interface.ISettingsBuilder settingsBuilder = SettingsBuilder.SettingsBuilder( factoryCollection, new Validator.IndexValidator(factoryCollection)); var searchService = new SearchDsl.SearchService(factoryCollection.SearchQueryFactory.GetAllModules()); var dbFactory = new OrmLiteConnectionFactory( Constants.ConfFolder.Value + "//conf.sqlite", SqliteDialect.Provider); dbFactory.OpenDbConnection().Run(db => db.CreateTable<Index>(true)); Interface.IIndexService indexservice = new FlexIndexModule.IndexService( settingsBuilder, searchService, dbFactory.Open(), false); indexservice.AddIndex(this.WikipediaIndex()); this.StartIndexing(indexservice, path); Console.ReadLine(); }
protected override void ConfigureApplicationContainer(ILifetimeScope existingContainer) { base.ConfigureApplicationContainer(existingContainer, true); LogTo.Warn("Using test (in-memory) database"); // Perform registration that should have an application lifetime var builder = new ContainerBuilder(); testdb = new OrmLiteConnectionFactory(":memory:", SqliteOrmLiteDialectProvider.Instance, true); testdb.AutoDisposeConnection = false; using (var db = testdb.Open()) { db.DropAndCreateTable<Movie>(); db.DropAndCreateTable<Customer>(); db.DropAndCreateTable<Showing>(); db.DropAndCreateTable<Purchase>(); db.DropAndCreateTable<Promotion>(); } builder.RegisterInstance(testdb); builder.Update(existingContainer.ComponentRegistry); }
private static void SingelThread_SQLite() { var dbFactory = new OrmLiteConnectionFactory( "App_Data/db.sqlite", SqliteDialect.Provider); using (IDbConnection db = dbFactory.Open()) { db.DropAndCreateTable<StringPOCO>(); Console.WriteLine("SingelThread_SQLite"); Stopwatch sw = Stopwatch.StartNew(); for (int i = 0; i < 1000; i++) { string key = Guid.NewGuid().ToString(); var poco = new StringPOCO() { Key = key, Value = key, }; db.Save(poco); var savedpoco = db.SingleById<StringPOCO>(key); if (savedpoco.Value != key) throw new Exception(); } sw.Stop(); Console.WriteLine(sw.Elapsed); } }
public override bool TryAuthenticate(IServiceBase authService, string userName, string password) { var Roles = new List<string>(); var Permissions = new List<string>(); var dbConnectionFactory = new OrmLiteConnectionFactory("Server = localhost; Database = auth; Uid = root; Pwd = 123", MySqlDialect.Provider); using (var db = dbConnectionFactory.Open()) { LoginModels user = db.Query<LoginModels>("Select * from loginmodels where User=@userName",new{userName = userName}).SingleOrDefault(); if (user==null) { return false; } if (password!=user.Pass) { return false; } //Get All the roles per user List<Roles> roleses = db.Query<Roles>("SELECT `Join1`.`ROLE_ID1` AS `role_Id`, `Join1`.`Name` FROM `LoginModels` AS `Extent1` INNER JOIN (SELECT `Extent2`.`lm_Id`, `Extent2`.`role_Id`, `Extent3`.`role_Id` AS `ROLE_ID1`, `Extent3`.`Name` FROM `login_roles` AS `Extent2` INNER JOIN `Roles` AS `Extent3` ON `Extent3`.`role_Id` = `Extent2`.`role_Id`) AS `Join1` ON `Extent1`.`lm_Id` = `Join1`.`lm_Id` WHERE `Extent1`.`User`=@userName",new { userName = userName }); foreach (var role in roleses) { Roles.Add(role.Name); List<Permissions> permis = db.Query<Permissions>("SELECT `Join1`.`permi_Id`, `Join1`.`Name` FROM `Roles` AS `Extent1` INNER JOIN (SELECT `Extent2`.`role_id`, `Extent2`.`per_id`, `Extent3`.`permi_Id`, `Extent3`.`Name` FROM `roles_permissions` AS `Extent2` INNER JOIN `Permissions` AS `Extent3` ON `Extent3`.`permi_Id` = `Extent2`.`per_id`) AS `Join1` ON `Extent1`.`role_Id` = `Join1`.`role_id` WHERE `Extent1`.`Name` =@role_name ", new { role_name = role.Name }); foreach (var permi in permis) { Permissions.Add(permi.Name); } } } var session = authService.GetSession(false); //Add Repository Method for Validate User if there's one. //if (!Membership.ValidateUser(userName, password)) return false; session.IsAuthenticated = true; session.Id = authService.GetSessionId(); if (session.UserAuthId == null) session.UserAuthId = userName; session.Roles = Roles; //loaded from db session.Permissions = Permissions; //loaded from db if (session.HasRole("admin")) { session.ReferrerUrl = "/api"; //Redirect to Admin Role to the api page } return true; }
public ActionResult DeletePost(int id = 0) { try { ServiceStack.Data.IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider); using (IDbConnection db = dbFactory.Open()) { var post = db.Select<Post>(); if (post != null) { string photoPath = post.FirstOrDefault().PhotoPath; System.IO.File.Delete(baseurl + photoPath.Substring(3, photoPath.Length - 3)); db.DeleteById<Post>(id); } } return RedirectToAction("Post"); } catch (Exception ex) { throw ex; } }
public ActionResult Update(Profile model, int[] ImgGroups, int[] textGroups) { ServiceStack.Data.IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider); using (IDbConnection db = dbFactory.Open()) { var existingRecord = db.Select<Profile>().Where(x => x.Id == model.Id).FirstOrDefault(); existingRecord.Interval = model.Interval; existingRecord.PageId = model.PageId; db.Update<Profile>(existingRecord); AddImageGroup(db, ImgGroups, model.Id); AddTextGroup(db, textGroups, model.Id); } return RedirectToAction("Index"); ; }
public ActionResult SaveInterval(string inertvaltime) { try { Config model = new Config(); model.ServiceInterval = Convert.ToInt32(inertvaltime); ServiceStack.Data.IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider); using (IDbConnection db = dbFactory.Open()) { var serviceInterval = db.Select<Config>().ToList(); if (serviceInterval.Count > 0) { var intervalmodel = serviceInterval.FirstOrDefault(); intervalmodel.ServiceInterval = Convert.ToInt32(inertvaltime); db.Update<Config>(intervalmodel); } else { db.Insert<Config>(model); } return Json("Success"); } } catch (Exception) { // throw; return Json("Fail"); } }
public void Save() { try { string userInfo = getUserDetail(); JavaScriptSerializer jss = new JavaScriptSerializer(); var obj = (IDictionary<string, object>)jss.DeserializeObject(userInfo); Profile model = new Data.Models.Profile(); model.AccessToken = AccessToken; model.UserId = obj["id"].ToString(); model.Username = obj["name"].ToString(); model.ProfileTypeID = ProfileTypeId; model.PageId = PageId;// "738024112987033"; model.Interval = ServiceInterval; ServiceStack.Data.IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider); using (IDbConnection db = dbFactory.Open()) { //Check user Exits var alreadyExist = db.Select<Profile>().Where(u => u.UserId == model.UserId).FirstOrDefault(); if (alreadyExist != null) { Response.Redirect("index"); } db.Insert<Profile>(model); } Response.Redirect("index"); } catch (Exception ex) { JavaScriptSerializer jss = new JavaScriptSerializer(); Response.Redirect("index"); // throw ex; } }
public ActionResult Post(HttpPostedFileBase PhotoPath, Post model) { if (PhotoPath != null && PhotoPath.ContentLength > 0) try { string path = Path.Combine("../Images", DateTime.Now.ToString("ddMMyyyyhhmm") + Path.GetFileName(PhotoPath.FileName)); ServiceStack.Data.IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider); using (IDbConnection db = dbFactory.Open()) { var existingRecord = db.Select<Post>().Where(x => x.Id == model.Id).FirstOrDefault(); if (existingRecord != null) { System.IO.File.Delete(Server.MapPath(existingRecord.PhotoPath)); //FIRST DELETE THE EXISTING PHOTO SaveImage(PhotoPath, path); model.PhotoPath = path; UpdatePost(model); } else { SaveImage(PhotoPath, path); model.PhotoPath = path; db.Save<Post>(model); } } return RedirectToAction("Post"); } catch (Exception ex) { } else { UpdatePost(model); return RedirectToAction("Post"); } return View(model); }
public ActionResult Post() { Post model = new Post(); ServiceStack.Data.IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider); using (IDbConnection db = dbFactory.Open()) { ViewBag.PostList = db.Select<Post>().ToList(); } return View(model); }
private void SaveTextInDB(string directory, int GroupId) { var model = new PostText(); model.GroupId = GroupId; model.Text = directory; ServiceStack.Data.IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider); using (IDbConnection db = dbFactory.Open()) { db.Save<PostText>(model); } }
public ActionResult GetSelectedGroups(string profileId) { ServiceStack.Data.IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider); JavaScriptSerializer jss = new JavaScriptSerializer(); string response = string.Empty; using (IDbConnection db = dbFactory.Open()) { var ImageGroups = db.Where<ProfileImageGroup>("ProfileID", Convert.ToInt32(profileId)); var TextGroups = db.Where<ProfileTextGroup>("ProfileID", Convert.ToInt32(profileId)); string imgGroupIds = string.Empty; string txtGroupIds = string.Empty; ImageGroups.ForEach(x => { imgGroupIds += x.GroupID + ","; }); TextGroups.ForEach(x => { txtGroupIds += x.GroupID + ","; }); if (imgGroupIds.Length > 0 || txtGroupIds.Length > 0) { imgGroupIds = imgGroupIds.Substring(0, imgGroupIds.Length - 1); txtGroupIds = txtGroupIds.Substring(0, txtGroupIds.Length - 1); } response = imgGroupIds + "||" + txtGroupIds; } return Json(jss.Serialize(response)); }
public ActionResult Index(string access_token) { FacebookClientID = ConfigurationManager.AppSettings["FacebookClientID"].ToString(); AppSecret = ConfigurationManager.AppSettings["AppSecret"].ToString(); try { if (Request.QueryString["access_token"] != null) { AccessToken = Request.QueryString["access_token"]; var querystingValues = Request.QueryString["pageid"]; PageId = querystingValues.ToString().Split('|')[0]; ServiceInterval = Convert.ToInt32(querystingValues.ToString().Split('|')[1]); ProfileTypeId = 1; AccessToken = GetLongLivedToken(AccessToken); Save(); } Profile model = new Profile(); ServiceStack.Data.IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider); using (IDbConnection db = dbFactory.Open()) { var items = db.Select<ProfileType>().Select(x => new { Id = x.Id, Name = x.Name }).ToList(); ViewBag.ProfileTypeList = items; var result = db.Select<Profile>().Select(x => new Profile { Id = x.Id, Username = x.Username, PageId = x.PageId, Interval = x.Interval, ProfileTypeID = x.ProfileTypeID, ProfileName = db.LoadSelect<ProfileType>().Where(u => u.Id == x.ProfileTypeID).FirstOrDefault() }).ToList(); var ImageGroups = db.Where<ProfileImageGroup>("ProfileID", "img"); var TextGroups = db.Where<ProfileTextGroup>("ProfileID", "img"); List<int> imgGroupIds = new List<int>(); List<int> txtGroupIds = new List<int>(); ImageGroups.ForEach(x => { imgGroupIds.Add(x.Id); }); ViewBag.userProfileList = result; ViewBag.ImageGroups = new MultiSelectList(db.Where<Group>("Type", "img"), "Id", "Name"); ViewBag.TextGroups = new MultiSelectList(db.Where<Group>("Type", "txt"), "Id", "Name"); // ViewBag.ImageGroups = new MultiSelectList(db.Select<PostImage>(), "Id", "Group"); //var serviceInterval = db.Select<Config>(); //if (serviceInterval.Count > 0) //{ // ViewBag.ServiceInterval = serviceInterval.FirstOrDefault().ServiceInterval; //} //else //{ // ViewBag.ServiceInterval = 10; //} // model.Interval = 10; } return View(model); } catch (Exception ex) { throw ex; } }
private void UpdatePost(Post model) { ServiceStack.Data.IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider); using (IDbConnection db = dbFactory.Open()) { var existingRecord = db.Select<Post>().Where(x => x.Id == model.Id).FirstOrDefault(); existingRecord.Text = model.Text; if (model.PhotoPath != null) existingRecord.PhotoPath = model.PhotoPath; db.Update<Post>(existingRecord); } }