public IHttpActionResult DangKiLichHoc(LichHocDto lichHocDto) { if (!ModelState.IsValid) { return(BadRequest()); } LichHoc lichHoc; if (lichHocDto.Id == 0) { lichHoc = Mapper.Map <LichHocDto, LichHoc>(lichHocDto); _context.LichHoc.Add(lichHoc); _context.SaveChanges(); return(Ok()); } lichHoc = _context.LichHoc.SingleOrDefault(lh => lh.Id == lichHocDto.Id); if (lichHoc == null) { return(NotFound()); } lichHoc.MapForEdit(lichHocDto); _context.SaveChanges(); return(Ok()); }
public void MapForEdit(LichHocDto lichHocDto) { BuoiSang = lichHocDto.BuoiSang; BaTietDau = lichHocDto.BaTietDau; Thu246 = lichHocDto.Thu246; NgayBatDau = lichHocDto.NgayBatDau; NgayKetThuc = lichHocDto.NgayKetThuc; GiaoVienDay = lichHocDto.GiaoVienDay; PhongHoc = lichHocDto.PhongHoc; }