protected override void Up() { this.RunCode(db => { var repo = RF.Concrete <MonthPlanRepository>(); var plans = repo.GetAll(); foreach (MonthPlan plan in plans) { foreach (TaskOrCategory item in plan.TaskOrCategoryList) { if (item.IsCategoryRO) { item.ObjectiveNum = null; item.WeightInCategory = null; item.Score = null; } else { item.MonthPercent = null; item.MonthScore = null; } } } RF.Save(plans); }); }
public void ET_Repository_TableQuery_UseSqlTreeQuery() { var repo = RF.Concrete <ChapterRepository>(); using (RF.TransactionScope(repo)) { RF.Save(new Book { Name = "Book1", ChapterList = { new Chapter { Name = "01" }, new Chapter { Name = "02" }, new Chapter { Name = "11" } } }); var table = repo.QueryChapterBySqlTree("0", PagingInfo.Empty); Assert.IsTrue(table.Rows.Count == 2); Assert.IsTrue(table[0].GetString(Chapter.NameProperty) == "01"); Assert.IsTrue(table[1].GetString(Chapter.NameProperty) == "02"); } }
public void ET_Repository_Submit_ChildrenOnly_UpdateCurrent() { var repo = RF.Concrete <BookRepository>(); using (RF.TransactionScope(repo)) { var book = new Book { ChapterList = { new Chapter() } }; repo.Save(book); book.ChapterList[0].Name = "DDDDD"; var dp = repo.DataProvider as BookRepositoryDataProvider; try { dp.UpdateCurrent = true; var c = Logger.ThreadDbAccessedCount; repo.Save(book); Assert.IsTrue(Logger.ThreadDbAccessedCount == c + 2); } finally { dp.UpdateCurrent = false; } } }
public void ET_Id_NotPrimaryKey() { var repo = RF.Concrete <BuildingRepository>(); using (RF.TransactionScope(repo)) { var model = new Building(); model.Name = "A"; repo.Save(model); Assert.IsTrue(model.Id > 0); Assert.IsTrue(repo.CountAll() == 1); model = new Building(); model.Name = "B"; repo.Save(model); Assert.IsTrue(model.Id > 0); Assert.IsTrue(repo.CountAll() == 2); model = new Building(); model.Name = "A"; try { repo.Save(model); Assert.IsTrue(false, "主键不能重复插入。"); } catch (DbException) { } } }
public void ET_Property_LOB_UpdateWithoutLOB() { var repo = RF.Concrete <BookRepository>(); using (RF.TransactionScope(repo)) { var book = new Book { Name = "1", Content = "Book1 Long Content........." }; repo.Save(book); var book2 = repo.GetById(book.Id); book2.Name = "name changed"; string updateSql = string.Empty; Logger.ThreadDbAccessed += (o, e) => { updateSql = e.Sql.ToLower(); }; repo.Save(book2); Assert.IsTrue(updateSql.Contains("update")); Assert.IsTrue(!updateSql.Contains("content"), "LOB 属性未发生改变时,更新语句不更新该字段。"); } }
public override ActionResult Add(AddOrEditViewModel <Xzqy> model, FormCollection collection) { if (!ModelState.IsValid) { return(View("AddOrEdit", model)); } int OrderBy = Convert.ToInt32(DbFactory.DBA.QueryValue("SELECT ISNULL(MAX(OrderBy),0)+1 OrderBy FROM Xzqy WHERE ParentId='" + model.Entity.ParentId + "'")); model.Entity.OrderBy = OrderBy; if (model.Entity.ParentId != Guid.Empty) { model.Entity.NodePath = model.Entity.NodePath + "\\" + model.Entity.Name; model.Entity.Level = model.Entity.Level + 1; model.Entity.IsLast = false; } else { model.Entity.NodePath = model.Entity.Name; } model.Entity.AddDate = DateTime.Now; model.Entity.UpdateDate = DateTime.Now; RF.Concrete <IXzqyRepository>().Create(model.Entity); RF.Concrete <IXzqyRepository>().Context.Commit(); return(RedirectToAction("Index", new { currentPageNum = model.CurrentPageNum, pageSize = model.PageSize })); }
public void ET_Repository_SaveList_Transaction() { var repo = RF.Concrete <BookLocRepository>(); var list = repo.GetAll(); list.Clear(); repo.Save(list); var dp = repo.DataProvider as BookLocRepositoryDataProvider; try { dp.TestSaveListTransactionItemCount = 0; repo.Save(new BookLocList { new BookLoc(), new BookLoc(), }); Assert.IsTrue(false, "超过一条数据,直接抛出异常。之前的数据需要回滚。"); } catch (NotSupportedException) { } finally { dp.TestSaveListTransactionItemCount = -1; } Assert.IsTrue(repo.CountAll() == 0, "所有数据需要回滚。"); }
public void MPT_Redundancy_UpdateC() { using (RF.TransactionScope(UnitTestEntityRepositoryDataProvider.DbSettingName)) { var a = new A { Name = "AName" }; Save(a); var b = new B { A = a }; Save(b); var c = new C { B = b }; Save(c); a.Name = "New Name"; Save(a); var b2 = RF.Concrete <BRepository>().GetById(b.Id) as B; Assert.AreEqual("New Name", b2.AName); var c2 = RF.Concrete <CRepository>().GetById(c.Id) as C; Assert.AreEqual("New Name", c2.AName); } }
public void MPT_Redundancy_RefId() { using (RF.TransactionScope(UnitTestEntityRepositoryDataProvider.DbSettingName)) { var a1 = new A { Name = "A1" }; var a2 = new A { Name = "A2" }; Save(a1, a2); var b = new B { A = a1 }; Save(b); var c = new C { B = b }; Save(c); Assert.AreEqual(c.AIdOfB, b.AId); Assert.AreEqual(b.AId, a1.Id); b.A = a2; Save(b); var cInDb = RF.Concrete <CRepository>().GetById(c.Id) as C; Assert.AreEqual(cInDb.AIdOfB, a2.Id); } }
private static FormattedSql ParseWhere(string filter) { var repo = RF.Concrete <TestUserRepository>(); var q = Parse(filter, repo); return(QueryNodeTester.GenerateTestSql(q.Where)); }
public void MPT_ORM_IsSelfDirty() { var repo = RF.Concrete <TestUserRepository>(); //clear var e = repo.GetByName("huqf"); if (e != null) { e.PersistenceStatus = PersistenceStatus.Deleted; repo.Save(e); } var user = repo.New().CastTo <TestUser>(); user.Name = "huqf"; user.NotEmptyCode = "NotEmptyCode"; Assert.IsTrue(user.IsNew); Assert.IsTrue(user.IsDirty); repo.Save(user); Assert.IsTrue(!user.IsNew); Assert.IsTrue(!user.IsDirty); user.PersistenceStatus = PersistenceStatus.Deleted; Assert.IsTrue(user.IsDeleted); repo.Save(user); Assert.IsTrue(!user.IsDeleted); Assert.IsTrue(!user.IsDirty); }
public CustomJsonResult AjaxEasyUITree_HM_Village() { string id = LRequest.GetString("id"); Guid pid = string.IsNullOrWhiteSpace(id) ? Guid.Empty : Guid.Parse(id); var repo = RF.Concrete <IHM_VillageRepository>(); ISpecification <HM_Village> spec = Specification <HM_Village> .Eval(p => p.ParentId == Guid.Empty); ISpecification <HM_Village> spec1 = Specification <HM_Village> .Eval(p => p.ParentId == pid); IEnumerable <HM_Village> list = repo.FindAll(spec).ToList(); if (pid != Guid.Empty) { list = repo.FindAll(spec1).ToList(); } List <EasyUITreeModel> easyTree = new List <EasyUITreeModel>(); int i = 0; foreach (var item in list) { EasyUITreeModel model = new EasyUITreeModel(); if (i == 0) { model.selected = true; model.Checked = true; } model.id = item.ID.ToString(); model.text = item.Name; model.parentId = item.ParentId.ToString(); model.parentName = repo.GetByName(item.ParentId); model.attributes.Add("ID", item.ID); model.attributes.Add("Name", item.Name); model.attributes.Add("Pinyi", item.Pinyi); model.attributes.Add("Type", item.Type); model.attributes.Add("EnName", item.EnName); model.attributes.Add("Alias", item.Alias); model.attributes.Add("Population", item.Population); model.attributes.Add("TotalArea", item.TotalArea); model.attributes.Add("Office", item.Office); model.attributes.Add("Summary", item.Summary); model.attributes.Add("Address", item.Address); model.attributes.Add("IsLast", item.IsLast); model.attributes.Add("Level", item.Level); model.attributes.Add("NodePath", item.NodePath); model.attributes.Add("OrderBy", item.OrderBy); model.attributes.Add("ParentId", item.ParentId); model.attributes.Add("IsDelete", item.IsDelete); model.attributes.Add("AddDate", item.AddDate); model.attributes.Add("UpdateDate", item.UpdateDate); easyTree.Add(model); i++; } var json = new CustomJsonResult(); json.JsonRequestBehavior = JsonRequestBehavior.AllowGet; json.Data = easyTree; return(json); }
/// <summary> /// 查找某个岗位下某个指定模块的禁用功能。 /// </summary> /// <param name="c"></param> /// <returns></returns> private EntityList GetBy(OperationAC_GetDenyListCriteria c) { var opId = c.OrgPositionId; var moduleAC = RF.Concrete <ModuleACRepository>().GetById(c.ModuleACId); var operations = this.DoGetByParent(moduleAC); //把所有已经禁用的功能都加入到列表中去。并把这个返回 var list = this.NewList(); var op = RF.Concrete <OrgPositionRepository>().GetById(opId) as OrgPosition; var denyList = op.OrgPositionOperationDenyList; list.AddRange(operations.Cast <OperationAC>().Where(item => { foreach (var deny in denyList) { if (item.IsSame(deny)) { return(true); } } return(false); })); return(list); }
public ActionResult DepartmentUser(int?currentPageNum, int?pageSize, System.Web.Mvc.FormCollection collection) { if (!currentPageNum.HasValue) { currentPageNum = 1; } if (!pageSize.HasValue) { pageSize = PagedResult <User> .DefaultPageSize; } int pageNum = currentPageNum.Value; Guid depId = Guid.Empty; string depIdstr = LRequest.GetString("depId"); if (!string.IsNullOrWhiteSpace(depIdstr)) { depId = Guid.Parse(depIdstr); } var villagelist = RF.Concrete <IUserRepository>().GetDepartmentUsers(depId); var pageList = new UserPagedListViewModel(pageNum, pageSize.Value, villagelist.ToList()); pageList.DepId = depId; return(View(pageList)); }
public void UtilsTest_Logger_ThreadDbAccessed() { var repo = RF.Concrete <TestUserRepository>(); using (RF.TransactionScope(repo)) { int count = 0; EventHandler <Logger.DbAccessedEventArgs> handler = (o, e) => { if (e.ConnectionSchema == RdbDataProvider.Get(repo).DbSetting) { count++; } }; Logger.ThreadDbAccessed += handler; repo.Save(new TestUser()); Logger.ThreadDbAccessed -= handler; var p = DbSetting.FindOrCreate(UnitTestEntityRepositoryDataProvider.DbSettingName).ProviderName; if (p == DbSetting.Provider_SqlClient) { Assert.IsTrue(count == 1);//sqlServer= 1 } else { Assert.IsTrue(count == 2);//sqlce oracle=2 } } }
public override ActionResult AddOrEdit(int?currentPageNum, int?pageSize, Guid?id, FormCollection collection) { if (!currentPageNum.HasValue) { currentPageNum = 1; } if (!pageSize.HasValue) { pageSize = PagedListViewModel <CompanyInfoAddOrEditViewModel> .DefaultPageSize; } if (!id.HasValue) { return(View(new CompanyInfoAddOrEditViewModel { UnitInfo = new UnitInfo(), CompanyInfo = new CompanyInfo(), })); } else { return(View(new CompanyInfoAddOrEditViewModel { UnitInfo = RF.Concrete <IUnitInfoRepository>().GetByKey(id.Value), CompanyInfo = RF.Concrete <ICompanyInfoRepository>().Find(LCL.Specifications.Specification <CompanyInfo> .Eval(e => e.UnitInfo.ID == id.Value)), })); } }
//TODO: 加入角色和管理员控制 public bool IsAuthority(string url) { try { var user = RF.Concrete <IUserRepository>().GetUserByLoginName(); if (user != null && user.Role != null) { var roleIds = user.Role.Select(p => p.ID).ToArray(); if (roleIds != null && roleIds.Length > 0) { string str = string.Join(",", roleIds); if (!string.IsNullOrWhiteSpace(str)) { string sql = @"SELECT * FROM RoleAuthority WHERE url='" + url + "' AND Role_ID IN(" + str + ")"; var datatable = DbFactory.DBA.QueryDataTable(sql); if (datatable.Rows.Count > 0) { return(true); } } } } // return(true); } catch (Exception ex) { Logger.LogError("权限控制", ex); return(true); } }
public void SET_StringRefInt() { var lRepo = RF.Concrete <LesseeRepository>(); var repo = RF.Concrete <HouseRepository>(); using (RF.TransactionScope(repo)) { var house = new House { Id = "House1" }; repo.Save(house); house = repo.GetFirst(); Assert.IsTrue(house.LesseeId == null); var lessee = new Lessee(); lRepo.Save(lessee); Assert.IsTrue(lessee.Id > 0); house.Lessee = lessee; Assert.IsTrue(house.LesseeId.GetValueOrDefault() == lessee.Id); repo.Save(house); house = repo.GetFirst(); Assert.IsTrue(house.LesseeId.GetValueOrDefault() == lessee.Id); } }
public void StampT_Insert_CreatedUser_Logined() { var oldPrincipal = RafyEnvironment.Principal; try { var userName = "******"; RafyEnvironment.Principal = new GenericPrincipal(new GenericIdentity(userName), null); var repo = RF.Concrete <InvoiceRepository>(); using (RF.TransactionScope(repo)) { var inv = new Invoice(); repo.Save(inv); Assert.AreEqual(inv.GetCreatedUser(), userName, "登录后,创建人属性应该正确的设置上。"); inv = repo.GetById(inv.Id); Assert.AreEqual(inv.GetCreatedUser(), userName, "登录后,创建人属性应该正确的设置上。"); } } finally { RafyEnvironment.Principal = oldPrincipal; } }
public void SET_IntWithString_Insert() { var repo = RF.Concrete <HouseMerchantRepository>(); var houseRepo = RF.Concrete <HouseRepository>(); using (RF.TransactionScope(repo)) { var house = new House { Id = "House1" }; houseRepo.Save(house); var house2 = new House { Id = "House2" }; houseRepo.Save(house2); var merchant = new HouseMerchant { MerchantItemList = { new MerchantItem { House = house }, new MerchantItem { House = house2 } } }; merchant.Id = "Merchant1"; repo.Save(merchant); } }
public void ET_Repository_DAL_Replace() { var repo = RF.Concrete <CarRepository>(); var item = repo.GetByReplacableDAL(); Assert.IsTrue(item.Name == "ImplementationReplaced"); }
public void SET_IntWithString_GetParentRef() { var repo = RF.Concrete <HouseMerchantRepository>(); var itemRepo = RF.Concrete <MerchantItemRepository>(); using (RF.TransactionScope(repo)) { var house = new House { Id = "House1" }; RF.Save(house); var merchant = new HouseMerchant { MerchantItemList = { new MerchantItem { House = house } } }; merchant.Id = "Merchant1"; repo.Save(merchant); var item = itemRepo.GetFirst(); Assert.IsTrue(item.HouseMerchantId == merchant.Id); } }
public void ET_Property_LazyList() { var repo = RF.Concrete <BookRepository>(); using (RF.TransactionScope(repo)) { var book = new Book { ChapterList = { new Chapter { Name = "c1" }, new Chapter { Name = "c2" }, } }; repo.Save(book); var book2 = repo.GetById(book.Id); Assert.IsTrue(!book2.FieldExists(Book.ChapterListProperty)); Assert.IsTrue(book2.GetProperty(Book.ChapterListProperty) == null); Assert.IsTrue(book2.ChapterList.Count == 2); } }
public void UtilsTest_TrasactionScope_Outer_RollBack() { var repo = RF.Concrete <TestUserRepository>(); Assert.IsTrue(repo.CountAll() == 0); using (var tranWhole = RF.TransactionScope(repo)) { repo.Save(new TestUser()); Assert.IsTrue(repo.CountAll() == 1); using (var tranSub = RF.TransactionScope(repo)) { repo.Save(new TestUser()); Assert.IsTrue(repo.CountAll() == 2); tranWhole.Complete(); } Assert.IsTrue(repo.CountAll() == 2); //外部不提交 } Assert.IsTrue(repo.CountAll() == 0, "外部事务未提交,整个事务不应该提交。"); }
public void ET_Repository_TableQuery() { var repo = RF.Concrete <ChapterRepository>(); using (RF.TransactionScope(repo)) { RF.Save(new Book { Name = "Book1", ChapterList = { new Chapter { Name = "Chapter1" }, } }); RF.Save(new Book { Name = "Book2", ChapterList = { new Chapter { Name = "Chapter4" }, } }); var table = repo.QueryChapterTable(1, PagingInfo.Empty); Assert.IsTrue(table.Rows.Count == 2); var bookName = table[0].GetString("BookName"); Assert.IsTrue(bookName.Contains("Book")); } }
public void UtilsTest_TrasactionScope_MultiDatabases() { var repoUser = RF.Concrete <TestUserRepository>(); Assert.IsTrue(repoUser.CountAll() == 0); var repoCustomer = RF.Concrete <CustomerRepository>(); Assert.IsTrue(repoCustomer.CountAll() == 0); using (var tranWhole = RF.TransactionScope(repoUser)) { repoUser.Save(new TestUser()); Assert.IsTrue(repoUser.CountAll() == 1); //另一数据的事务。 using (var tranSub = RF.TransactionScope(repoCustomer)) { repoUser.Save(new Customer()); Assert.IsTrue(repoCustomer.CountAll() == 1); //内部不提交 } tranWhole.Complete(); } Assert.IsTrue(repoCustomer.CountAll() == 0, "两个数据库的事务互不干扰,Customer 对应的数据库事务已经回滚。"); Assert.IsTrue(repoUser.CountAll() == 1, "两个数据库的事务互不干扰,TestUser 对应的数据库事务提交成功。"); DeleteUsers(); }
public void ET_Repository_Memory() { var repo = RF.Concrete <MemoryCustomerRepository>(); var items = repo.GetAll(); Assert.IsTrue(items.Count == 0); //添加 var customer = new MemoryCustomer { Name = "Huqf", Age = 10 }; repo.Save(customer); Assert.IsTrue(repo.CountAll() == 1); Assert.IsTrue(customer.PersistenceStatus == PersistenceStatus.Unchanged); //更新 items = repo.GetAll(); (items[0] as MemoryCustomer).Age = 11; repo.Save(items); items = repo.GetAll(); Assert.IsTrue((items[0] as MemoryCustomer).Age == 11); //删除 items.Clear(); repo.Save(items); Assert.IsTrue(repo.CountAll() == 0); }
public void UtilsTest_LiteDataTable_Query() { var repoUser = RF.Concrete <TestUserRepository>(); using (var tranWhole = RF.TransactionScope(repoUser)) { repoUser.Save(new TestUser() { Age = 1 }); repoUser.Save(new TestUser() { Age = 1 }); repoUser.Save(new TestUser() { Age = 1 }); using (var dba = DbAccesserFactory.Create(repoUser)) { var table = dba.QueryLiteDataTable("Select * from Users where id > {0}", 0); var columns = table.Columns; Assert.IsTrue(columns.Find("UserName") != null); Assert.IsTrue(columns.Find("Age") != null); var rows = table.Rows; Assert.IsTrue(rows.Count == 3); Assert.IsTrue(rows[0].Values.Length == columns.Count); Assert.IsTrue(rows[0].GetInt32("Age") == 1); } } }
public void ET_Repository_GetChildProperties() { var repo = RF.Concrete <BookRepository>(); var childProperties = repo.GetChildProperties(); Assert.IsTrue(childProperties.Count == 1); }
/// <summary> /// 在缓存的版本号中找到对应主键的数据。 /// </summary> /// <param name="classRegion"></param> /// <param name="scopeClassName"></param> /// <param name="scopeId"></param> /// <returns></returns> public ScopeVersion Find(string classRegion, string scopeClassName, string scopeId) { //检测是否过期 if (this._regionValues == null || this.IsExpired()) { lock (this) { if (this._regionValues == null) { var allValues = RF.Concrete <ScopeVersionRepository>().GetAll() as ScopeVersionList; this.SetAllValues(allValues); } //如果过期,则差异更新。 else if (this.IsExpired()) { var values = RF.Concrete <ScopeVersionRepository>().GetList(_serverTime); this.UpdateByDifference(values); } } } List <ScopeVersion> regionValues = null; if (this._regionValues.TryGetValue(classRegion, out regionValues)) { return(regionValues.FirstOrDefault(v => v.ScopeClass == scopeClassName && v.ScopeId == scopeId)); } return(null); }