Beispiel #1
0
        private async Task Setup()
        {
            listNews      = new List <News>(NewsMock.listNews.Select(x => (News)x.Clone()));
            user1         = (User)UserMock.listUsers[0].Clone();
            user2         = (User)UserMock.listUsers[1].Clone();
            group         = (Group)GroupMock.groupMocks[0].Clone();
            course        = (Course)CourseMock.listCourse[0].Clone();
            courseProgram = (CourseProgram)CourseProgramMock.listCourseProgram[0].Clone();
            city          = (City)DictionaryMocks.cityMock[0].Clone();

            var createdCityId = await dictionaryStorage.CityAddOrUpdate(city);

            user1.CityId = (int)createdCityId;
            user2.CityId = (int)createdCityId;

            listNews[0].AuthorId = await userStorage.UserAddOrUpdate(user1);

            listNews[0].RecipientID = await userStorage.UserAddOrUpdate(user2);

            listNews[1].AuthorId = await userStorage.UserAddOrUpdate(user2);

            courseProgram.CourseId = await courseStorage.CourseAddOrUpdate(course);

            group.CourseProgramId = await courseStorage.CourseProgramAddOrUpdate(courseProgram);

            listNews[1].GroupID = await groupStorage.GroupAddOrUpdate(group);

            for (int i = 0; i < listNews.Count; i++)
            {
                News inputmodel = new News()
                {
                    AuthorId        = listNews[i].AuthorId,
                    Content         = listNews[i].Content,
                    GroupID         = listNews[i].GroupID,
                    Id              = listNews[i].Id,
                    PublicationDate = listNews[i].PublicationDate,
                    RecipientID     = listNews[i].RecipientID,
                    Title           = listNews[i].Title
                };
                int id = await newsStorage.NewsAddOrUpdate(inputmodel);

                listNews[i].Id = id;
                listNews[i].PublicationDate = (await newsStorage.NewsGetById(id)).PublicationDate;
            }
        }
Beispiel #2
0
        public async Task <ActionResult <NewsOutputModel> > GetNewsById(int id)
        {
            if (id.Equals(null))
            {
                return(BadRequest("Id is empty"));
            }

            var news = NewsMapper.ToOutputModel(await newsStorage.NewsGetById(id));

            if (news == null)
            {
                return(NotFound("Object not found"));
            }
            return(Ok(news));
        }