public List <Alliance> GetAlliances(AllianceQueryObj queryObj) { try { using (var ctx = new BaseDBContext()) { var predicate = PredicateBuilder.True <Alliance>(); if (queryObj.BallType != null) { predicate = predicate.And(p => p.BallType.Equals(Convert.ToInt32(queryObj.BallType))); } if (!string.IsNullOrEmpty(queryObj.SearchStr)) { predicate = predicate.And(p => p.AllianceName.Contains(queryObj.SearchStr)); } Func <Alliance, bool> query = predicate.Compile(); var result = ctx.Alliances.Where(query).ToList(); return(result); } } catch (Exception ex) { throw ex; } }
public void TestRepositoryConstructorTest() { //1.准备工作 IUnitOfWork unitOfWork = new TestDBContext(); // TODO: 初始化为适当的值 TestRepository target = new TestRepository(unitOfWork); // bool isTrue = target.Context is TestDBContext; Assert.IsTrue(isTrue, "给定对象不能转换为指定的TestDBContext类型"); isTrue = target.Context is BaseDBContext; Assert.IsTrue(isTrue, "给定对象不能转换为指定的BaseDBContext类型"); TestModel test = new TestModel(); target.Insert(test); TestDBContext testDBC = target.Context as TestDBContext; Assert.AreEqual(testDBC, target.Context); Assert.IsNotNull(testDBC.Tests.Find(test.testID)); Assert.IsNull(testDBC.Tests.Find(0)); BaseDBContext baseDBC = target.Context as BaseDBContext; Assert.IsNotNull(baseDBC.Set <TestModel>().Find(test.testID)); Assert.IsNull(baseDBC.Set <TestModel>().Find(0)); Assert.AreEqual(testDBC, target.Context); }
public ApiApp(IUnitWork unitWork, IAuth auth, BaseDBContext context) { _unitWork = unitWork; _authUtil = auth; _context = context; AuthStrategyContext authStrategyContext = _authUtil.GetCurrentUser(); if (authStrategyContext != null) { _loginInfo = new LoginInfo { Id = authStrategyContext.User.Id, Account = authStrategyContext.User.Account, Name = authStrategyContext.User.Name, }; } else { _loginInfo = new LoginInfo { Id = 0, Account = "Guest", Name = "匿名", }; } }
public void SetZeroScore(int id, bool flag) { try { using (var ctx = new BaseDBContext()) { var alliance = ctx.Alliances.Where(a => a.Id == id).FirstOrDefault(); if (alliance != null) { alliance.ZeroScore = Convert.ToByte(flag); ctx.SaveChanges(); } //else //{ // throw new Exception("Not Fount!"); //} } //update sub site } catch (Exception ex) { throw ex; } }
public static AccountSession UpdateAccountAndSession(UserInfoJson u, bool?isAttend = null) { using (BaseDBContext db = new BaseDBContext()) { var wa = db.WxAccount.FirstOrDefault(d => d.openid == u.openid); if (wa != null) { if (isAttend == null) { isAttend = false; } } else { if (isAttend == null) { isAttend = wa.subscribe; } } wa = WxDBUpdateAccount(u, db, isAttend.Value); wa.lastDate = DateTime.Now; db.SaveChanges(); Student s = db.Student.Find(wa.studentId); var a = AccountHelper.CreateAccountSession(wa, s); AccountHelper.SetSession(a); //debug.log("UpdateAccountAndSession_最终AccountSession", a); return(a); } }
/// <summary> /// 验证并产生TestSession /// </summary> /// <param nickname="cc"></param> /// <param nickname="db"></param> /// <param nickname="studentId"></param> /// <param nickname="test"></param> /// <returns></returns> public static BoolAny <TestVertifyResult> Start(Controller cc, BaseDBContext db, int studentId, Test test) { var result = Verify(cc, db, studentId, test); var tesresult = test.TestResults.FirstOrDefault(d => d.StudentId == studentId); if (result.t.Statue == TestStatue.新的) { //if (element == null) //{ // element = new TestElement(); // element.StudentId = studentId; // element.TestResults = new List<TestResult>(); // test.Elements.Add(element); // db.SaveChanges(); //} var tr = new TestResult() { TestId = test.Id, ExamId = test.ExamId.Value, Date = DateTime.Now, StudentId = studentId }; test.TestResults.Add(tr); test.JoinCount++; test.StudentCount++; try { db.SaveChanges(); }catch (Exception e) { } setTestSession(test, cc, new TestSession() { DateBegin = result.t.DateBegin, DateEnd = result.t.DateEnd, TestId = test.Id, studentId = studentId, openid = "", TestResultId = tr.Id }); //写记录 //var xx = test.Elements.FirstOrDefault(d => d.StudentId == studentId).TestResults; } if (result.t.Statue == TestStatue.继续) { setTestSession(test, cc, new TestSession() { DateBegin = result.t.DateBegin, DateEnd = result.t.DateEnd, TestId = test.Id, studentId = studentId, openid = "", TestResultId = tesresult.Id, }); } return(result); }
/// <summary> /// 更新登录信息 /// </summary> /// <param nickname="id"></param> /// <returns></returns> public static Boolean UpdateLogin(int id) { using (BaseDBContext db = new BaseDBContext()) { db.Student.Find(id).LastLoginDate = DateTime.Now; } return(true); }
public JsonResult getPage(int id) { using (BaseDBContext db2 = new BaseDBContext()) { var p = db2.MaterialPage.Find(id); return(myJson.successEx(new { p.Index, p.Title, p.Content, p.ExtUrl })); } }
public MaterialDistributeTaskHeaderApp(IUnitWork unitWork, IRepository <MaterialDistributeTaskHeader> repository, IRepository <MaterialDistributeTaskDetail> repositoryd, IHostingEnvironment hostingEnvironment, BaseDBContext context) { _unitWork = unitWork; _app = repository; _appd = repositoryd; _hostingEnvironment = hostingEnvironment; _context = context; }
protected void CreateDbContext() { DbContext = new BaseDBContext(); DbContext.Configuration.ProxyCreationEnabled = false; DbContext.Configuration.LazyLoadingEnabled = false; DbContext.Configuration.ValidateOnSaveEnabled = false; //Enable the below configuration for performance enablement //DbContext.Configuration.AutoDetectChangesEnabled = false; }
// // GET: /Manage/voteLog/ public ActionResult Index(int pageIndex = 1, int pageSize = 50, int orderBy = 0, int voteItemId = 0, string studentName = "", string ip = "", DateTime?sDate = null, DateTime?eDate = null) { using (BaseDBContext db = new BaseDBContext()) { IQueryable <VoteLog> vl = db.VoteLog; if (voteItemId != 0) { vl = vl.Where(d => d.VoteItemId == voteItemId); } if (!string.IsNullOrWhiteSpace(studentName)) { var students = db.Student.Where(d => studentName.Contains(d.Name)).Select(d => d.Id).ToArray(); if (students.Count() > 0) { vl = vl.Where(d => students.Contains(d.StudentId)); } } if (ip != "") { var _ip = ip.Split('.').Length; if (_ip == 4) { vl = vl.Where(d => d.ip == ip); } else if (_ip > 1 && _ip < 4) { vl = vl.Where(d => d.ip.Contains(ip)); } } if (sDate != null) { vl = vl.Where(d => d.Date >= sDate); } if (eDate != null) { vl = vl.Where(d => d.Date <= eDate); } if (orderBy == 0) { vl = vl.OrderByDescending(d => d.Id); } else { vl = vl.OrderBy(d => d.Id); } ViewBag.ip = ip; ViewBag.studentName = studentName; ViewBag.voteItemId = voteItemId; ViewBag.sDate = sDate; ViewBag.eDate = eDate; ViewBag.orderBy = orderBy; ViewBag.count = vl.Count().ToString(); ViewData.Model = vl.ToPagedList(pageIndex, pageSize); } return(View()); }
public OrderHeaderApp(IUnitWork unitWork, IRepository <OrderHeader> repository, IRepository <MaterialDemand> repositorymd, IRepository <SerialNumber> repositorys, IRepository <OrderDetiail> repositorydt, IHostingEnvironment hostingEnvironment, BaseDBContext context) { _unitWork = unitWork; _app = repository; _appdt = repositorydt; _appmd = repositorymd; _apps = repositorys; _hostingEnvironment = hostingEnvironment; _context = context; }
// //编写测试时,还可使用以下特性: // //使用 ClassInitialize 在运行类中的第一个测试前先运行代码 //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //使用 ClassCleanup 在运行完类中的所有测试后再运行代码 //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //使用 TestInitialize 在运行每个测试前先运行代码 //[TestInitialize()] //public void MyTestInitialize() //{ //} // //使用 TestCleanup 在运行完每个测试后运行代码 //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion #region 测试方法 /// <summary> /// GenericRepository`1 构造函数 的测试 /// </summary> /// <typeparam name="TEntity">The type of the T entity.</typeparam> public void GenericRepositoryConstructorTestHelper <TEntity>() where TEntity : class { IUnitOfWork unitOfWork = new BaseDBContext(); // TODO: 初始化为适当的值 GenericRepository <TEntity> target = new GenericRepository <TEntity>(unitOfWork); Assert.IsNotNull(target.Context); target = new GenericRepository <TEntity>(null); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); //BundleConfig.RegisterBundles(BundleTable.Bundles); JULONG.TRAIN.WEB.Models.DBfun.DBInit(); JULONG.TRAIN.WEB.Models.DBfun.WxDBInit(); ASConsoLe.Init(Config.AS_Url, Config.AS_AppId, Config.AS_SecretKey); /*同步wx关注用户*/ return; string accessToken = AccessTokenContainer.TryGetAccessToken(Config.AS_AppId, Config.AS_SecretKey); wx.OpenIdResultJson openIds; int count = 0; using (BaseDBContext db = new BaseDBContext()) { string nextOpenId = ""; do { openIds = UserApi.Get(accessToken, nextOpenId); if (openIds.count != 0) { foreach (var x in openIds.data.openid) { var o = db.WxAccount.FirstOrDefault(d => d.openid == x); if (o == null) { db.WxAccount.Add(new WxAccount() { lastDate = DateTime.Now, regDate = DateTime.Now, openid = x, subscribe = true }); count++; } else { break; } } } nextOpenId = openIds.next_openid; } while (openIds.count != 0); if (count > 0) { db.SaveChanges(); } } }
public void ContextTest() { IUnitOfWork unitOfWork = new TestDBContext(); // TODO: 初始化为适当的值 GenericRepository <TestModel> target = new GenericRepository <TestModel>(unitOfWork); // TODO: 初始化为适当的值 BaseDBContext expected = unitOfWork as BaseDBContext; // TODO: 初始化为适当的值 BaseDBContext actual; Assert.AreEqual(expected, target.Context); target.Context = expected; actual = target.Context; Assert.AreEqual(expected, actual); }
public Task Execute(IJobExecutionContext context) { string filePath = @"C:\Users\XiaLM\Desktop\text.txt"; string tempStr = File.ReadAllText(filePath) + $"|{DateTime.Now.ToString("YYYYmmDDHHmmss")}"; File.WriteAllText(filePath, tempStr); string strSql = sqlManament.FirstOrDefault(p => p.SqlName.Equals("CHZKRYJL")).SqlText; string sql = string.Format(strSql, DateTime.Now.ToString("yyyyMMdd000000"), DateTime.Now.ToString("yyyyMMdd235959")); var result = BaseDBContext.GetInstance().Database.SqlQuery <object>(sql); //执行sql语句 return(Task.CompletedTask); }
public static BoolAny <AccountSession> WxUnBinding(string openid) { using (BaseDBContext db = new BaseDBContext()) { var wxaccount = db.WxAccount.Find(openid); if (wxaccount == null || wxaccount.studentId == 0) { return(BoolAny <AccountSession> .fail("未绑定")); } wxaccount.studentId = 0; db.SaveChanges(); return(BoolAny <AccountSession> .succeed()); } }
public List <BallCountry> GetBallCountrys(AllianceQueryObj queryObj) { try { using (var ctx = new BaseDBContext()) { return(ctx.BallCountries.ToList()); } } catch (Exception ex) { throw ex; } }
private Manager GetQueryUserManager(string queryUser) { try { using (var ctx = new BaseDBContext()) { return(ctx.Managers.Where(m => m.Account.Equals(queryUser, StringComparison.OrdinalIgnoreCase)).FirstOrDefault()); } } catch (Exception ex) { throw ex; } }
public static BoolAny <WxAccount> WxDBUpdateAccount(UserInfoJson userinfo, BaseDBContext wdb, bool isAttend) { try { WxAccount newWa = wdb.WxAccount.Find(userinfo.openid); if (newWa == null) { newWa = new WxAccount() { subscribe = isAttend, regDate = DateTime.Now, //subscribe_time = LIB.DateTimeEx.TimeStampToDateTime(userinfo.subscribe_time), subscribe_time = DateTime.Now, openid = userinfo.openid, lastDate = DateTime.Now, headimgurl = userinfo.headimgurl, nickname = userinfo.nickname, sex = userinfo.sex.ToString(), groupid = userinfo.groupid.ToString(), remark = userinfo.remark, unionid = userinfo.unionid, studentId = 0 }; wdb.WxAccount.Add(newWa); } else { newWa.subscribe = isAttend; newWa.headimgurl = userinfo.headimgurl; newWa.nickname = userinfo.nickname; newWa.sex = userinfo.sex.ToString(); newWa.groupid = userinfo.groupid.ToString(); newWa.remark = userinfo.remark; } wdb.SaveChanges(); //debug.log("WxDBUpdateAccount_DBSave", newWa); return(BoolAny <WxAccount> .succeed(newWa)); } catch (DbEntityValidationException dbEx) { debug.log("WxDBUpdateAccount_DBSave_异常", dbEx.Message); //debug.print("addAccount_error", e.Message); return(BoolAny <WxAccount> .fail(dbEx.Message)); } }
/// <summary> /// Initializes a new instance of the <see cref="GenericRepository{TEntity}" /> class. /// </summary> /// <param name="unitOfWork">The unit of work.</param> /// <exception cref="System.ArgumentNullException">不能为null.</exception> /// <exception cref="System.ArgumentException">IUnitOfWork类型接口必须为可以转换为BaseDBContext类型的对象</exception> public GenericRepository(IUnitOfWork unitOfWork) { if (unitOfWork == null) { throw new ArgumentNullException("不能为null."); } _context = unitOfWork as BaseDBContext; if (_context == null) { throw new ArgumentException("IUnitOfWork类型接口必须为可以转换为BaseDBContext类型的对象"); } this.dbSet = _context.Set <TEntity>(); }
public Manager GetManagerByAccount(string account) { try { using (var ctx = new BaseDBContext()) { var query = from manager in ctx.Managers where manager.Account.Equals(account, StringComparison.OrdinalIgnoreCase) select manager; return(query.FirstOrDefault()); } } catch (Exception ex) { throw ex; } }
public DateTime GetTransferTime() { try { using (var ctx = new BaseDBContext()) { var query = from t in ctx.Transfers orderby t.Date select t.Date; return(Convert.ToDateTime(query.First())); } } catch (Exception ex) { throw ex; } }
public List <string> GetMultiNames(ManagerCatagory catagory = ManagerCatagory.Majordomo) { try { using (var ctx = new BaseDBContext()) { var result = from manager in ctx.Managers where manager.Catagory == (int)catagory orderby manager.Account.Length descending, manager.Account descending select manager.Account; return(result.Take(20).ToList <string>()); } } catch (Exception ex) { throw ex; } }
/// <summary> /// 已经关注 /// </summary> /// <returns></returns> public static Boolean WxIsAttendByDB(string openid) { bool attend = false; using (BaseDBContext wdb = new BaseDBContext()) { WxAccount newWa = wdb.WxAccount.Find(openid); if (newWa == null) { attend = false; } else { attend = newWa.subscribe; } } return(attend); }
/// <summary> /// 新增或更新关注用户信息 /// </summary> /// <returns></returns> public static BoolAny <WxAccount> WxDBUpdateAccount(string openid, BaseDBContext wdb, bool isAttend) { try { WxAccount newWa = wdb.WxAccount.Find(openid); if (isAttend) { if (newWa == null) { newWa = new WxAccount() { subscribe = true, regDate = DateTime.Now, subscribe_time = DateTime.Now, openid = openid, lastDate = DateTime.Now }; wdb.WxAccount.Add(newWa); } else { newWa.subscribe = true; } //debug.log("WxDBUpdateAccount_string_Attend", newWa); } else { //debug.log("WxDBUpdateAccount_string_UnAttend", newWa); if (newWa != null) { newWa.subscribe = false; } } wdb.SaveChanges(); return(BoolAny <WxAccount> .succeed(newWa)); } catch (Exception e) { //debug.print("addAccount_error", e.Message); return(BoolAny <WxAccount> .fail(e.Message)); } }
/// <summary> /// 更新WxAccount表和AccountSession。根据Student表 /// </summary> /// <param nickname="openid"></param> /// <returns></returns> public static AccountSession UpdateSession(string openid) { using (BaseDBContext db = new BaseDBContext()) { var wa = db.WxAccount.FirstOrDefault(d => d.openid == openid && d.subscribe); if (wa == null) { AccountHelper.SetSession(null); return(null); } else { Student s = db.Student.Find(wa.studentId); var a = AccountHelper.CreateAccountSession(wa, s); AccountHelper.SetSession(a); return(a); } } }
public static AccountSession UpdateAccountAndSession(string openid, bool isAttend) { using (BaseDBContext db = new BaseDBContext()) { var wa = db.WxAccount.FirstOrDefault(d => d.openid == openid && isAttend); wa = WxDBUpdateAccount(openid, db, isAttend); wa.lastDate = DateTime.Now; db.SaveChanges(); Student s = db.Student.Find(wa.studentId); var a = AccountHelper.CreateAccountSession(wa, s); AccountHelper.SetSession(a); return(a); } }
public static void WxDBInit() { using (BaseDBContext db = new BaseDBContext()) { if (!db.WxArtcle.Any(d => d.Name == "Welcome")) { db.WxArtcle.Add(new WxArtcle() { Name = "Welcome", type = WeixinArtcleType.图文, Bak = "关注欢迎" }); } if (!db.WxArtcle.Any(d => d.Name == "help")) { db.WxArtcle.Add(new WxArtcle() { Name = "help", type = WeixinArtcleType.图文, Bak = "帮助" }); } db.SaveChanges(); } }
/// <summary> /// 取消关注 /// </summary> /// <returns></returns> public static Boolean WxCancelAttend(string openid) { try { using (BaseDBContext wdb = new BaseDBContext()) { WxAccount newWa = wdb.WxAccount.Find(openid); if (newWa != null) { newWa.subscribe = false; newWa.lastDate = DateTime.Now; wdb.SaveChanges(); } wdb.SaveChanges(); } } catch (Exception e) { //debug.print("cancelAttend", e.Message); return(false); } return(true); }
/// <summary> /// 导出文件 /// </summary> /// <returns></returns> public FileResult Export(int id, string type = "txt") { BaseDBContext db = new BaseDBContext(); var exam = db.Exam.Find(id); switch (type) { case "doc": return(File(Encoding.Default.GetBytes(ExprotTxt(exam)), "application/msword", exam.Name + ".doc")); case "html": var s = RenderViewHelper.ToString(this, RenderViewHelper.FromFilePath + "试卷html导出模板.cshtml", exam); return(File(System.Text.Encoding.Default.GetBytes(s), "text/html", exam.Name + ".html")); case "htmldoc": var ss = RenderViewHelper.ToString(this, RenderViewHelper.FromFilePath + "试卷htmldoc导出模板.cshtml", exam); return(File(System.Text.Encoding.Default.GetBytes(ss), "application/msword", exam.Name + ".doc")); case "word": ComponentInfo.SetLicense("FREE-LIMITED-KEY"); var s1 = RenderViewHelper.ToString(this, RenderViewHelper.FromFilePath + "试卷html导出模板.cshtml", exam); var t1 = new System.IO.MemoryStream(); var hd = LoadOptions.HtmlDefault; hd.Encoding = Encoding.UTF8; var doc = SaveOptions.DocxDefault; DocumentModel.Load(new System.IO.MemoryStream(Encoding.UTF8.GetBytes(s1)), hd).Save(Server.MapPath("/Content/temp.docx"), doc); return(File(t1, "application/msword", exam.Name + ".doc")); default: return(File(Encoding.Default.GetBytes(ExprotTxt(exam)), "text/plain")); } }