public IHttpActionResult CreateTag(CreateTagBindingModel model) { var userId = this.User.Identity.GetUserId(); if (userId == null) { return(this.Unauthorized()); } var tag = new Tag() { Name = model.Name }; return(this.Ok(tag)); }
public IHttpActionResult PutTag([FromUri] int id, [FromBody] CreateTagBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (model == null) { return(BadRequest()); } var dbTag = db.Tags.Find(id); if (dbTag == null) { return(NotFound()); } var userId = User.Identity.GetUserId(); ApplicationUser user = null; if (userId != null) { user = db.Users.Find(userId); } if (user == null && userId != null) { return(Unauthorized()); } dbTag.Name = model.Name; dbTag.IsAdultContent = model.IsAdultContent; db.SaveChanges(); return(this.Ok(new { id = dbTag.Id, name = dbTag.Name, isAdultContent = dbTag.IsAdultContent })); }
public IHttpActionResult PostTag([FromBody] CreateTagBindingModel model) { var userId = User.Identity.GetUserId(); if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (db.Tags.Any(t => t.Name == model.Name)) { return(BadRequest()); } var newTag = new Tag() { Name = model.Name, IsAdultContent = model.IsAdultContent, OwnerId = userId }; db.Tags.Add(newTag); db.SaveChanges(); return(this.Ok(new { id = newTag.Id, name = newTag.Name, isAdultContent = newTag.IsAdultContent })); }