예제 #1
0
        public async Task <IActionResult> UpdateById(string soHDDV, string maDichVu, ChiTietHDDVForUpdateDto chiTietHDDV)
        {
            try
            {
                var result = await _repo.UpdateById(soHDDV, maDichVu, chiTietHDDV);

                return(StatusCode(200, new SuccessResponseDto
                {
                    Message = "Cập nhật " + _entityName + " thành công!",
                    Result = new SuccessResponseResultWithSingleDataDto
                    {
                        Data = result
                    }
                }));
            }
            catch (Exception e)
            {
                return(StatusCode(500, new FailedResponseDto
                {
                    Message = "Cập nhật " + _entityName + " thất bại!",
                    Result = new FailedResponseResultDto
                    {
                        Errors = e
                    }
                }));
            }
        }
예제 #2
0
        public async Task <ChiTietHDDV> UpdateById(string soHDDV, string maDichVu, ChiTietHDDVForUpdateDto chiTietHDDV)
        {
            var oldRecord = await _context.DanhSachChiTietHDDV.AsNoTracking().FirstOrDefaultAsync(x => x.SoHDDV == soHDDV && x.MaDichVu == maDichVu);

            var chiTietHDDVToUpdate = new ChiTietHDDV
            {
                SoHDDV          = soHDDV,
                MaDichVu        = maDichVu,
                SoLuong         = chiTietHDDV.SoLuong,
                DonGia          = chiTietHDDV.DonGia,
                ThanhTien       = chiTietHDDV.ThanhTien,
                TrangThai       = chiTietHDDV.TrangThai,
                ThoiGianTao     = oldRecord.ThoiGianTao,
                ThoiGianCapNhat = DateTime.Now
            };

            _context.DanhSachChiTietHDDV.Update(chiTietHDDVToUpdate);
            await _context.SaveChangesAsync();

            return(chiTietHDDVToUpdate);
        }