コード例 #1
0
        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));
            }
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        // 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));
            }
        }