public void AddTags(List <string> tagsDb, string id) { foreach (string s in tagsDb) { var meh = tags.Find(searchTag => searchTag.tagName.ToLower() == s.ToLower()).FirstOrDefault(); switch (meh) { case null: TagDb newDb = new TagDb(); newDb.tagName = s; newDb.idList.Add(id); tags.InsertOne(newDb); break; default: if (meh.idList.Contains(id)) { break; } else { meh.idList.Add(id); tags.ReplaceOne(tag => tag.id == meh.id, meh); } break; } } }
/// <summary> /// Create a new tag in repository. /// </summary> /// <param name="tag"></param> /// <returns></returns> public async Task <TagDb> AddAsync(TagDb tag) { _videoDbContext.Tags.Add(tag); await _videoDbContext.SaveChangesAsync().ConfigureAwait(false); return(await Task.FromResult(tag)); }
/// <summary> /// Update tag in repository. /// </summary> /// <param name="tag"></param> /// <returns></returns> public void Update(TagDb tag) { if (tag == null) { throw new ArgumentNullException("tag"); } _videoDbContext.Entry(tag).State = EntityState.Modified; _videoDbContext.SaveChanges(); }
/// <summary> /// Remove tag in repository. /// </summary> /// <param name="tag"></param> /// <returns></returns> public async Task RemoveAsync(TagDb tag) { if (tag == null) { throw new ArgumentNullException("user"); } _videoDbContext.Tags.Remove(tag); await _videoDbContext.SaveChangesAsync().ConfigureAwait(false); }
/// <summary> /// Update tag in repository. /// </summary> /// <param name="tag"></param> /// <returns></returns> public async Task <TagDb> UpdateAsync(TagDb tag) { if (tag == null) { throw new ArgumentNullException("tag"); } _videoDbContext.Entry(tag).State = EntityState.Modified; await _videoDbContext.SaveChangesAsync().ConfigureAwait(false); return(await Task.FromResult(tag)); }
private bool disposedValue = false; // 要检测冗余调用 protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { db.Dispose(); } db = null; disposedValue = true; } }
public List <string> GetNameTags(List <string> ids) { List <string> meh = new List <string>(); TagDb kek = new TagDb(); foreach (string s in ids) { kek = tags.Find(tag => tag.id == s).FirstOrDefault(); meh.Add(kek.tagName); } return(meh); }
private bool disposedValue = false; // 要检测冗余调用 protected virtual void Dispose(bool disposing) { if (!this.disposedValue) { if (disposing) { this.db.Dispose(); } this.db = null; this.disposedValue = true; } }
internal DataBase() { db = new TagDb(); }
/// <summary> /// Gets all courses by tag in repository. /// </summary> /// <param name="tag"></param> /// <returns></returns> public async Task <IEnumerable <CourseDb> > GetCoursesAsync(TagDb tag) { var courses = await _videoDbContext.Tags.Where(c => c.TagId == tag.TagId)?.SelectMany(c => c.Courses).ToListAsync(); return(courses.AsReadOnly());; }
/// <summary> /// Create a new tag in repository. /// </summary> /// <param name="tag"></param> /// <returns></returns> public void Add(TagDb tag) { _videoDbContext.Tags.Add(tag); _videoDbContext.SaveChanges(); }
/// <summary> /// Remove tag in repository. /// </summary> /// <param name="tag"></param> /// <returns></returns> public void Remove(TagDb tag) { _videoDbContext.Tags.Remove(tag); _videoDbContext.SaveChanges(); }
static Client() { TagDb.Migrate(); }
public TagBs() { db = new TagDb(); }
public void InitMock() { _tagDb = new TagDb() { TagId = "tag1", Content = "C#" }; _tagDbFirst = new List <TagDb>() { _tagDb, new TagDb() { TagId = "tag2", Content = "ASP" }, }; _tagDbSecond = new List <TagDb>() { new TagDb() { TagId = "tag3", Content = "Java" }, new TagDb() { TagId = "tag4", Content = "Javascript" }, }; _tagInfo = new TagInfo() { TagId = "tag1", Content = "C#" }; _tagInfoFirst = new List <TagInfo>() { _tagInfo, new TagInfo() { TagId = "tag2", Content = "ASP" }, }; _tagInfoSecond = new List <TagInfo>() { new TagInfo() { TagId = "tag3", Content = "Java" }, new TagInfo() { TagId = "tag4", Content = "Javascript" }, }; _coursesDb = new List <CourseDb>() { new CourseDb() { CourseId = "idCourse1", Name = "Course1", Price = 10, Date = DateTime.Now, Description = "Description1", Level = 1, Raiting = 5, RateCount = 3, Tags = _tagDbFirst }, new CourseDb() { CourseId = "idCourse2", Name = "Course2", Price = 20, Date = DateTime.Now, Description = "Description2", Level = 2, Raiting = 4, RateCount = 10, Tags = _tagDbSecond }, new CourseDb() { CourseId = "idCourse3", Name = "Course3", Price = 30, Date = DateTime.Now, Description = "Description3", Level = 2, Raiting = 3, RateCount = 15, Tags = _tagDbSecond }, new CourseDb() { CourseId = "idCourse4", Name = "Course4", Price = 40, Date = DateTime.Now, Description = "Description4", Level = 1, Raiting = 2, RateCount = 12, Tags = _tagDbFirst }, new CourseDb() { CourseId = "idCourse5", Name = "Course5", Price = 50, Date = DateTime.Now, Description = "Description5", Level = 2, Raiting = 3, RateCount = 24, Tags = _tagDbFirst }, }.AsQueryable(); _coursesInfo = new List <CourseInfo>() { new CourseInfo() { Name = "Course1", Price = 10, Description = "Description1", Duration = 15, Level = 1, Raiting = 5 }, new CourseInfo() { Name = "Course2", Price = 20, Description = "Description2", Duration = 25, Level = 2, Raiting = 4 }, new CourseInfo() { Name = "Course3", Price = 30, Description = "Description3", Duration = 35, Level = 2, Raiting = 3 }, new CourseInfo() { Name = "Course4", Price = 40, Description = "Description4", Duration = 45, Level = 1, Raiting = 2 }, new CourseInfo() { Name = "Course5", Price = 50, Description = "Description5", Duration = 55, Level = 2, Raiting = 3 } }.AsQueryable(); _oneCourseDb = new CourseDb() { CourseId = "idCourseFirst", Name = "CourseFirst", Price = 40, Date = DateTime.Now, Description = "DescriptionFirst", Level = 1, Raiting = 5 }; _oneCourseInfo = new CourseInfo() { Name = "CourseFirst", Price = 40, Description = "DescriptionFirst", Duration = 45, Level = 1, Raiting = 5 }; //_autorsDb = new List<AuthorDb>() { // new AuthorDb(){ AuthorId = "id1", Name = "name1", Lastname = "lastname1", Annotation = "Annotation1", Professions = "Professions1", AuthorCourses = _coursesDb}, // new AuthorDb(){ AuthorId = "id2", Name = "name2", Lastname = "lastname2", Annotation = "Annotation2", Professions = "Professions2" }, // new AuthorDb(){ AuthorId = "id3", Name = "name3", Lastname = "lastname3", Annotation = "Annotation3", Professions = "Professions3" } //}.AsQueryable(); //_oneAuthorDb = new AuthorDb() { AuthorId = "id4", Name = "name4", Lastname = "lastname4", Annotation = "Annotation4", Professions = "Professions4" }; //_authorsInfo = new List<AuthorInfo>() { // new AuthorInfo(){ Name = "name1", Lastname = "lastname1", Annotation = "Annotation1", Professions = "Professions1" }, // new AuthorInfo(){ Name = "name2", Lastname = "lastname2", Annotation = "Annotation2", Professions = "Professions2" }, // new AuthorInfo(){ Name = "name3", Lastname = "lastname3", Annotation = "Annotation3", Professions = "Professions3" } //}.AsQueryable(); //_oneAuthorInfo = new AuthorInfo() { Name = "name4", Lastname = "lastname4", Annotation = "Annotation4", Professions = "Professions4" }; _mockSet = new Mock <DbSet <CourseDb> >(); _mockSet.As <IQueryable <CourseDb> >().Setup(m => m.Expression).Returns(_coursesDb.Expression); _mockSet.As <IQueryable <CourseDb> >().Setup(m => m.ElementType).Returns(_coursesDb.ElementType); _mockSet.As <IQueryable <CourseDb> >().Setup(m => m.GetEnumerator()).Returns(_coursesDb.GetEnumerator()); _mockContext = new Mock <VideoDbContext>(); _mockMapper = new Mock <IMapper>(); }
protected override void Seed(BulbaCourses.Video.Data.DatabaseContext.VideoDbContext context) { // This method will be called after migrating to the latest version. #region Users var user1 = new UserDb() { UserId = Guid.NewGuid().ToString(), Login = "******", SubscriptionType = 1 }; var user2 = new UserDb() { UserId = Guid.NewGuid().ToString(), Login = "******", SubscriptionType = 1 }; context.Users.Add(user1); context.Users.Add(user2); #endregion #region Tags var tag1 = new TagDb() { TagId = Guid.NewGuid().ToString(), Content = "C#" }; List <TagDb> tagDbC = new List <TagDb>() { tag1 }; var tag2 = new TagDb() { TagId = Guid.NewGuid().ToString(), Content = "ASP.Net" }; List <TagDb> tagDbCSharp = new List <TagDb>() { tag1, tag2 }; var tag3 = new TagDb() { TagId = Guid.NewGuid().ToString(), Content = "Java" }; var tag4 = new TagDb() { TagId = Guid.NewGuid().ToString(), Content = "Automated" }; var tag5 = new TagDb() { TagId = Guid.NewGuid().ToString(), Content = "Testing" }; List <TagDb> tagDbJava = new List <TagDb>() { tag3, tag4, tag5 }; var tag6 = new TagDb() { TagId = Guid.NewGuid().ToString(), Content = "Network" }; var tag7 = new TagDb() { TagId = Guid.NewGuid().ToString(), Content = "DHCP" }; List <TagDb> tagDbNet = new List <TagDb>() { tag6, tag7 }; context.Tags.Add(tag1); context.Tags.Add(tag2); context.Tags.Add(tag3); context.Tags.Add(tag4); context.Tags.Add(tag5); context.Tags.Add(tag6); context.Tags.Add(tag7); #endregion #region Authors var author1 = new AuthorDb() { AuthorId = Guid.NewGuid().ToString(), Name = "Aleksandr", Lastname = "Shaduro", Annotation = "Experienced Instructor with a demonstrated history of working in the higher education industry. " + "Skilled in WEB Development, Agile Methodologies. Strong education professional graduated from Belarusian State University", Professions = "Chief Technical Officer at Artooba" }; var author2 = new AuthorDb() { AuthorId = Guid.NewGuid().ToString(), Name = "Aleksandr", Lastname = "Korablin", Annotation = "MCSD: MICROSOFT CERTIFIED SOLUTION DEVELOPER, ORACLE CERTIFIED ASSOCIATE, " + "JAVA SE 7 PROGRAMMER, WINDOWS AZURE DEVELOPER, MICROSOFT CERTIFIED TRAINER", Professions = "MICROSOFT CERTIFIED SOLUTION DEVELOPER" }; var author3 = new AuthorDb() { AuthorId = Guid.NewGuid().ToString(), Name = "Aleksandr", Lastname = "Borovoy", Annotation = "Local network, DHCP, DNS, NOD-32", Professions = "Local network" }; context.Authors.Add(author1); context.Authors.Add(author2); context.Authors.Add(author3); #endregion #region Courses var course1 = new CourseDb() { CourseId = Guid.NewGuid().ToString(), Name = "ASP by Shaduro", Author = author1, Level = 1, Raiting = 5, RateCount = 20, Description = ".NET is a developer platform made up of tools, programming languages, and libraries for building many different types of applications." + "ASP.NET extends the.NET developer platform with tools and libraries specifically for building web apps.", Date = DateTime.Now, Price = 850, Tags = tagDbCSharp }; var course2 = new CourseDb() { CourseId = Guid.NewGuid().ToString(), Name = "Programming in C#", Author = author1, Level = 1, Raiting = 4, RateCount = 12, Description = "C#(Sharp) is an object-oriented programming language developed by Microsoft.", Date = DateTime.Now, Price = 50, Tags = tagDbC }; var course3 = new CourseDb() { CourseId = Guid.NewGuid().ToString(), Name = "Java for Automated Testing", Author = author2, Level = 1, Raiting = 4, RateCount = 10, Description = "Test automation, a formalized testing process, can automate repetitive but necessary tasks that would be difficult to do manually.", Date = DateTime.Now, Price = 70, Tags = tagDbJava }; var course4 = new CourseDb() { CourseId = Guid.NewGuid().ToString(), Name = "Local Network", Author = author3, Level = 1, Raiting = 3, RateCount = 6, Description = "A local area network (LAN) is a computer network that interconnects computers within a limited area.", Date = DateTime.Now, Price = 10, Tags = tagDbNet }; context.Courses.Add(course1); context.Courses.Add(course2); context.Courses.Add(course3); context.Courses.Add(course4); #endregion #region Videos var video1 = new VideoMaterialDb() { VideoId = Guid.NewGuid().ToString(), Name = "validation", Url = @"D:\TestCourses\ASP by Shaduro\1_video_validation.mp4", Created = DateTime.Now, NumberOfViews = 1, Order = 1, CourseId = course1.CourseId }; var video2 = new VideoMaterialDb() { VideoId = Guid.NewGuid().ToString(), Name = "Refactiring & Security", Url = @"D:\TestCourses\ASP by Shaduro\2_video_refactiring_&_security.mp4", Created = DateTime.Now, NumberOfViews = 1, Order = 2, CourseId = course1.CourseId }; var video3 = new VideoMaterialDb() { VideoId = Guid.NewGuid().ToString(), Name = "Angular_Basic", Url = @"D:\TestCourses\ASP by Shaduro\3_video_angular_basic.mp4", Created = DateTime.Now, NumberOfViews = 1, Order = 3, CourseId = course1.CourseId }; var video4 = new VideoMaterialDb() { VideoId = Guid.NewGuid().ToString(), Name = "C# start part.1", Url = @"D:\TestCourses\Programming in C#\1_1_x264.mp4", Created = DateTime.Now, NumberOfViews = 1, Order = 1, CourseId = course2.CourseId }; var video5 = new VideoMaterialDb() { VideoId = Guid.NewGuid().ToString(), Name = "C# start part.1", Url = @"D:\TestCourses\Programming in C#\1_2_x264.mp4", Created = DateTime.Now, NumberOfViews = 1, Order = 2, CourseId = course2.CourseId }; var video6 = new VideoMaterialDb() { VideoId = Guid.NewGuid().ToString(), Name = "Java Fundamentals", Url = @"D:\TestCourses\Java for Automated Testing\01_Java Fundamentals.wmv", Created = DateTime.Now, NumberOfViews = 1, Order = 1, CourseId = course3.CourseId }; var video7 = new VideoMaterialDb() { VideoId = Guid.NewGuid().ToString(), Name = "Object Oriented Programming", Url = @"D:\TestCourses\Java for Automated Testing\02_Object Oriented Programming.wmv", Created = DateTime.Now, NumberOfViews = 1, Order = 2, CourseId = course3.CourseId }; var video8 = new VideoMaterialDb() { VideoId = Guid.NewGuid().ToString(), Name = "Numbers, strings, dates", Url = @"D:\TestCourses\Java for Automated Testing\03_Numbers, strings, dates.avi", Created = DateTime.Now, NumberOfViews = 1, Order = 3, CourseId = course3.CourseId }; var video9 = new VideoMaterialDb() { VideoId = Guid.NewGuid().ToString(), Name = "¬водный урок", Url = @"D:\TestCourses\Ћокальна¤ компьютерна¤ сеть\”рок 1 Ч ¬водный урок.avi", Created = DateTime.Now, NumberOfViews = 1, Order = 1, CourseId = course4.CourseId }; var video10 = new VideoMaterialDb() { VideoId = Guid.NewGuid().ToString(), Name = "«акрыта¤ серверна¤ стойка", Url = @"D:\TestCourses\Ћокальна¤ компьютерна¤ сеть\”рок 2 Ч ќбзор закрытой серверной стойки.avi", Created = DateTime.Now, NumberOfViews = 1, Order = 2, CourseId = course4.CourseId }; context.VideoMaterials.Add(video1); context.VideoMaterials.Add(video2); context.VideoMaterials.Add(video3); context.VideoMaterials.Add(video4); context.VideoMaterials.Add(video5); context.VideoMaterials.Add(video6); context.VideoMaterials.Add(video7); context.VideoMaterials.Add(video8); context.VideoMaterials.Add(video9); context.VideoMaterials.Add(video10); #endregion base.Seed(context); }