private DAL() { Configurations = new MongoRepository <ConfigKeyValue, string>(); if (!Configurations.Exists(config => config.Key == "CurrentAccountId")) { Configurations.Add(new ConfigKeyValue { Key = "CurrentAccountId", Value = "0000000000000000" }); } if (!Configurations.Exists(config => config.Key == "CurrentSessionId")) { Configurations.Add(new ConfigKeyValue { Key = "CurrentSessionId", Value = "0000000000000000" }); } Users = new MongoRepository <User, string>(); Accounts = new MongoRepository <Account, string>(); Operations = new MongoRepository <Operation, string>(); Sessions = new MongoRepository <Session, string>(); BankIdToIpMapping = new Dictionary <string, string>(); ReadBankIdToIpMappingFromFile(); }
public ActionResult Display(string id) { Template template = null; ViewBag.isAdmin = isInRole(User.Identity.Name, "Admin"); if (templaterepo.Exists(c => c.Key == id)) { template = templaterepo.First(c => c.Key == id); ViewBag.flash = TempData["flash"]; } else { template = new Template() { Subject = id, Key = id, Body = "The page for this key does not yet exist" }; ViewBag.flash = buildFlash("warning", "Page does not exist", "A page for this key does not yet exist. Please contact your admin."); } return(View(template)); }
public ServiceResult Update(Department entity) { var isExists = _mongoRepository.Exists <Department>(a => a.Id != entity.Id && a.Name == entity.Name); if (isExists) { return(ServiceResult.IsSuccess("已存在相同名称的部门")); } _mongoRepository.Update(entity); return(ServiceResult.IsSuccess(AccountConstString.OperateSuccess)); }
public SignResponse SignUp(SignUpCommand command) { if (_recruitersRepository.Exists(rec => rec.Email == command.Email)) { return new SignResponse() { CanSignIn = false } } ; RecruiterEntity newEntity = _recruitersRepository.Add(new RecruiterEntity() { Email = command.Email, Password = command.Password, Gender = Gender.Unknown, RegisterStatus = RecruiterRegisterStatus.Register, SourceType = RecruiterSourceType.System, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, //RegisterStatusHistory = new List<BaseStatusHistory>() { new BaseStatusHistory() { Status = RecruiterRegisterStatus.Register, Date = DateTime.Now } }, FriendlyId = _recruitersRepository.GetNextId <RecruiterEntity>() }); return(new SignResponse() { CanSignIn = true, UserId = newEntity.Id, UserType = CvLocate.Common.EndUserDtoInterface.Enums.UserType.Recruiter }); } #endregion }
/// <summary> /// 编辑角色 /// </summary> /// <param name="entity"></param> /// <returns></returns> public ServiceResult Edit(Role entity) { entity.MenuActionIds = new ObjectId[] { }; entity.MenuId = new ObjectId[] { }; entity.CreateDateTime = DateTime.Now; var result = _mongoRepository.Exists <Role>(a => a.Id != entity.Id && a.Name == entity.Name); if (result) { return(ServiceResult.IsFailed("已存在相同名称的角色")); } return (_mongoRepository.Update(entity) ? ServiceResult.IsSuccess(AccountConstString.OperateSuccess) : ServiceResult.IsFailed(AccountConstString.OperateFailed)); }
public void AddAndUpdateTest() { var customerRepository = new MongoRepository <Customer>(); var customerManager = new MongoRepositoryManager <Customer>(); //_customerManager.Exists.ShouldBeFalse(); var customer = new Customer(); customer.FirstName = "Bob"; customer.LastName = "Dillon"; customer.Phone = "0900999899"; customer.Email = new CustomerEmail("*****@*****.**"); customer.HomeAddress = new Address { Address1 = "North kingdom 15 west", Address2 = "1 north way", City = "George Town", Country = "Alaska", PostCode = "40990" }; customerRepository.Add(customer); customerManager.Exists.ShouldBeTrue(); customer.Id.ShouldNotBeNullOrWhiteSpace(); // fetch it back var alreadyAddedCustomer = customerRepository.Where(c => c.FirstName == "Bob").Single(); alreadyAddedCustomer.ShouldNotBeNull(); customer.FirstName.ShouldBe(alreadyAddedCustomer.FirstName); customer.HomeAddress.Address1.ShouldBe(alreadyAddedCustomer.HomeAddress.Address1); alreadyAddedCustomer.Phone = "10110111"; alreadyAddedCustomer.Email = new CustomerEmail("*****@*****.**"); customerRepository.Update(alreadyAddedCustomer); // fetch by id now var updatedCustomer = customerRepository.GetById(customer.Id); updatedCustomer.ShouldNotBeNull(); alreadyAddedCustomer.Phone.ShouldBe(updatedCustomer.Phone); alreadyAddedCustomer.Email.Value.ShouldBe(updatedCustomer.Email.Value); customerRepository.Exists(c => c.HomeAddress.Country == "Alaska").ShouldBeTrue(); customerRepository.Delete(updatedCustomer); var exists = customerRepository.GetById(updatedCustomer.Id); exists.ShouldBeNull(); customerRepository.DeleteAll(); }
public void CanCheckIfDocumentExists() { var customerRepository = new MongoRepository <Customer>(); customerRepository.Add(this.TestCustomers); customerRepository.Count().ShouldBe(this.TestCustomers.Count); var exists = customerRepository.Exists(x => x.Id == this.TestCustomers[0].Id); exists.ShouldBeTrue(); customerRepository.Delete(this.TestCustomers); }
public void AddAndUpdateTest() { IRepository <Customer> _customerRepo = new MongoRepository <Customer>(); IRepositoryManager <Customer> _customerMan = new MongoRepositoryManager <Customer>(); Assert.IsFalse(_customerMan.Exists); var customer = new Customer(); customer.FirstName = "Bob"; customer.LastName = "Dillon"; customer.Phone = "0900999899"; customer.Email = "*****@*****.**"; customer.HomeAddress = new Address { Address1 = "North kingdom 15 west", Address2 = "1 north way", PostCode = "40990", City = "George Town", Country = "Alaska" }; _customerRepo.Add(customer); Assert.IsTrue(_customerMan.Exists); Assert.IsNotNull(customer.Id); // fetch it back var alreadyAddedCustomer = _customerRepo.Where(c => c.FirstName == "Bob").Single(); Assert.IsNotNull(alreadyAddedCustomer); Assert.AreEqual(customer.FirstName, alreadyAddedCustomer.FirstName); Assert.AreEqual(customer.HomeAddress.Address1, alreadyAddedCustomer.HomeAddress.Address1); alreadyAddedCustomer.Phone = "10110111"; alreadyAddedCustomer.Email = "*****@*****.**"; _customerRepo.Update(alreadyAddedCustomer); // fetch by id now var updatedCustomer = _customerRepo.GetById(customer.Id); Assert.IsNotNull(updatedCustomer); Assert.AreEqual(alreadyAddedCustomer.Phone, updatedCustomer.Phone); Assert.AreEqual(alreadyAddedCustomer.Email, updatedCustomer.Email); Assert.IsTrue(_customerRepo.Exists(c => c.HomeAddress.Country == "Alaska")); }
public void AddAndUpdateTest() { IRepository<Customer> _customerRepo = new MongoRepository<Customer>(); IRepositoryManager<Customer> _customerMan = new MongoRepositoryManager<Customer>(); Assert.IsFalse(_customerMan.Exists); var customer = new Customer(); customer.FirstName = "Bob"; customer.LastName = "Dillon"; customer.Phone = "0900999899"; customer.Email = "*****@*****.**"; customer.HomeAddress = new Address { Address1 = "North kingdom 15 west", Address2 = "1 north way", PostCode = "40990", City = "George Town", Country = "Alaska" }; _customerRepo.Add(customer); Assert.IsTrue(_customerMan.Exists); Assert.IsNotNull(customer.Id); // fetch it back var alreadyAddedCustomer = _customerRepo.Where(c => c.FirstName == "Bob").Single(); Assert.IsNotNull(alreadyAddedCustomer); Assert.AreEqual(customer.FirstName, alreadyAddedCustomer.FirstName); Assert.AreEqual(customer.HomeAddress.Address1, alreadyAddedCustomer.HomeAddress.Address1); alreadyAddedCustomer.Phone = "10110111"; alreadyAddedCustomer.Email = "*****@*****.**"; _customerRepo.Update(alreadyAddedCustomer); // fetch by id now var updatedCustomer = _customerRepo.GetById(customer.Id); Assert.IsNotNull(updatedCustomer); Assert.AreEqual(alreadyAddedCustomer.Phone, updatedCustomer.Phone); Assert.AreEqual(alreadyAddedCustomer.Email, updatedCustomer.Email); Assert.IsTrue(_customerRepo.Exists(c => c.HomeAddress.Country == "Alaska")); }
static void Main(string[] args) { var url = ""; var mongoRepository = new MongoRepository(url); var u = new User { Name = "skychen", BirthDateTime = new DateTime(1991, 2, 2), AddressList = new List <string> { "guangdong", "guangzhou" }, Sex = Sex.Son, Son = new User { Name = "xiaochenpi", BirthDateTime = DateTime.Now } }; mongoRepository.Add(u); mongoRepository.Update <User>(a => a.Id == u.Id, a => new User { Sex = Sex.Son, Age = a.Age + 2 }); var upResulr = mongoRepository.GetAndUpdate <User>(a => a.Id == u.Id, a => new User { Sex = Sex.Son }); var getResult = mongoRepository.Get <User>(a => a.Id == u.Id); getResult.Name = "superskychen"; mongoRepository.Update(getResult); mongoRepository.Exists <User>(a => a.Id == u.Id); mongoRepository.Delete <User>(a => a.Id == u.Id); }
static void Main(string[] args) { var url = "mongodb://192.168.50.138:27020"; var mongoRepository = new MongoRepository(url); var u = new User { Name = "Mr.right", BirthDateTime = new DateTime(1990, 1, 1), AddressList = new List <string> { "liaoning", "shenyang" }, Sex = Sex.Man, Son = new User { Name = "XiaoMu", BirthDateTime = DateTime.Now } }; var addresult = mongoRepository.Add(u); mongoRepository.Update <User>(a => a.Id == u.Id, a => new User { Sex = Sex.Man }); var upResulr = mongoRepository.GetAndUpdate <User>(a => a.Id == u.Id, a => new User { Sex = Sex.Man }); var getResult = mongoRepository.Get <User>(a => a.Id == u.Id); getResult.Name = "supermr.right"; mongoRepository.Update(getResult); mongoRepository.Exists <User>(a => a.Id == u.Id); mongoRepository.Delete <User>(a => a.Id == u.Id); }
static void Main(string[] args) { var url = "mongodb://10.1.20.143:27017"; var mongoRepository = new MongoRepository(url); var u = new User { Name = "skychen", BirthDateTime = new DateTime(1991, 2, 2), AddressList = new List <string> { "guangdong", "guangzhou" }, Sex = 1, Son = new User { Name = "xiaochenpi", BirthDateTime = DateTime.Now } }; var addresult = mongoRepository.Add(u); var upResulr = mongoRepository.GetAndUpdate <User>(a => a.Id == u.Id, a => new User { Sex = 3 }); var getResult = mongoRepository.Get <User>(a => a.Id == u.Id); getResult.Name = "superskychen"; mongoRepository.Update(getResult); mongoRepository.Update <User>(a => a.Id == u.Id, a => new User { AddressList = new List <string> { "guangdong", "jiangmen", "cuihuwan" } }); mongoRepository.Exists <User>(a => a.Id == u.Id); mongoRepository.Delete <User>(a => a.Id == u.Id); }
// // GET: /Home/ public ActionResult Index() { MongoRepository <Template> templaterepo = new MongoRepository <Template>(); ViewBag.isAdmin = isInRole(User.Identity.Name, "Admin"); Template template = null; string key = "Welcome"; if (templaterepo.Exists(c => c.Key == key)) { template = templaterepo.First(c => c.Key == key); } else { template = new Template() { Subject = "Welcome", Body = "A custom Welcome page has not been created for this <strong>application</strong> - you can create one under Admin - Templates" }; } return(View(template)); }
public bool Exists(Expression <Func <T, bool> > predicate) { return(entityRep.Exists(predicate)); }
static void Main(string[] args) { var url = "mongodb://192.168.88.141:27017/chengongtest"; var userRepository = new UserRepository(url); var sw = Stopwatch.StartNew(); var qwe = userRepository.Count <User2>(a => a.Age == 1000); var time = sw.Elapsed.TotalSeconds; var mongoRepository = new MongoRepository(url); var u = new User { Name = "skychen", BirthDateTime = new DateTime(1991, 2, 2), AddressList = new List <string> { "guangdong", "guangzhou" }, Sex = Sex.Son, Son = new User { Name = "xiaochenpi", BirthDateTime = DateTime.Now } }; mongoRepository.Add(u); mongoRepository.Update <User>(a => a.Id == u.Id, a => new User { Sex = Sex.Son, Age = a.Age + 2 }); var upResulr = mongoRepository.GetAndUpdate <User>(a => a.Id == u.Id, a => new User { Sex = Sex.Son }); u.AddressList = new List <string> { "111", "2222" }; mongoRepository.Update(u); var q = new User { AddressList = new List <string> { "111", "2222" } }; mongoRepository.Update <User>(a => a.Id == u.Id, a => new User { AddressList = q.AddressList }); mongoRepository.Update <User>(a => a.Id == u.Id, a => new User { AddressList = a.AddressList.Pull("asd1231123") }); mongoRepository.Update <User>(a => a.Id == u.Id, a => new User { AddressList = a.AddressList.Push("asd1231123") }); var getResult = mongoRepository.Get <User>(a => a.Id == u.Id); getResult.Name = "superskychen"; mongoRepository.Update(getResult); mongoRepository.Exists <User>(a => a.Id == u.Id); mongoRepository.Delete <User>(a => a.Id == u.Id); }
public void Exists_Normal_IsTrue() { var isExist = MongoRepository.Exists <Logs>(a => a.LogName == "CatchErrorLog"); Assert.IsTrue(isExist); }
public bool Exists(Expression <Func <Position, bool> > expression) { return(_mongoRepository.Exists(expression)); }
public void Exists_Normal_IsTrue() { var isExist = MongoRepository.Exists <User>(a => a.Name == "chengongeee"); Assert.IsTrue(isExist); }
public ServiceResult IsExists(string userName, string id) { return(_mongoRepository.Exists <Administrator>(a => a.Id != new ObjectId(id) && a.UserName == userName) ? ServiceResult.IsFailed("已存在该用户名") : ServiceResult.IsSuccess(AccountConstString.OperateSuccess)); }
/// <summary> /// 是否已存在名称 /// </summary> /// <param name="id"></param> /// <param name="name"></param> /// <returns></returns> public ServiceResult IsNameExists(string id, string name) { var isExists = _mongoRepository.Exists <Menu>(a => a.Id != id.ToObjectId() && a.Name == name); return(isExists ? ServiceResult.IsFailed("已存在该菜单名称") : ServiceResult.IsSuccess("")); }