Пример #1
0
        public IActionResult getPostGroupItem(int id)
        {
            PostGroupItem item = postGroupDB.getPostGroupItem(id);

            if (item == null)
            {
                return(NotFound($"No PostGroupItem found for ID {id}"));
            }
            return(Ok(item));
        }
Пример #2
0
        /// <summary>
        /// Saves new item and assing new id, return the new item
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public NewsItem saveNewPost(NewsItem item)
        {
            if (File.Exists(filename))
            {
                //Need new id
                item.ID        = getMaxUsedNewsID() + 1;
                item.PostGroup = postGroupDatabase.getPostGroupItem(item.PostGroup.PostGroupID);

                File.AppendAllLines(filename, new String[] { ConvertFromNewsItemToString(item) });
                return(item);
            }
            throw new FileNotFoundException("File " + filename + " not found");
        }