public HttpResponseMessage PostUsersTab(UsersTab usersTab) { var usersList = GetUsersTabs(); if (usersList != null && usersList.Count() > 0) { usersTab.User_ID = usersList.Max(x => x.User_ID) + 1; } else { usersTab.User_ID = 1; } db.UsersTabs.Add(usersTab); try { db.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, usersTab); return(message); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex)); } }
public void PostUsersTab() { var userTab = new UsersTab { FirstName = "CreatedTest", LastName = "User", Employee_ID = 333333 }; var userCtrl = new UsersTabsController(); userCtrl.Request = new HttpRequestMessage(); userCtrl.Configuration = new HttpConfiguration(); var tsk = userCtrl.PostUsersTab(userTab); Assert.AreEqual(tsk.ReasonPhrase, "Created"); }
// PUT: api/UsersTabs/5 public HttpResponseMessage Put(UsersTab usersTab) { db.Entry(usersTab).State = EntityState.Modified; try { db.SaveChanges(); if (Request == null) { return(new HttpResponseMessage(HttpStatusCode.Created)); } var message = Request.CreateResponse(HttpStatusCode.Created, usersTab); return(message); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex)); } }