Esempio n. 1
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));
        }
Esempio n. 2
0
        public async Task <ActionResult> FillWhoWereAbsent(JournalInputModel inputModel)
        {
            if (inputModel == null)
            {
                return(BadRequest("Model is empty"));
            }
            List <Journal> journals = JournalMapper.ToModel(inputModel);
            bool           belong   = await groupStorage.GetBelongnessOfGroupToTheTeacher(inputModel.GroupId, inputModel.TeacherId);

            if (belong)
            {
                lessonStorage.FillWhoWhereAbsent(journals); return(Ok());
            }
            else
            {
                return(BadRequest(("Failed to fill")));
            }
        }