Beispiel #1
0
        public IHttpActionResult Update(int id, TagOutputData tag)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var exisitingTag = this.data.Tags.All().FirstOrDefault(u => u.Id == id);
            if (exisitingTag == null)
            {
                return BadRequest("Such tag does not exists!");
            }

            exisitingTag.Name = tag.Name ?? exisitingTag.Name;

            this.data.Tags.Update(exisitingTag);
            this.data.SaveChanges();

            return Ok();
        }
Beispiel #2
0
        public IHttpActionResult Create(int id, TagOutputData tag)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var exisitingPost = this.data.Posts.All().FirstOrDefault(u => u.Id == id);
            if (exisitingPost == null)
            {
                return BadRequest("Such post does not exists!");
            }

            var newTag = new Tag
            {
                Name = tag.Name,
            };

            exisitingPost.Tags.Add(newTag);
            this.data.SaveChanges();

            return Ok(newTag.Id);
        }