Пример #1
0
        public async Task <ActionResult <List <int> > > AddNewsForTeachers([FromBody] NewsInputModel model)
        {
            List <int> newsIds = new List <int>();

            if (model == null)
            {
                return(BadRequest("Model is empty"));
            }
            if (model.GroupID != null)
            {
                model.GroupID = null;
            }

            List <User> teachers = await userStorage.GetUserByRoleId(teacherRoleId);

            foreach (var user in teachers)
            {
                model.RecipientID = user.Id;
                newsIds.Add(await newsStorage.NewsAddOrUpdate(NewsMapper.ToDataModel(model)));
            }
            if (newsIds.Equals(null))
            {
                return(BadRequest("Failed to add object"));
            }
            return(Ok(newsIds));
        }
Пример #2
0
        public async Task <ActionResult <int> > AddNewsForAll([FromBody] NewsInputModel model)
        {
            var newsId = 0;

            if (model == null)
            {
                return(BadRequest("Model is empty"));
            }
            if (model.RecipientID != null)
            {
                model.RecipientID = null;
            }
            if (model.GroupID != null)
            {
                model.GroupID = null;
            }

            newsId = await newsStorage.NewsAddOrUpdate(NewsMapper.ToDataModel(model));

            if (newsId.Equals(null))
            {
                return(BadRequest("Failed to add object"));
            }
            return(Ok(newsId));
        }
Пример #3
0
        public async Task <ActionResult <int> > AddNewsForGpoup([FromBody] NewsInputModel model)
        {
            if (model == null)
            {
                return(BadRequest("Model is empty"));
            }
            if (model.RecipientID != null)
            {
                model.RecipientID = null;
            }
            if (model.GroupID == null)
            {
                return(BadRequest("The inputModel doesn't contain GroupID"));
            }

            var  newsId = 0;
            bool isCreationAllowed;

            isCreationAllowed = await groupStorage.GetBelongnessOfGroupToTheTeacher((int)model.GroupID,
                                                                                    model.AuthorId);

            if (isCreationAllowed && await CanUserPost(model.AuthorId))
            {
                newsId = await newsStorage.NewsAddOrUpdate(NewsMapper.ToDataModel(model));
            }
            if (newsId.Equals(null))
            {
                return(BadRequest("Failed to add object"));
            }
            return(Ok(newsId));
        }
Пример #4
0
        public async Task <ActionResult <int> > AddOrUpdateNews([FromBody] NewsInputModel model)
        {
            if (model == null)
            {
                return(BadRequest("Model is empty"));
            }
            var newsId = await newsStorage.NewsAddOrUpdate(NewsMapper.ToDataModel(model));

            if (newsId.Equals(null))
            {
                return(BadRequest("Failed to add object"));
            }

            return(Ok(newsId));
        }