public async Task <IActionResult> PutPhieuThuChiTiet([FromRoute] int id, [FromBody] PhieuThuChiTiet phieuthuchitiet)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != phieuthuchitiet.PhieuThuChiTietId)
            {
                return(BadRequest());
            }

            _context.Entry(phieuthuchitiet).State = EntityState.Modified;

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

            return(NoContent());
        }
        public async Task <IActionResult> PostPhieuThuChiTiet([FromBody] PhieuThuChiTiet phieuthuchitiet)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.PhieuThuChiTiets.Add(phieuthuchitiet);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPhieuThuChiTiet", new { id = phieuthuchitiet.PhieuThuChiTietId }, phieuthuchitiet));
        }
Exemple #3
0
        public IEnumerable <TheXe> GetItems([FromRoute] int start, int count, string orderBy, [FromBody] string whereClause)
        {
            orderBy = orderBy != "x" ? orderBy : "";
            var thexes = _context.Set <TheXe>().FromSql($"tbl_TheXe_GetItemsByRange {start},{count},{whereClause},{orderBy}").ToList <TheXe>();

            for (int i = 0; i < thexes.Count(); i++)
            {
                thexes[i].LoaiXes = _context.LoaiXes.SingleOrDefault(o => o.LoaiXeId == thexes[i].LoaiXeId);
                PhieuThuChiTiet pt = _context.PhieuThuChiTiets.Where(o => o.TheXeId == thexes[i].TheXeId).OrderByDescending(o => o.HanDenNgay).FirstOrDefault();
                thexes[i].PhieuThuChiTiets = pt;
            }
            return(thexes);
        }