예제 #1
0
        public async Task <IHttpActionResult> PutMasterDetail(int id, MasterDetailVM masterDetailVM)
        {
            MasterDetail masterDetail = ConvertToDBModel(masterDetailVM);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != masterDetail.ID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
 private MasterDetail ConvertToDBModel(MasterDetailVM md)
 {
     return(new MasterDetail
     {
         ID = md.ID,
         DisplayText = md.DisplayText,
         DisplayOrder = md.DisplayOrder,
         MasterType = md.MasterType,
         IsDeleted = md.IsDeleted
     });
 }
예제 #3
0
        public async Task <IHttpActionResult> PostMasterDetail(MasterDetailVM masterDetail)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.MasterDetails.Add(ConvertToDBModel(masterDetail));
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = masterDetail.ID }, masterDetail));
        }