コード例 #1
0
ファイル: FiscalYearController.cs プロジェクト: daradbd/BMS
        // POST api/FiscalYear
        public HttpResponseMessage PostFiscalYear(FiscalYear fiscalyear)
        {
            if (ModelState.IsValid)
            {
                fiscalyear.InsertBy = loginUser.UserID;
                db.FiscalYears.Add(fiscalyear);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, fiscalyear);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = fiscalyear.FiscalYearID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
コード例 #2
0
ファイル: FiscalYearController.cs プロジェクト: daradbd/BMS
        // PUT api/FiscalYear/5
        public HttpResponseMessage PutFiscalYear(long id, FiscalYear fiscalyear)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != fiscalyear.FiscalYearID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }