public async Task <IHttpActionResult> Puttb_bai(int id, tb_bai tb_bai) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tb_bai.id_bai) { return(BadRequest()); } db.Entry(tb_bai).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!tb_baiExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> Gettb_bai(int id) { tb_bai tb_bai = await db.tb_bai.FindAsync(id); if (tb_bai == null) { return(NotFound()); } return(Ok(tb_bai)); }
public async Task <IHttpActionResult> Posttb_bai(tb_bai tb_bai) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.tb_bai.Add(tb_bai); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = tb_bai.id_bai }, tb_bai)); }
public async Task <IHttpActionResult> Deletetb_bai(int id) { tb_bai tb_bai = await db.tb_bai.FindAsync(id); if (tb_bai == null) { return(NotFound()); } db.tb_bai.Remove(tb_bai); await db.SaveChangesAsync(); return(Ok(tb_bai)); }
public HttpResponseMessage InsertBai([FromBody] EnBai bai) { //return CreateResponse(bai); var objInsert = new tb_bai { id_chuyende = bai.id_chuyende, ngay_tao = bai.ngay_tao, bai_mau = bai.bai_mau, thu_tu = bai.thu_tu, xuat_ban = bai.xuat_ban, tb_templatenoidung = bai.ds_templatenoidungdebai.Select(b => { if (b.loai_template == LoaiTemplateNoidungDeBai.TEXT) { return(new tb_templatenoidung { loai_template = LoaiTemplateNoidungDeBai.TEXT, tb_templatenoidung_text = new tb_templatenoidung_text { noidung = b.template_noidung_text.noi_dung } }); } else if (b.loai_template == LoaiTemplateNoidungDeBai.HINH_ANH) { return(new tb_templatenoidung { loai_template = LoaiTemplateNoidungDeBai.HINH_ANH, tb_templatenoidung_hinhanh = new tb_templatenoidung_hinhanh { url = b.template_noidung_hinhanh.url } }); } return(new tb_templatenoidung { }); }).ToList(), tb_cauhoi = bai.ds_cauhoi.Select(h => new tb_cauhoi { loai_cau_hoi = h.loai_cau_hoi, ngay_tao = h.ngay_tao, phuong_thuc_check_dap_an = h.phuongthuc_check_dapan, thu_tu = h.thu_tu, xuat_ban = h.xuat_ban, gia_tri_dung = h.gia_tri_dung, tb_templatenoidung = h.ds_templatenoidungcauhoi.Select(t => { if (t.loai_template == LoaiTemplateNoidungDeBai.TEXT) { return(new tb_templatenoidung { loai_template = LoaiTemplateNoidungDeBai.TEXT, tb_templatenoidung_text = new tb_templatenoidung_text { noidung = t.template_noidung_text.noi_dung } }); } else if (t.loai_template == LoaiTemplateNoidungDeBai.HINH_ANH) { return(new tb_templatenoidung { loai_template = LoaiTemplateNoidungDeBai.HINH_ANH, tb_templatenoidung_hinhanh = new tb_templatenoidung_hinhanh { url = t.template_noidung_hinhanh.url } }); } return(new tb_templatenoidung { }); }).ToList() }).ToList() }; try { tb_bai rs = null; using (var db = new appbookEntities2()) { rs = db.tb_bai.Add(objInsert); db.SaveChanges(); } return(CreateResponse(rs)); } catch (Exception ex) { return(CreateResponse(new { error = ex.Message })); } }