public void Find_Should_Return_First_Ordered_Item_Which_Satisfies_Specification_WIth_Sorting_Predicate(IRepository<Contact, string> repository) { for (var i = 1; i <= 3; i++) { var contact = new Contact { Name = "Test User " + i }; repository.Add(contact); } var result = repository.Find(new Specification<Contact>(p => p.Name.StartsWith("Test")), new SortingOptions<Contact, string>(c => c.Name, true)); result.Name.ShouldEqual("Test User 3"); var result2 = repository.Find(new Specification<Contact>(p => p.Name.StartsWith("Test")), new SortingOptions<Contact, string>(c => c.Name, false)); result2.Name.ShouldEqual("Test User 1"); }
static void Main(string[] args) { IoC.Register(); _repo = IoC.Resolve<IRepository>(); var geos = _repo.Find<City>().ToList(); Console.WriteLine(string.Format("{0} total cities...", geos.Count())); int i =0; foreach (var geo in geos) { if (geo.Geography.GetType() == typeof(NetTopologySuite.Geometries.MultiPoint)) { Console.WriteLine(string.Format("{0} is a MultiPoint...", geo.Name)); var point = new NetTopologySuite.Geometries.Point(geo.Geography.Coordinates.First()); geo.Geography = point; _repo.Save<City>(geo); _repo.SubmitChanges(); Console.WriteLine(string.Format("{0} updated to Point...", geo.Name)); i++; } } Console.WriteLine(string.Format("{0} total Cities updated...", i)); Console.Read(); }
public static Guid? ValidateUser(IRepository repository, string username, string password) { var user = repository.Find<User>(x => x.Username == username).SingleOrDefault(); if (user == null) { return null; } if (user.VerifyPassword(password)) { return new Guid(user.Guid); } else { return null; } }
public void Setup() { context = new InMemoryDataContext(); repo = new Repository(context); // All tests will fail if the Create does not work repo.Context.Add(new Customer { FirstName = "Kevin", LastName = "Berry", Company = new Company("Improving Enterprises"), Email = "*****@*****.**", Phone = "(555)123-4567" }); repo.Context.Commit(); customerK = repo.Find(new FindCustomerByFirstName("Kevin")).First(); }
public List<BLL.BusinessObjects.Configuration> GetByModelID(int modelID) { // List<BLL.BusinessObjects.Configuration> BLLConfigurations = new List<BusinessObjects.Configuration>(); using (_ConfigurationRepository = new GenericRepository<DAL.DataEntities.Configuration>()) { List<DAL.DataEntities.Configuration> DALConfigurations = _ConfigurationRepository.Find(m => m.ModelID == modelID).ToList<DAL.DataEntities.Configuration>(); DALConfigurations.ForEach(DALentity => BLLConfigurations.Add(BLL.BusinessObjects.Configuration.CreateInstance(DALentity))); } return BLLConfigurations; }
public List<BLL.BusinessObjects.Feature> GetByModelID(int ModelID) { // List<BLL.BusinessObjects.Feature> BFeatures; using (_FeatureRepository = new GenericRepository<DAL.DataEntities.Feature>()) { IEnumerable<DAL.DataEntities.Feature> DALfeatures = _FeatureRepository.Find(m => m.ModelID == ModelID); //Create Business objects for each DAL object BFeatures = new List<BusinessObjects.Feature>(); foreach (DAL.DataEntities.Feature DALfeature in DALfeatures) { //Create the BLL feature BLL.BusinessObjects.Feature BLLfeature = BLL.BusinessObjects.Feature.CreateInstance(DALfeature); BFeatures.Add(BLLfeature); } } return BFeatures; }
public IEnumerable <AnimalWeight> Find(Func <AnimalWeight, bool> predicate) { return(_animalweightRepository.Find(predicate).ToList()); }
public List<BLL.BusinessObjects.UITemplate> GetByUserID(int userid, bool excludeContentAndCSS = false) { // List<BLL.BusinessObjects.UITemplate> BUITemplates; using (_UITemplateRepository = new GenericRepository<DAL.DataEntities.UITemplate>()) { List<DAL.DataEntities.UITemplate> templates = _UITemplateRepository.Find(m => m.UserID == userid).ToList<DAL.DataEntities.UITemplate>(); //Create Business objects for each DAL object BUITemplates = new List<BusinessObjects.UITemplate>(); foreach (DAL.DataEntities.UITemplate template in templates) { if (excludeContentAndCSS) { template.Content = ""; template.Stylesheet = ""; } BUITemplates.Add((BLL.BusinessObjects.UITemplate)BLL.BusinessObjects.UITemplate.CreateInstance(template)); } } return BUITemplates; }
///<summary> ///<para>Retorna os registros do banco de dados que atendem ao predicado passado como parâmetro</para> ///<para>retorna os registros com o [Include] para as classes passadas como parâmetro</para> ///</summary> public IEnumerable <TEntity> Find(Expression <Func <TEntity, bool> > where, params string[] includes) { IEnumerable <TEntity> entity = repository.Find(where, includes); return(entity); }
public IEnumerable <OrderItem> Find(Func <OrderItem, bool> predicate) { return(_OrderItemRepository.Find(predicate)); }
/// <summary> /// 用户登录 /// </summary> /// <param name="name">账户名</param> /// <param name="psd">账户密码</param> /// <returns>Account</returns> public Account Logon(UserLogOnModel model) { Account user = null; //创建账户仓储 IRepository <Account> accountRep = FBS.Factory.Factory <IRepository <Account> > .GetConcrete <Account>(); ISpecification <Account> namespec; if (string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.UserName)) { //昵称登录 namespec = new Specification <Account>(o => o.UserName == model.UserName); } else if (string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.Email)) { //邮箱登录 namespec = new Specification <Account>(o => o.Email == model.Email);//查询条件 } else { throw new NullReferenceException("用户登录时,用户名和邮箱至少使用一个"); } if (accountRep.Exists(namespec))//这个账户是否存在 { user = accountRep.Find(namespec); if (!user.CheckPsd(model.Password)) { throw new LogonException("密码错误");//账户存在,密码错误 } else { if (new UserEntryService().CheckForbidden(user.Id)) { throw new LogonException("您由于不遵守相关规定,账户被禁用");//您由于不遵守相关规定,账户被禁用 } //将Identify更新到HttpContext中 UserIdentity u = new UserIdentity("Forms", true, user.Id.ToString()); /*UserInfoService uis=new UserInfoService(); * string[] roles=uis.GetUserRoles(user.Id);*/ string[] roles = user.Roles.Split('|'); if (roles == null) { roles = new string[1] { string.Empty } } ; System.Security.Principal.GenericPrincipal gp = new System.Security.Principal.GenericPrincipal(u, roles); HttpContext.Current.User = gp; //添加ticket到cookie FormsAuthenticationTicket ticket = AuthenticationHelper.CreateAuthenticationTicket(user.Id.ToString(), user.UserName, model.RememberMe); AuthenticationHelper.SetAuthenticalCookie(ticket); } } else { throw new LogonException("账户不存在");//账户不存在 } return(user); }
public List<BLL.BusinessObjects.CustomRule> GetByModelID(int ModelID) { // List<BLL.BusinessObjects.CustomRule> BCustomRules; using (_CustomRuleRepository = new GenericRepository<DAL.DataEntities.CustomRule>()) { IEnumerable<DAL.DataEntities.CustomRule> customRules = _CustomRuleRepository.Find(m => m.ModelID == ModelID); //Create Business objects for each DAL object BCustomRules = new List<BusinessObjects.CustomRule>(); foreach (DAL.DataEntities.CustomRule customRule in customRules) { BCustomRules.Add((BLL.BusinessObjects.CustomRule)BLL.BusinessObjects.CustomRule.CreateInstance(customRule)); } } return BCustomRules; }
public IList <Mentor> GetAllMentors() { return(_mentorRepository.Find(m => m != null).ToList()); }
public JobReceiveHeaderExtended Find(int id) { return(_JobReceiveHeaderExtendedRepository.Find(id)); }
public List <Post> GetPostsByUser(int id) { return(postRepository.Find(p => p.UserId == id).ToList()); }
public bool Remove(long accountId, long applianceId, long timerTypeId) { var notificationPreference = repoNotificationPreference.Find(x => x.AccountId == accountId && x.ApplianceId == applianceId && x.EventTypeId == timerTypeId); return(repoNotificationPreference.Delete(notificationPreference)); }
public IEnumerable <Category> Find(Func <Category, bool> predicate) { return(_CategoryRepository.Find(predicate)); }
public void Find_Should_Return_Single_Item_Which_Satisfies_Predicate(IRepository<Contact, string> repository) { for (var i = 1; i <= 3; i++) { var contact = new Contact { Name = "Test User " + i }; repository.Add(contact); } var result = repository.Find(p => p.Name == "Test User 1"); result.Name.ShouldEqual("Test User 1"); }
public List<BLL.BusinessObjects.Model> GetByUserID(int userid) { // List<BLL.BusinessObjects.Model> BModels; using (_ModelRepository = new GenericRepository<DAL.DataEntities.Model>()) { List<DAL.DataEntities.Model> models = _ModelRepository.Find(m => m.UserID == userid).ToList<DAL.DataEntities.Model>(); //Create Business objects for each DAL object BModels = new List<BusinessObjects.Model>(); foreach (DAL.DataEntities.Model model in models) { BModels.Add((BLL.BusinessObjects.Model)BLL.BusinessObjects.Model.CreateInstance(model)); } } return BModels; }
public DocumentTable Find(Guid?id) { return(repoDocument.Find(a => a.Id == id)); }
public IEnumerable <TemplateInvoice> GetAll() { return(_templateInvoice.Find()); }
public MenuModule Find(int id) { return(_ModuleRepository.Find(id)); }
public async Task DeleteAsync(User user) { await Task.Run(() => { try { var dbUser = _repository.Find(f => f.Id.ToString() == user.Id); Mapper.Map(user, dbUser); dbUser.Roles.Clear(); _repository.Update(dbUser); _repository.Delete(dbUser); } catch (Exception exception) { //TODO: log here throw; } }); }
public JobCategory GetById(int id) { var cat = categoryRepository.Find(x => x.Id == id); return(cat); }
public bool CanUserSignIn(string email, string password) { return(_userRepository.Find(user => user.Email == email && user.Password == password).Any()); }
public Medic Find(int id) { return(_repository.Find(id)); }
public ActionResult Edit(int id) { return(View(ProStatusRepository.Find(id))); }
public IList <IViewActivityByHour> Find(IDataQuery query) { IList <IViewActivityByHour> collection = _repositorieDAL.Find(query); return(collection); }
public virtual T Find <T>(ISpecification <T> criteria) where T : class { return(_repository.Find(criteria)); }
public List<BLL.BusinessObjects.GroupRelation> GetByModelID(int ModelID) { // List<BLL.BusinessObjects.GroupRelation> BLLGroupRelations; using (_GroupRelationRepository = new GenericRepository<DAL.DataEntities.GroupRelation>()) { //Get all DAL groupRelation entities IEnumerable<DAL.DataEntities.GroupRelation> DALgroupRelations = _GroupRelationRepository.Find(m => m.ModelID == ModelID); //Create Business objects for each DAL object BLLGroupRelations = new List<BusinessObjects.GroupRelation>(); foreach (DAL.DataEntities.GroupRelation DALgroupRelation in DALgroupRelations) { //Business object BLL.BusinessObjects.GroupRelation BLLGroupRelation = (BLL.BusinessObjects.GroupRelation)BLL.BusinessObjects.GroupRelation.CreateInstance(DALgroupRelation); BLLGroupRelations.Add(BLLGroupRelation); } } return BLLGroupRelations; }
public IQueryable <DefectCode> Find(Expression <Func <DefectCode, bool> > exp) { return(_app.Find(exp)); }
public List<BLL.BusinessObjects.Constraint> GetByModelID(int ModelID) { // List<BLL.BusinessObjects.Constraint> BConstraints; using (_ConstraintRepository = new GenericRepository<DAL.DataEntities.Constraint>()) { IEnumerable<DAL.DataEntities.Constraint> customRules = _ConstraintRepository.Find(m => m.ModelID == ModelID); //Create Business objects for each DAL object BConstraints = new List<BusinessObjects.Constraint>(); foreach (DAL.DataEntities.Constraint customRule in customRules) { BConstraints.Add((BLL.BusinessObjects.Constraint)BLL.BusinessObjects.Constraint.FromDataEntity(customRule)); } } return BConstraints; }
public IEnumerable <string> FindBySessionId(int sessionId) { return(sessionIdRepository.Find(id => id == sessionId).Select(x => x.Key)); }
private static async Task<bool> FindUserByEmailAsync(IRepository<User> usersColl, string email) { var foundUser = await usersColl.Find(u => u.Email == email).FirstOrDefaultAsync(); return (null != foundUser); }
public IEnumerable <string> FindByAccessToken(string accessToken) { return(connectionRepository.Find(context => context.GetHttpContext().Request.Query["access_token"].ToString() == accessToken).Select(x => x.Key)); }
public void Delete(int id) { DAL.DataEntities.Feature feature; using (_FeatureRepository = new GenericRepository<DAL.DataEntities.Feature>()) { feature = _FeatureRepository.SingleOrDefault(m => m.ID == id); //Cascade delete on all related FeatureSelections using (_FeatureSelectionRepository = new GenericRepository<DAL.DataEntities.FeatureSelection>()) { IEnumerable<DAL.DataEntities.FeatureSelection> featureSelections = _FeatureSelectionRepository.Find(k => k.FeatureID == feature.ID); foreach (DAL.DataEntities.FeatureSelection featureSelection in featureSelections) { _FeatureSelectionRepository.Delete(featureSelection); } _FeatureSelectionRepository.SaveChanges(); } // _FeatureRepository.Delete(feature); _FeatureRepository.SaveChanges(); } }
public void Find_Should_Return_Single_Item_Which_Satisfies_Composite_Specification(IRepository<Contact, string> repository) { for (var i = 1; i <= 3; i++) { var contact = new Contact { Name = "Test User " + i }; repository.Add(contact); } var result = repository.Find(new Specification<Contact>(p => p.Name == "Test User 1").OrElse(new Specification<Contact>(p => p.Name == "Test User 1000"))); result.Name.ShouldEqual("Test User 1"); }
public DomainEntity Find(Guid id, IRepository repository) { return(repository.Find <T>(id)); }
public IQueryable <Equipment> Find(Expression <Func <Equipment, bool> > exp) { return(_app.Find(exp)); }
public async Task <IEnumerable <LessonDTO> > GetLessonsByCourseIdAsync(int id) { var lessons = await lessonRepository.Find(l => l.CourseId == id); return(mapper.Map <IEnumerable <LessonDTO> >(lessons)); }
public Order GetOrder(string Id) { return(orderContext.Find(Id)); }
public List<BLL.BusinessObjects.Relation> GetByModelID(int ModelID) { // List<BLL.BusinessObjects.Relation> BRelations; using (_RelationRepository = new GenericRepository<DAL.DataEntities.Relation>()) { IEnumerable<DAL.DataEntities.Relation> relations = _RelationRepository.Find(m => m.ModelID == ModelID); //Create Business objects for each DAL object BRelations = new List<BusinessObjects.Relation>(); foreach (DAL.DataEntities.Relation relation in relations) { BRelations.Add((BLL.BusinessObjects.Relation)BLL.BusinessObjects.Relation.CreateInstance(relation)); } } return BRelations; }
public IList <IProfile> Find(IDataQuery query) { IList <IProfile> collection = _repositorieDAL.Find(query); return(collection); }
//Methods public List<BLL.BusinessObjects.Attribute> GetByFeatureID(int FeatureID) { // List<BLL.BusinessObjects.Attribute> BLLAttributes; using (_AttributeRepository = new GenericRepository<DAL.DataEntities.Attribute>()) { IEnumerable<DAL.DataEntities.Attribute> DALAttributes = _AttributeRepository.Find(m => m.FeatureID == FeatureID); //Create Business objects for each DAL object BLLAttributes = new List<BusinessObjects.Attribute>(); foreach (DAL.DataEntities.Attribute DALAttribute in DALAttributes) { //Create the BLL object BLL.BusinessObjects.Attribute BLLAttribute = BLL.BusinessObjects.Attribute.CreateInstance(DALAttribute); BLLAttributes.Add(BLLAttribute); } } return BLLAttributes; }
public async Task Execute( IRepository <Product, int> globalProductRepository, IServiceProvider serviceProvider, IHubContext <MessagesHub> messageHubContext, ITelegramBotClient telegramBotClient = null) { Log.Information("Running {Source} Monitor.", AlertSource.Products); var sourceChanged = false; var storedProducts = globalProductRepository.Find(product => product.IsEnabled).ToList(); await storedProducts.ParallelForEachAsync( async storedProduct => { var serviceScope = serviceProvider.CreateScope(); var serviceScopeServiceProvider = serviceScope.ServiceProvider; var productRepository = serviceScopeServiceProvider.GetService <IRepository <Product, int> >(); var productScrapper = serviceProvider.GetService <IEntityScraper <Product> >(); var userRepository = serviceScopeServiceProvider.GetService <IRepository <User, int> >(); var dateTime = DateTime.Now; var product = await productScrapper.GetAsync(storedProduct.Url, true); IDbContextTransaction transaction = null; Log.Information("Updating scrapped product '{url}'", storedProduct.Url); if (product == null) { product = storedProduct; if (product.IsAvailable) { transaction = PolicyHelper.WaitAndRetry().Execute( () => productRepository.BeginTransaction(IsolationLevel.Serializable)); product.IsAvailable = false; product.Updated = dateTime; product.Sha256 = JsonSerializer.Serialize(storedProduct).ComputeSha256(); sourceChanged = true; Log.Information( "Product {Product} from {Store} has changed. Is Available: {IsAvailable}", storedProduct.Name, storedProduct.Store, storedProduct.IsAvailable); } } else if (product.Sha256 != storedProduct.Sha256) { transaction = PolicyHelper.WaitAndRetry().Execute( () => productRepository.BeginTransaction(IsolationLevel.Serializable)); product.Id = storedProduct.Id; product.Updated = dateTime; productRepository.TryAddOrUpdate(product, nameof(Product.Added), nameof(Product.Read)); sourceChanged = true; Log.Information( "Product {Product} from {Store} has changed. Is Available: {IsAvailable}", product.Name, product.Store, product.IsAvailable); } if (transaction != null) { await productRepository.SaveChangesAsync(); await transaction.CommitAsync(); var productDataTransferObject = product.ToDataTransferObject(true); var message = JsonSerializer.Serialize(productDataTransferObject); await messageHubContext.Clients.All.SendAsync( ClientMethods.EntityChanged, AlertSource.Products, message); Log.Information("Entity changed at source {Source}.", AlertSource.Products); if (telegramBotClient != null) { var messageStringBuilder = new StringBuilder(); messageStringBuilder.AppendLine("*Product Changed*"); messageStringBuilder.AppendLine($"*Name:* _{productDataTransferObject.Name}_"); messageStringBuilder.AppendLine( $"*Price:* _{productDataTransferObject.Price.ToString("C")} {productDataTransferObject.Currency}_"); messageStringBuilder.AppendLine( $"*Is Available:* _{productDataTransferObject.IsAvailable}_"); messageStringBuilder.AppendLine( $"*Is In Cart:* _{productDataTransferObject.IsInCart}_"); if (productDataTransferObject.IsAvailable) { messageStringBuilder.AppendLine( $"*Link:* [{productDataTransferObject.Url}]({productDataTransferObject.Url})"); } messageStringBuilder.AppendLine($"*Store:* _{productDataTransferObject.Store}_"); messageStringBuilder.AppendLine( $"*Department:* _{productDataTransferObject.Department}_"); messageStringBuilder.AppendLine( $"*Category:* _{productDataTransferObject.DepartmentCategory}_"); var markdownMessage = messageStringBuilder.ToString(); var users = userRepository.Find(user => user.IsEnable).ToList(); foreach (var user in users) { try { await telegramBotClient.SendTextMessageAsync( user.ChatId, markdownMessage, ParseMode.Markdown); } catch (Exception e) { Log.Error(e, "Error sending message via telegram to {UserName}", user.Name); } } } } }); Log.Information( sourceChanged ? "{Source} changes detected" : "No {Source} changes detected", AlertSource.Products); }
private void VerifyPlayerDataDeleted(Player player, IRepository repository) { // verify that player is deleted Assert.IsEmpty(repository.Find<Player>(x => x.Id == player.Id)); // verify that actions, cards, and messages are deleted Assert.IsEmpty(repository.Find<Haven.Action>(x => x.OwnerId == player.Id)); Assert.IsEmpty(repository.Find<PlayerNameCard>(x => x.PlayerId == player.Id)); Assert.IsEmpty(repository.Find<PlayerSafeHavenCard>(x => x.PlayerId == player.Id)); Assert.IsEmpty(repository.Find<Message>(x => x.PlayerId == player.Id)); }
public virtual TEntity GetById(object id) { return(Repository.Find(id)); }
public List<BLL.BusinessObjects.Model> GetByUserID_Shallow(int userid) { // List<BLL.BusinessObjects.Model> BModels; using (_ModelRepository = new GenericRepository<DAL.DataEntities.Model>()) { //Shallow retreival _ModelRepository.GetContext().ContextOptions.LazyLoadingEnabled = false; // List<DAL.DataEntities.Model> models = _ModelRepository.Find(m => m.UserID == userid).ToList<DAL.DataEntities.Model>(); //Create Business objects for each DAL object BModels = new List<BusinessObjects.Model>(); foreach (DAL.DataEntities.Model model in models) { BModels.Add((BLL.BusinessObjects.Model)BLL.BusinessObjects.Model.CreateInstance(model)); } } return BModels; }
private TRole _findById(string roleId) { return((TRole)_roleRepository.Find(x => x.Id == roleId).ToSingleOrDefault()); }