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)); }
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)); }
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)); }
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)); }