public void Delete_Should_Remove_Item_By_Key(IRepository<Contact, string> repository) { var contact = new Contact { Name = "Test User" }; repository.Add(contact); var result = repository.Get(contact.ContactId); result.ShouldNotBeNull(); repository.Delete(contact.ContactId); result = repository.Get(contact.ContactId); result.ShouldBeNull(); }
public OrderShippingPartHandler( IRepository<OrderShippingPartRecord> repository, IRepository<OrderAddressRecord> orderAddressRepository) { Filters.Add(StorageFilter.For(repository)); OnActivated<OrderShippingPart>((context, part) => { part._shippingDetails.Loader(shippingDetails => { var orderPart = context.ContentItem.As<OrderPart>(); if (orderPart != null) { return orderPart.Details.Where(d => d.DetailType == "Shipping"); } else { return new List<OrderDetail>(); } }); part._shippingAddress.Loader(shippingAddress => orderAddressRepository.Get(part.ShippingAddressId)); }); OnCreated<OrderShippingPart>((context, part) => { part.ShippingAddressId = orderAddressRepository.CreateOrUpdate(part.ShippingAddress); }); OnUpdated<OrderShippingPart>((context, part) => { part.ShippingAddressId = orderAddressRepository.CreateOrUpdate(part.ShippingAddress); }); }
public GiveCampSettings() { repository = new EntityFrameworkRepository(); var settings = repository.Get<EventSetting>(x => x.Id == DefaultId); HttpRuntime.Cache.Insert("Settings", settings, null, DateTime.Now.AddMinutes(10d), System.Web.Caching.Cache.NoSlidingExpiration); }
public HasTagsHandler(IRepository<Tag> tagsRepository, IRepository<TagsContentItems> tagsContentItemsRepository) { OnLoading<HasTags>((context, tags) => { // provide names of all tags on demand tags._allTags.Loader(list => tagsRepository.Table.ToList()); // populate list of attached tags on demand tags._currentTags.Loader(list => { var tagsContentItems = tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id); foreach (var tagContentItem in tagsContentItems) { var tag = tagsRepository.Get(tagContentItem.TagId); list.Add(tag); } return list; }); }); OnRemoved<HasTags>((context, ht) => { tagsContentItemsRepository.Flush(); HasTags tags = context.ContentItem.As<HasTags>(); foreach (var tag in tags.CurrentTags) { if (!tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id).Any()) { tagsRepository.Delete(tag); } } }); }
static async Task MainAsync(IRepository<SampleEntity> repo) { foreach (var s in await repo.GetAllAsync()) { Console.WriteLine("{0} | {1}", s.ID, s.Name); } // Paged Set // Console.WriteLine("\nPage = 2 - Page Size = 2 :"); var some = await repo.GetAsync(2, 2, s => s.ID); foreach (var s in some) { Console.WriteLine("{0} | {1}", s.ID, s.Name); } // Updating // var fox = await repo.FindAsync(e => e.Name == "Fox"); fox.Name = "Dog"; repo.Update(fox, fox.ID); // Deleting // Console.WriteLine("\n " + await repo.DeleteAsync(repo.Get(5)) + "\n"); foreach (var e in repo.GetAll()) Console.WriteLine(e.ID + " | " + e.Name); }
public LowHealthUnitsWalkTogetherRule(ComponentService componentService, AIDto ai, IRepository<GameEnvironment> gameEnvironmentRepository, IVector2Service vector2Service, IEventStoreService eventStoreService) { _componentService = componentService; _ai = ai; _vector2Service = vector2Service; _eventStoreService = eventStoreService; _gameEnvironment = gameEnvironmentRepository.Get(); }
public void Get_With_String_Selector_Should_Return_Item_If_Item_Exists(IRepository<Contact, string> repository) { var contact = new Contact { Name = "Test User" }; repository.Add(contact); var result = repository.Get(contact.ContactId, c => c.Name); result.ShouldEqual("Test User"); }
private static void GetPushEventExample(IRepository<EventPushCampaign> eventPushRepo) { var e = eventPushRepo.Get(4251); Console.WriteLine("Fetched event: {0}", e.Id); Console.WriteLine("Channels: {0}", String.Join(", ", e.ChannelIds)); Console.WriteLine("Targets: {0}", String.Join(", ", e.Targets)); }
public void CombineDecisions(IAccessDecisionCombinator combinator, IRepository<Role> roleRepository) { if (_disabled) return; foreach (var roleId in _roles) { roleRepository.Get(roleId).CombineDecisions(combinator); } }
public PeopleViewModel(IRepository<Person> repository, IEventAggregator eventAggregator) { People = new ListCollectionView(repository.Get()); People.CurrentChanged += new EventHandler(OnSelectedItemChanged); this.eventAggregator = eventAggregator; }
public void Update_Should_Save_Modified_Business_Name(IRepository<Contact, string> repository) { var contact = new Contact { Name = "Test User" }; repository.Add(contact); var contact2 = new Contact { Name = "Test User 2" }; repository.Add(contact2); contact.Name = "Test User - Updated"; repository.Update(contact); var updated = repository.Get(contact.ContactId); var notUpdated = repository.Get(contact2.ContactId); updated.Name.ShouldEqual("Test User - Updated"); notUpdated.Name.ShouldEqual("Test User 2"); }
public void Get_With_Anonymous_Class_Selector_Should_Return_Item_If_Item_Exists(IRepository<Contact, string> repository) { var contact = new Contact { Name = "Test User", ContactTypeId = 2 }; repository.Add(contact); var result = repository.Get(contact.ContactId, c => new { c.ContactTypeId, c.Name }); result.ContactTypeId.ShouldEqual(2); result.Name.ShouldEqual("Test User"); }
public void Get_Should_Return_Item_If_Item_Exists(IRepository<Contact, string> repository) { var contact = new Contact { Name = "Test User", ContactTypeId = 1 }; repository.Add(contact); var result = repository.Get(contact.ContactId); result.Name.ShouldEqual(contact.Name); result.ContactTypeId.ShouldEqual(contact.ContactTypeId); }
public BuildBarrackRule(ComponentService componentService, AIDto ai, IOrientationService orientationService, IVector2Service vector2Service, IRepository<GameEnvironment> gameEnvironmentRepository, IEventStoreService eventStoreService) { _componentService = componentService; _ai = ai; _orientationService = orientationService; _vector2Service = vector2Service; _eventStoreService = eventStoreService; _gameEnvironment = gameEnvironmentRepository.Get(); }
public void Using_TransactionScope_Without_Complete_Should_Not_Add(IRepository<Contact, string> repository) { repository.Get("test"); // used to create the SqlCe database before being inside the transaction scope since that throws an error using (var trans = new TransactionScope()) { repository.Add(new Contact {Name = "Contact 1"}); } repository.GetAll().Count().ShouldEqual(0); }
private static Setting GetSetting(string settingName, IRepository repository) { var setting = repository.Get<Setting>(settingName.Encrypt()); if (setting == null) { setting = InitializeSetting(settingName, repository); } return setting; }
public JustEatModule(IRepository repository) { this.repository = repository; Get["/restaurants/{outcode}"] = parameters => { var outcode = parameters.outcode; var results = repository.Get(outcode).Result; return View["Finder", results]; }; Get["/restaurants/"] = parameters => { var results = repository.Get("").Result; return View["Finder", results]; }; }
public void Delete_Should_Wait_To_Remove_Item_If_Item_Exists_In_BatchMode(IRepository<Contact, string> repository) { var contact = new Contact { Name = "Test User" }; repository.Add(contact); var result = repository.Get(contact.ContactId); result.ShouldNotBeNull(); using (var batch = repository.BeginBatch()) { batch.Delete(contact); // not really delete until call Save, because in BatchMode result = repository.Get(contact.ContactId); result.ShouldNotBeNull(); batch.Commit(); // actually do the delete } result = repository.Get(contact.ContactId); result.ShouldBeNull(); }
public static void ListActions(IRepository repository, int gameId) { var game = repository.Get<Game>(gameId); foreach (Player player in game.Players) { Console.WriteLine(string.IsNullOrWhiteSpace(player.Name) ? string.Format("Player {0}:", player.Id) : player.Name + ": "); Console.WriteLine(string.Format("On {0}", player.SpaceId)); foreach (Haven.Action a in player.Actions) { Console.WriteLine(a.Id + ") " + a); } } }
public OrderPartHandler( IRepository<OrderPartRecord> repository, IContentManager contentManager, IRepository<OrderDetailRecord> orderDetailsRepository, IOrdersService ordersService, IRepository<OrderAddressRecord> orderAddressRepository) { _orderDetailsRepository = orderDetailsRepository; Filters.Add(StorageFilter.For(repository)); OnActivated<OrderPart>((context, part) => { // Details part._details.Loader(details => _orderDetailsRepository.Fetch(d => d.OrderId == part.Id) .Select(d => new OrderDetail(d)) .ToList()); // Order total part._orderTotal.Loader(orderTotal => BuildOrderTotal(part)); // BillingAddress part._billingAddress.Loader(shippingAddress => orderAddressRepository.Get(part.BillingAddressId)); }); OnLoading<OrderPart>((context, part) => { // Order total part._orderTotal.Loader(orderTotal => part.Retrieve(x => x.OrderTotal)); }); OnCreating<OrderPart>((context, part) => { if (String.IsNullOrWhiteSpace(part.Reference)) { part.Reference = ordersService.BuildOrderReference(); } }); OnCreated<OrderPart>((context, part) => { // Order total part.OrderTotal = BuildOrderTotal(part); SaveDetails(part); part.BillingAddressId = orderAddressRepository.CreateOrUpdate(part.BillingAddress); }); OnUpdated<OrderPart>((context, part) => { // Order total part.OrderTotal = BuildOrderTotal(part); SaveDetails(part); part.BillingAddressId = orderAddressRepository.CreateOrUpdate(part.BillingAddress); }); }
public static void PerformAction(IRepository repository, int gameId, int actionId) { Console.Write("Input: "); var input = Console.ReadLine(); if (string.IsNullOrWhiteSpace(input)) { input = null; } var action = repository.Get<Haven.Action>(actionId); action.PerformAction(input); var latestMessage = action.Owner.Messages.First(); Console.WriteLine(latestMessage.Text); }
public PackageModule(IRepository<User> users) { Post["/Packages/GetPackage"] = parameters => { var dto = this.Bind<PDto>(); var user = users.Get(dto.UserId); var contractDto = Mapper.Map<Contract, ContractDto>(user.Contracts.First()); if(!contractDto.Packages.Any()) throw new Exception("No packages for contract"); return Response.AsJson(new { PackageId = contractDto.Packages.First().Key }); }; }
public void GetContact_ContactExists_ContactReturned( TestIndexUtils contactIndex, IRepository<ElasticContact> repo, ElasticContact contact, ISystemContext ctx) { using (contactIndex) { repo.Save(contact, ctx); var res = repo.Get(contact.Id, ctx); res.Should().NotBeNull(); res.Id.Should().Be(contact.Id); } }
public static Comment CreateOrLoadComment( CommentModel comment, IRepository<Comment> commentRepository, DbUsersRepository usersRepository) { Comment commentEntity = commentRepository.Get(comment.ID); if (commentEntity != null) { return commentEntity; } Comment newComment = CommentsMapper.ToCommentEntity(comment, usersRepository); return newComment; }
public static Mark CreateOrLoadMark(IRepository<Mark> repository, Mark entity) { Mark mark = repository.Get(entity.MarkId); if (mark != null) { return mark; } Mark newAlbum = repository.Add(new Mark() { Subject = entity.Subject, Value = entity.Value }); return newAlbum; }
public static Comment ToCommentEntity( CommentModel commentModel, DbUsersRepository usersRepository, IRepository<NewsArticle> newsArticlesRepository) { Comment commentEntity = new Comment() { Content = commentModel.Content, Date = commentModel.Date, Author = usersRepository.GetByNickname(commentModel.Author) }; NewsArticle newsArticle = newsArticlesRepository.Get(commentModel.ArticleID); newsArticle.Comments.Add(commentEntity); return commentEntity; }
public static School CreateOrLoadSong(IRepository<School> repository, School entity) { School school = repository.Get(entity.SchoolId); if (school != null) { return school; } School newSchool = repository.Add(new School() { Name = entity.Name, Location = entity.Location, Students = entity.Students }); return newSchool; }
public static Session Create(Guid competitionId, IRepository<Competition> competitionRepository) { var operationChecker = new OperationChecker(competitionRepository); if (!operationChecker.IsRunning(competitionId)) { throw new Exception("Cannot create session for non-running competition."); } var session = new Session(operationChecker) { CompetitionId = competitionId, Schedule = Schedule.Create(competitionRepository.Get(competitionId).GetOptions()), Outcomes = new List<Outcome>() }; return session; }
public static Song CreateOrLoadSong(IRepository<Song> repository, Song entity) { Song song = repository.Get(entity.SongId); if (song != null) { return song; } Song newSong = repository.Add(new Song() { Title = entity.Title, Year = entity.Year, Genre = entity.Genre, Album = entity.Album, Artist = entity.Artist }); return newSong; }
public static Artist CreateOrLoadArtist(IRepository<Artist> repository, Artist entity) { Artist artist = repository.Get(entity.ArtistId); if (artist != null) { return artist; } Artist newArtist = repository.Add(new Artist() { Name = entity.Name, Country = entity.Country, DateOfBirth = entity.DateOfBirth, Songs = entity.Songs, Albums = entity.Albums }); return newArtist; }
public IActionResult Index() { var categories = _repository.Get().OrderBy(c => c.Title); return(View("Index", categories)); }
public static void ResourceGroupRender(FrontContext context, string id) { var db = context.SiteDb; var group = db.ResourceGroups.GetByNameOrId(id, ConstObjectType.Style); if (group == null) { group = db.ResourceGroups.GetByNameOrId(id, ConstObjectType.Script); } if (group == null) { group = db.ResourceGroups.TableScan.Where(o => Lib.Helper.StringHelper.IsSameValue(o.Name, id)).FirstOrDefault(); } if (group == null) { return; } IRepository repo = null; string spliter = "\r\n"; switch (group.Type) { case ConstObjectType.Style: context.RenderContext.Response.ContentType = "text/css;charset=utf-8"; repo = context.SiteDb.Styles as IRepository; break; case ConstObjectType.Script: context.RenderContext.Response.ContentType = "text/javascript;charset=utf-8"; repo = context.SiteDb.Scripts as IRepository; spliter = ";\r\n"; //need split with newline ,otherwise two different combinations of comments will report an error break; default: break; } StringBuilder sb = new StringBuilder(); long totalversion = 0; foreach (var item in group.Children.OrderBy(o => o.Value)) { var route = context.SiteDb.Routes.Get(item.Key); if (route != null) { var siteobject = repo.Get(route.objectId); if (siteobject != null) { if (siteobject is ITextObject) { var text = siteobject as ITextObject; sb.Append(text.Body); sb.Append(spliter); } if (siteobject is ICoreObject) { var core = siteobject as ICoreObject; totalversion += core.Version; } } } } string result = sb.ToString(); if (context.RenderContext.WebSite != null && context.RenderContext.WebSite.EnableJsCssCompress) { if (!string.IsNullOrWhiteSpace(result)) { if (group.Type == ConstObjectType.Style) { result = CompressCache.Get(group.Id, totalversion, result, CompressType.css); } else if (group.Type == ConstObjectType.Script) { result = CompressCache.Get(group.Id, totalversion, result, CompressType.js); } } } TextBodyRender.SetBody(context, result); var version = context.RenderContext.Request.GetValue("version"); if (!string.IsNullOrWhiteSpace(version)) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r"); } }
public Image GetImage(int id) { return(imageRepository.Get(id)); }
public Order GetOrderById(int orderId) { return(_orderRepository.Get(orderId)); }
public List <string> Get() { return(Repo.Get()); }
public async Task <WS_Vare> GetVare(int id) { return(await _repository.Get(id)); }
public static bool TryGetById <T>(this IRepository <T> repo, string id, out T r) where T : class, Model.IEntity { r = repo.Get().FirstOrDefault(x => x.Id == id); return(r != null); }
public UpdateModel <MenuModel> Update(UpdateModel <MenuModel> updateModel) { IValidator validator = new FluentValidator <MenuModel, MenuValidationRules>(updateModel.Item); var validationResults = validator.Validate(); if (!validator.IsValid) { throw new ValidationException(Messages.DangerInvalidEntitiy) { ValidationResult = validationResults }; } var parent = _repositoryMenu.Get(x => x.Id == updateModel.Item.ParentMenu.Id && x.IsApproved); if (parent == null) { throw new NotFoundException(Messages.DangerParentNotFound); } var item = _repositoryMenu.Join(x => x.Creator.Person) .Join(x => x.LastModifier.Person) .Join(x => x.ParentMenu).FirstOrDefault(e => e.Id == updateModel.Item.Id); if (item == null) { throw new NotFoundException(Messages.DangerRecordNotFound); } if (updateModel.Item.Code != item.Code) { if (_repositoryMenu.Get().Any(p => p.Code == updateModel.Item.Code)) { throw new DuplicateException(string.Format(Messages.DangerFieldDuplicated, Dictionary.Code)); } } var versionHistoryMenu = _repositoryMenuHistory.Get().Where(e => e.ReferenceId == item.Id).Max(t => t.Version); var itemHistory = item.CreateMapped <Menu, MenuHistory>(); itemHistory.Id = GuidHelper.NewGuid(); itemHistory.ReferenceId = item.Id; itemHistory.CreatorId = IdentityUser.Id; itemHistory.IsDeleted = false; itemHistory.ParentMenuId = item.ParentMenu.Id; itemHistory.Version = versionHistoryMenu + 1; itemHistory.RestoreVersion = 0; _repositoryMenuHistory.Add(itemHistory, true); item.ParentMenu = parent; item.Code = updateModel.Item.Code; item.Name = updateModel.Item.Name; item.Description = updateModel.Item.Description; item.Address = updateModel.Item.Address; item.Icon = updateModel.Item.Icon; item.IsApproved = updateModel.Item.IsApproved; item.LastModificationTime = DateTime.Now; item.LastModifier = IdentityUser; item.LastModificationTime = DateTime.Now; item.LastModifier = IdentityUser; var version = item.Version; item.Version = version + 1; var affectedItem = _repositoryMenu.Update(item, true); updateModel.Item = affectedItem.CreateMapped <Menu, MenuModel>(); updateModel.Item.Creator = new IdCodeName(item.Creator.Id, item.Creator.Username, item.Creator.Person.DisplayName); updateModel.Item.LastModifier = new IdCodeName(IdentityUser.Id, IdentityUser.Username, IdentityUser.Person.DisplayName); return(updateModel); }
public void DeleteTransaction(int id) { Transaction Transaction = TransactionRepository.Get(id); TransactionRepository.Remove(Transaction); }
public Pet GetById(int id) { return(_petRepository.Get(id)); }
public IEnumerable <Question> Get() { return(_questionRepository.Get()); }
public async Task <Player> Get(Guid id) { return(await _repository.Get(id)); }
public Apartment Get(int id) { return(repository.Get(id)); }
public Customer Get(string id) { return(_Repository.Get(id)); }
public Proizvodjac Get(int id) { return(proizvodjacRepository.Get(id)); }