public long CreateUserCameraSite(NewUserSiteModel model) { User user = UserRepository.First(u => u.ProviderID == this.User.Identity.Name); string guid = Guid.NewGuid().ToString(); CameraSite newCameraSite = new CameraSite() { Name = model.SiteName, Latitude = model.Latitude, Longitude = model.Longitude, CountyFips = DroughtMonitorRepository.GetFipsForCountyAndState(model.County, model.State), ContainerID = guid, DirectoryName = guid }; Collection newCollection = new Collection() { Name = model.SiteName, Site = newCameraSite, Owner = user, ContainerID = guid, Type = CollectionType.USER }; CollectionRepository.Insert(newCollection); Unit.Commit(); return(newCollection.ID); }
public MKCalendarPosCondition(IFileSystemManagement fs, IRepository <CalendarCollection, string> collectionRepository) { _collectionRepository = collectionRepository as CollectionRepository; Fs = fs; }
public void User_Can_Get_A_Single_Collection_By_Id() { // Set an expected collection to get that's in the db var expectedCollection = new Collection() { UserId = 1, CategorizationId = 1, Categorization = new Categorization() { Id = 1, Type = "Part of Speech" }, Name = "Monsters", Description = "Monsters and related words It becomes.", Pinned = false }; // Get a Collection Id that is in the Db int collectionId = 3; // Instantiate CollectionRepo var repo = new CollectionRepository(_context); // Get Collection by its Id var actualCollection = repo.GetByCollectionId(collectionId); // Two objects should have the same name. Was unable to test if Assert.Equal because Repo returns all the Objects from the FKs Assert.True(expectedCollection.Name == actualCollection.Collection.Name); }
public void User_Can_Add_Collection() { // Get a userId int userId = 1; // Create a new collection Collection collection = new Collection() { UserId = 1, CategorizationId = 1, Name = "New stuff", Description = "New lame description.", Pinned = false, CreationDate = DateTime.Now - TimeSpan.FromDays(10) }; // Instantiate CollectionRepo var repo = new CollectionRepository(_context); // Add collection repo.Add(collection); // Get new count of all collections var count = repo.Get(userId).Count; // User with Id 1 should have 3 Assert.True(count == 3); }
private List <ThumbnailModel> GetSiteYearSummary(long siteID) { List <ThumbnailModel> Years = new List <ThumbnailModel>(); string siteName = CollectionRepository.Find(c => c.Site.ID == siteID).FirstOrDefault().Site.Name; List <int> yearStrings = PhotoRepository.Find(p => p.Site.ID == siteID).Select(p => p.Captured.Year).Distinct().ToList <int>(); foreach (int y in yearStrings) { ThumbnailModel model = new ThumbnailModel(); model.Name = Convert.ToString(y); Photo[] photos = PhotoRepository.Find(p => p.Site.ID == siteID && p.Captured.Year == y) .ToArray(); model.PhotoCount = photos.Count(); model.First = photos[0].Captured; model.Last = photos[photos.Count() - 1].Captured; photos = photos.Where(p => p.Captured.Hour > 12 && p.Captured.Hour < 16).ToArray(); Random rand = new Random(); model.CoverPhotoID = photos[rand.Next(photos.Length)].ID; model.Link = "/Search/Index?site=" + siteName + "&year=" + model.Name; Years.Add(model); } return(Years); }
/// <summary> /// The actual Work to be done. /// </summary> protected override void Execute() { List <CollectionModel> newlist = new List <CollectionModel>(); CollectionModel collectionModel = new CollectionModel(); List <repository> repositories = RepositoryRepository.GetRepositoriess(); if (this.Request.CollectionId > 0) { collection collection = CollectionRepository.FirstOrDefault(c => c.Id == this.Request.CollectionId); collectionModel = Util.ConvertToCollectionModel( collection, repositories.First(c => c.Id == collection.RepositoryId).RepositoryName); } else { foreach (collection item in CollectionRepository.GetCollections().OrderBy(c => c.CollectionName)) { newlist.Add(Util.ConvertToCollectionModel(item, repositories.First(c => c.Id == item.RepositoryId).RepositoryName)); } } Response = new ResponseModel() { Collection = collectionModel, Collections = newlist, IsOperationSuccess = true }; }
public ActionResult AddEditCollection(int CollectionId) { var UserId = Session["AdminId"]; if (UserId != null) { collectionRepository = new CollectionRepository(); categoryRepository = new CategoryRepository(); bannersRepository = new BannersRepository(); List <Side> SideList = new List <Side>(); Side side = new Side(); side.sId = 1; side.sName = "Right"; SideList.Add(side); side = new Side(); side.sId = 2; side.sName = "Left"; SideList.Add(side); ViewBag.SideList = new SelectList(SideList, "sId", "sName"); ViewBag.Banners = new SelectList(bannersRepository.GetBanners(), "Id", "BannerKeyName"); ViewBag.Categories = new SelectList(categoryRepository.getAllCategory(), "Id", "CategoryName"); ViewBag.CollectionsList = new SelectList(collectionRepository.GetAllCollections(), "CollectionId", "CollectionName"); ViewBag.SubCategories = new SelectList(_DBContext.SubCategories.ToList(), "Id", "SubCategoryName"); if (CollectionId > 0) { var collection = collectionRepository.GetCollectionsById(CollectionId); return(View(collection)); } return(View()); } return(RedirectToAction("Index", "Admin")); }
public ActionResult SiteDashboard(long siteID) { // Make sure the siteID belongs to a CameraSite if (CollectionRepository.Find(c => c.Site.ID == siteID && c.Type == CollectionType.SITE).FirstOrDefault() == null) { return(RedirectToAction("SiteList", "Home", null)); } else { SiteDashboardViewModel model = new SiteDashboardViewModel(); model.CollectionViewModel = GetCollectionViewModel(siteID, -1); model.Years = GetSiteYearSummary(siteID); model.Tags = PhotoService.GetPopularTagsForSite(siteID); //Photo Frequency model.PhotoFrequency = GetPhotoFrequencyData(siteID); model.PhotoFrequency.SiteName = model.CollectionViewModel.Collection.Site.Name; model.PhotoFrequency.StartDate = model.CollectionViewModel.SiteDetails.First; Photo lastPhoto = PhotoRepository.Find(p => p.Site.ID == siteID).OrderBy(p => p.Captured).Last(); DateTime lastPhotoDate = lastPhoto.Captured; model.DroughtMonitorData = LoadDMData(DMDataType.COUNTY, lastPhotoDate, model.CollectionViewModel.Collection.Site.CountyFips); model.DroughtMonitorData.PhotoID = lastPhoto.ID; model.WaterData = LoadWaterData(model.CollectionViewModel.Collection.Site.Latitude, model.CollectionViewModel.Collection.Site.Longitude, lastPhotoDate); model.WaterData.PhotoID = lastPhoto.ID; return(View(model)); } }
public async Task Found_Collection_Should_Not_Be_Tracked() { //Given const string realName = "A Collection"; var collectionId = await Database.OnceAsync(async db => { var repo = new CollectionRepository(db); var collection = new Collection { Name = realName }; await repo.AddAsync(collection); return(collection.Id); }); //When await Database.OnceAsync(async db => { var repo = new CollectionRepository(db); var collection = await repo.FindAsync(collectionId); collection.Name = "Manipulated Name"; await db.SaveChangesAsync(); }); //Then var result = await Database.OnceAsync(async db => await db.Collections.FindAsync(collectionId)); Assert.Equal(realName, result.Name); }
// // GET: /Home/ public ActionResult Index(int e = 0) { HomeViewModel model = new HomeViewModel(); ICollection <Collection> collections = CollectionRepository.Find(c => c.Status == CollectionStatus.COMPLETE && c.Type == CollectionType.SITE, c => c.CoverPhoto, c => c.Site).ToList <Collection>(); model.Sites = collections.Select(c => GetDetailsForCollection(c)).ToArray(); model.SiteThumbnails = new List <ThumbnailModel>(); foreach (var s in model.Sites) { model.SiteThumbnails.Add(new ThumbnailModel() { ID = s.SiteID, Name = s.SiteName, First = s.First, Last = s.Last, PhotoCount = s.PhotoCount, CoverPhotoID = s.CoverPhotoID, Link = "/photo/sitedashboard?siteId=" + s.SiteID.ToString() }); } model.Tags = PhotoService.GetTagNames(); model.SiteIndex = new Random().Next(model.Sites.Count()); if (e == 2) { ViewBag.Message = "Please enter at lease one search parameter."; } return(View(model)); }
public async Task Can_Find_A_Collection_By_id() { //Given var toBeFound = await Database.OnceAndSaveAsync(async db => { var collections = new[] { new Collection { Name = "Collection1" }, new Collection { Name = "Collection2" }, }; await db.Collections.AddRangeAsync(collections); return(collections.First()); }); //When var found = await Database.OnceAsync(async db => { var repository = new CollectionRepository(db); return(await repository.FindAsync(toBeFound.Id)); }); //Then Assert.Equal(toBeFound.Name, found.Name); }
public async Task Updated_Collection_Should_Not_Be_Tracked() { //Given const string newName = "New Collection Name"; var collection = new Collection { Name = "A Collection" }; await Database.OnceAndSaveAsync(async db => await db.Collections.AddAsync(collection)); //When await Database.OnceAsync(async db => { var repository = new CollectionRepository(db); collection.Name = newName; await repository.UpdateAsync(collection); collection.Name = "Manipulated Name"; await db.SaveChangesAsync(); }); //Then var updated = await Database.OnceAsync(async db => await db.Collections.FindAsync(collection.Id)); Assert.Equal(newName, updated.Name); }
public async Task Can_Update_A_Collection() { //Given const string newName = "New Collection Name"; var collection = new Collection { Name = "A Collection" }; await Database.OnceAndSaveAsync(async db => await db.Collections.AddAsync(collection)); //When var isSucceed = await Database.OnceAsync(async db => { var repository = new CollectionRepository(db); collection.Name = newName; return(await repository.UpdateAsync(collection)); }); //Then Assert.True(isSucceed); var updated = await Database.OnceAsync(async db => await db.Collections.FindAsync(collection.Id)); Assert.Equal(newName, updated.Name); }
public async Task Listed_Collections_Should_Not_Be_Tracked() { // Given var collectionsNames = new[] { "Collection1", "Collection2", "Collection3" }; await Database.OnceAndSaveAsync(async db => { var collections = collectionsNames.Select(name => new Collection { Name = name }); await db.AddRangeAsync(collections); }); // When await Database.OnceAsync(async db => { var repository = new CollectionRepository(db); var collections = await repository.ListAsync(); foreach (var collection in collections) { collection.Name = $"Manipulated {collection.Name}"; } await db.SaveChangesAsync(); }); // Then var collections = await Database.OnceAsync(async db => await db.Collections.ToArrayAsync()); Assert.True(collections.All(collection => collectionsNames.Contains(collection.Name))); }
public void OnGet() { CollectionRepository collectionRepository = new CollectionRepository(); collectionRepository.Initialize(); Collections = collectionRepository.Items.OrderBy(i => i.ID).ToList(); }
// Anropen mot Ratings och Users kan bli tunga med flera tusen // ratings och användare, därför har jag valt att jobba asynkront. // Databasen är till för att användas med ett ASP.NET MVC projekt och // EF Core är inte threadsafe ännu vilket var till fördel // för asynkront. public void GetBookInfoRatingAndUsersAsync(Book inputBook) { BookRepository bookRepo = new BookRepository(); AuthorRepository authorRepo = new AuthorRepository(); GenreRepository genreRepository = new GenreRepository(); CollectionRepository collectionRepo = new CollectionRepository(); var book = bookRepo.GetById(1); var bookRatingsAsync = bookRepo.GetAllUserRatingsByBookAsync(book); var usersAsync = bookRepo.GetAllBookOwnersAsync(book); var genreAsync = bookRepo.GetBookGenresAsync(book); var authorAsync = authorRepo.GetByIdAsync(book.Id); var author = authorAsync.Result; var genres = genreAsync.Result; var users = usersAsync.Result; var bookRatings = bookRatingsAsync.Result; Console.WriteLine("Title: " + book.Title + "\nAuthor: " + author.FirstName + " " + author.LastName); Console.Write("Genres: "); foreach (var genre in genres) { Console.Write(" / " + genre.Category); } Console.WriteLine("\nAverage Score: " + bookRatings.Values.Average() + " / 10"); Console.WriteLine("In users collection: "); foreach (var user in users) { Console.WriteLine("- " + user.Username); } }
public void NewUserCollection(User user, string collectionName, string photoIds) { List <Photo> photos; long[] ids; if (!String.IsNullOrWhiteSpace(photoIds)) { ids = photoIds.Split(',').Select(i => Convert.ToInt64(i)).ToArray(); photos = PhotoRepository.Find(p => ids.Contains(p.ID), p => p.Site).ToList(); } else { ids = new long[0]; photos = new List <Photo>(); } Guid containerID = Guid.NewGuid(); //save the collection Collection c = new Collection() { Name = collectionName, ContainerID = containerID.ToString(), Owner = user, Type = CollectionType.USER, Status = CollectionStatus.COMPLETE, Photos = photos }; CollectionRepository.Insert(c); Unit.Commit(); }
private CollectionViewModel GetCollectionViewModel(long siteID, long year) { CollectionViewModel model = new CollectionViewModel(); model.Collection = CollectionRepository.First(c => c.Site.ID == siteID); model.SiteCoords = string.Format("{0}, {1}", model.Collection.Site.Latitude, model.Collection.Site.Longitude); List <Photo> photos = PhotoRepository.Find(p => p.Site.ID == model.Collection.Site.ID).OrderBy(p => p.Captured).ToList <Photo>(); if (year != -1) { photos = photos.Where(p => p.Captured.Year == year).ToList <Photo>(); } model.SiteDetails = new SiteDetails() { PhotoCount = photos.Count(), First = photos.Select(p => p.Captured).First(), Last = photos.Select(p => p.Captured).Last() }; Phocalstream_Shared.Data.Model.Photo.User User = UserRepository.First(u => u.ProviderID == this.User.Identity.Name); if (User != null) { UserCollectionList userCollectionModel = new UserCollectionList(); userCollectionModel.User = User; userCollectionModel.Collections = CollectionRepository.Find(c => c.Owner.ID == User.ID && c.Type == CollectionType.USER, c => c.Photos).ToList(); model.UserCollections = userCollectionModel; } return(model); }
public void SetUserCollectionPublic(User user, long collectionID, bool publish) { Collection collection = CollectionRepository.First(c => c.ID == collectionID && c.Owner.ID == user.ID); collection.Public = publish; Unit.Commit(); }
} //End LoadDMDataValues private UserCollectionData LoadUserCollections(long photoID) { Phocalstream_Shared.Data.Model.Photo.User User = UserRepository.First(u => u.ProviderID == this.User.Identity.Name); if (User != null) { UserCollectionData model = new UserCollectionData(); model.PhotoID = photoID; List <UserCollection> userCollections = new List <UserCollection>(); IEnumerable <Collection> collections = CollectionRepository.Find(c => c.Owner.ID == User.ID && c.Site == null && c.Type != CollectionType.TIMELAPSE, c => c.Photos); foreach (var col in collections) { UserCollection userCollection = new UserCollection(); userCollection.CollectionID = col.ID; userCollection.CollectionName = col.Name; userCollection.Added = col.Photos.Select(p => p.ID).Contains(photoID); userCollections.Add(userCollection); } model.Collections = userCollections; return(model); } else { return(null); } }
public void Setup() { _keys = GetKeys(); var client = new LexalyticsRepositoryClient(_keys); _sut = new CollectionRepository(_keys, client); }
public ActionResult CreateUserSite(AddUserCameraSite site) { User user = UserRepository.First(u => u.ProviderID == this.User.Identity.Name); string guid = Guid.NewGuid().ToString(); CameraSite newCameraSite = new CameraSite() { Name = site.CameraSiteName, Latitude = site.Latitude, Longitude = site.Longitude, CountyFips = DroughtMonitorRepository.GetFipsForCountyAndState(site.County, site.State), ContainerID = guid, DirectoryName = guid }; Collection newCollection = new Collection() { Name = site.CameraSiteName, Site = newCameraSite, Owner = user, ContainerID = guid, Type = CollectionType.USER }; CollectionRepository.Insert(newCollection); Unit.Commit(); return(RedirectToAction("UploadPhotos", new { @collectionID = newCollection.ID })); }
public async Task Can_Find_And_Map_Result() { //Given const int itemsCount = 3; var collection = await Database.OnceAndSaveAsync(async db => { var collection = new Collection { Name = "A Collection" }; for (var i = 0; i < itemsCount; i++) { collection.TodoItems.Add(new TodoItem { Name = $"Item{i}" }); } await db.Collections.AddAsync(collection); return(collection); }); //When var result = await Database.OnceAsync(async db => { var repository = new CollectionRepository(db); return(await repository.FindAndMapAsync(collection.Id, c => new { Collection = c, TodoItemsCount = c.TodoItems.Count, })); }); //Then Assert.Equal(collection.Id, result.Collection.Id); Assert.Equal(itemsCount, result.TodoItemsCount); }
private CollectionsControl() { InitializeComponent(); collectionRepository = new CollectionRepository(); refresh(); }
public static IHost BuildHost(string[] args, CollectionRepository <Book> repo, Dispatcher dispatcher, int port = 15000) { return(CreateHostBuilder(args, repo, dispatcher, port).Build()); }
public void OnGet(string vendor) { furnitureRepository = new FurnitureRepository(QueryMode.ByVendorCode, vendor); furnitureRepository.Initialize(); Furniture = furnitureRepository.Items.FirstOrDefault(); // Furniture.CategoryID = Furniture.Category.ID; Furniture.ManufacturerID = Furniture.Manufacturer.ID; Furniture.CollectionID = Furniture.Collection.ID; // CollectionRepository = new CollectionRepository(); CollectionRepository.Initialize(); // ManufacturerRepository = new ManufacturerRepository(); ManufacturerRepository.Initialize(); // CategoryRepository = new CategoryRepository(); CategoryRepository.Initialize(); // ColorRepository = new ColorRepository(); ColorRepository.Initialize(); // MaterialRepository = new MaterialRepository(); MaterialRepository.Initialize(); }
private void initializeCollectionsDropdown() { var items = new CollectionRepository().query().forUser(Auth.getUser()).get(); if (items.Count < 1) { throw new ValidationException("You cannot create files without existing collection."); } foreach (var i in items) { collectionsDropdown.AddItem(i.Name); } var index = -1; if (!item.isNull()) { index = items.FindIndex(i => i.Name == (item.Collection?.Name ?? "")); } else if (item.isNull() && items.Count > 0) { index = 0; } collectionsDropdown.selectedIndex = index; }
public void GetDeleteDrugFromConsultation(string id) { bool collected = true; using (var consrepo = new ConsultationRepository()) { CollectionRepository collrepo = new CollectionRepository(); var consultdrug = consrepo.GetById(id); //consrepo.Delete(consultdrug); consultdrug.collected = collected; consrepo.Update(consultdrug); //da.CollectionDrugs.Remove(consultdrug); //da.SaveChanges(); } //ConsultationDrugView cdv=new ConsultationDrugView(); //using (var consultrepo = new ConsultationDrugsRepository()) //{ // if (id != 0) // { // ConsultationDrug consult = consultrepo.FindbyId(id); // cdv.DrugId = consult.DrugId; // cdv.PrescriptionId = consult.PrescriptionId; // cdv.DrugName = consult.DrugName; // cdv.Price = consult.Price; // cdv.DrugToConsultId = consult.DrugToConsultId; // cdv.Quantity = consult.Quantity; // } // return cdv; //} }
public ACLReport(IRepository <Principal, string> prinRepository, IRepository <CalendarCollection, string> colRepository, IRepository <CalendarResource, string> resRepository) { _principalRepository = prinRepository as PrincipalRepository; _collectionRepository = _collectionRepository; _resourceRepository = resRepository as ResourceRespository; }
public override File addIncludes(File model) { collectionRepository = new CollectionRepository(); model.Collection = collectionRepository.query().where ("id", "=", model.CollectionID).first(false); return(model); }