public IHttpActionResult ChangeManagerStatus() { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } AppUser changeUser = null; int id; var httpRequest = HttpContext.Current.Request; try { id = JsonConvert.DeserializeObject <Int32>(httpRequest.Form[0]); changeUser = db.AppUsers.Find(id); changeUser.CanCreateService = (changeUser.CanCreateService == true) ? false : true; } catch (JsonSerializationException) { return(BadRequest(ModelState)); } try { db.Entry(changeUser).State = EntityState.Modified; db.SaveChanges(); } catch (DbEntityValidationException) { return(BadRequest(ModelState)); } catch (DbUpdateException) { return(BadRequest(ModelState)); } return(Ok("Success")); }
public IHttpActionResult AddComment() { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Comment comment = new Comment(); var httpRequest = HttpContext.Current.Request; try { comment = JsonConvert.DeserializeObject <Comment>(httpRequest.Form[0]); } catch (JsonSerializationException) { return(BadRequest(ModelState)); } Drive drive = db.Drives.Where(d => d.Id == comment.DriveId) .FirstOrDefault(); drive.CommentId = comment.Id; db.Comments.Add(comment); try { db.Entry(drive).State = EntityState.Modified; db.SaveChanges(); } catch (DbEntityValidationException) { return(BadRequest(ModelState)); } catch (DbUpdateException) { return(BadRequest(ModelState)); } return(Ok("Success")); }