Esempio n. 1
0
        // POST api/ProjectSide
        public HttpResponseMessage PostProjectSide(ProjectSide projectside)
        {
            if (ModelState.IsValid)
            {
                //db.ProjectSides.Add(projectside);
                projectside.InsertBy = loginUser.UserID;
                db.Entry(projectside).State = projectside.ProjectSideID == 0 ?
                EntityState.Added : EntityState.Modified;
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, projectside);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = projectside.ProjectSideID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Esempio n. 2
0
        // PUT api/ProjectSide/5
        public HttpResponseMessage PutProjectSide(long id, ProjectSide projectside)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != projectside.ProjectSideID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            projectside.UpdateBy = loginUser.UserID;
            db.Entry(projectside).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }