コード例 #1
0
        public async Task <IHttpActionResult> PutCostStructure(int id, CostStructure costStructure)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != costStructure.Id)
            {
                return(BadRequest());
            }

            db.Entry(costStructure).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CostStructureExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        public async Task <IHttpActionResult> GetCostStructure(int id)
        {
            CostStructure costStructure = await db.CostStructures.FindAsync(id);

            if (costStructure == null)
            {
                return(NotFound());
            }

            return(Ok(costStructure));
        }
コード例 #3
0
        public async Task <IHttpActionResult> PostCostStructure(CostStructure costStructure)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.CostStructures.Add(costStructure);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = costStructure.Id }, costStructure));
        }
コード例 #4
0
        public async Task <IHttpActionResult> DeleteCostStructure(int id)
        {
            CostStructure costStructure = await db.CostStructures.FindAsync(id);

            if (costStructure == null)
            {
                return(NotFound());
            }

            db.CostStructures.Remove(costStructure);
            await db.SaveChangesAsync();

            return(Ok(costStructure));
        }