Exemplo n.º 1
0
        private async Task AddArticlesAndSourcesToDb(RootNewsServiceModel root)
        {
            if (root != null)
            {
                foreach (var article in root.Articles)
                {
                    if (!this.db.Sources.Any(x => x.Id == article.Source.Id))
                    {
                        db.Sources.Add(new Source
                        {
                            Id   = article.Source.Id,
                            Name = article.Source.Name,
                        });
                        await db.SaveChangesAsync();
                    }

                    db.Articles.Add(new Article
                    {
                        Author      = article.Author,
                        Title       = article.Title,
                        Description = article.Description,
                        Url         = article.Url,
                        UrlToImage  = article.UrlToImage,
                        PublishedAt = article.PublishedAt,
                        Content     = article.Content,
                        SourceId    = article.Source.Id,
                    });
                    await db.SaveChangesAsync();
                }
            }
        }
Exemplo n.º 2
0
        public async Task <bool> DeleteStudentByIdAsync(Guid id)
        {
            ValidateStudentId(id);
            ValidateIfStudentIsDeleted(id);

            var studentToDelete = await this.db.Students.FindAsync(id);

            studentToDelete.IsDeleted = true;
            await db.SaveChangesAsync();

            return(true);
        }
Exemplo n.º 3
0
        public async Task <bool> DeleteClassByIdAsync(Guid id)
        {
            ValidateClassId(id);
            ValidateIfClassIsDeleted(id);

            var classToDelete = await this.db.Classes.FindAsync(id);

            classToDelete.IsDeleted = true;
            await db.SaveChangesAsync();

            return(true);
        }
Exemplo n.º 4
0
        public async Task <bool> DeleteTeacherByIdAsync(Guid id)
        {
            ValidateTeacherId(id);
            ValidateIfTeacherIsDeleted(id);

            var teacherToDelete = await this.db.Teachers.FindAsync(id);

            teacherToDelete.IsDeleted = true;
            await db.SaveChangesAsync();

            return(true);
        }
        public async Task ReturnCorrectCollectionClassesLightServiceModelsByPage_When_ClassesExistInDb()
        {
            // Arrange
            var options = Utils.GetOptions(nameof(ReturnCorrectCollectionClassesLightServiceModelsByPage_When_ClassesExistInDb));

            Teacher teacher1 = Utils.CreateMockTeacher();
            Class   class1   = Utils.CreateMockClass(teacher1.Id);

            using (var arrangeContext = new PTSchoolDbContext(options))
            {
                arrangeContext.Teachers.Add(teacher1);
                arrangeContext.Classes.Add(class1);
                await arrangeContext.SaveChangesAsync();
            }

            // Act
            using (var actContext = new PTSchoolDbContext(options))
            {
                ClassService sut    = new ClassService(actContext, Utils.Mapper);
                var          result = await sut.GetAllClassesLightByPageAsync();

                // Assert
                Assert.AreEqual(1, result.Count());
            }
        }