public async Task <IActionResult> PutBoPhan(int id, BoPhanViewModel boPhan) { if (id != boPhan.Id) { return(BadRequest()); } var boPhanV = Mapper.Map <BoPhanViewModel, BoPhan>(boPhan); try { _context.Update(boPhanV); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BoPhanExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <BoPhan> > PostBoPhan(BoPhanViewModel boPhanViewModel) { var boPhan = Mapper.Map <BoPhanViewModel, BoPhan>(boPhanViewModel); _context.BoPhans.Add(boPhan); await _context.SaveChangesAsync(); return(CreatedAtAction("GetBoPhan", new { id = boPhan.Id }, boPhan)); }
public async Task <APIResult <BoPhanViewModel> > Details(int IDBP) { var bp = await _context.BoPhans.FirstOrDefaultAsync(x => x.IDBP == IDBP); var bpmd = new BoPhanViewModel() { IDBP = bp.IDBP, TenBP = bp.TenBP }; return(new APISuccessedResult <BoPhanViewModel>(bpmd)); }
public async Task <APIResult <List <BoPhanViewModel> > > GetAllWithNotPaging() { var query = from bp in _context.BoPhans select bp; var list = new List <BoPhanViewModel>(); foreach (var data in query) { var cvmd = new BoPhanViewModel() { TenBP = data.TenBP, IDBP = data.IDBP }; list.Add(cvmd); } return(new APISuccessedResult <List <BoPhanViewModel> >(list)); }