public IHttpActionResult PutCategory(int id, Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != category.ID) { return(BadRequest()); } db.Entry(category).State = EntityState.Modified; try { category.User_ID = this.GetUser(db).ID; db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutUserInfo(int id, UserInfo userInfo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != userInfo.ID) { return(BadRequest()); } db.Entry(userInfo).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserInfoExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "ID,Title")] TestTable testTable) { if (ModelState.IsValid) { db.TestTables.Add(testTable); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(testTable)); }
public async Task <IHttpActionResult> Register(RegisterBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new ApplicationUser() { UserName = model.Email, Email = model.Email }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); if (!result.Succeeded) { return(GetErrorResult(result)); } using (budgetTrackerEntities db = new budgetTrackerEntities()) { db.UserInfoes.Add(new UserInfo() { Name = user.UserName, Balance = 0, User_Id = user.Id }); try { db.SaveChanges(); return(Ok()); } catch (Exception e) { UserManager.Delete(user); return(BadRequest(e.Message)); } } }