public async Task <IHttpActionResult> PutHistoryKhamBenh(int id, HistoryKhamBenh historyKhamBenh)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != historyKhamBenh.IDHistory)
            {
                return(BadRequest());
            }

            db.Entry(historyKhamBenh).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> PostHistoryKhamBenh(HistoryKhamBenh historyKhamBenh)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.HistoryKhamBenhs.Add(historyKhamBenh);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (HistoryKhamBenhExists(historyKhamBenh.IDHistory))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = historyKhamBenh.IDHistory }, historyKhamBenh));
        }
        public async Task <IHttpActionResult> DeleteHistoryKhamBenh(int id)
        {
            HistoryKhamBenh historyKhamBenh = await db.HistoryKhamBenhs.FindAsync(id);

            if (historyKhamBenh == null)
            {
                return(NotFound());
            }

            db.HistoryKhamBenhs.Remove(historyKhamBenh);
            await db.SaveChangesAsync();

            return(Ok(ConvertToHistoryKhamBenhDTO(historyKhamBenh)));
        }
        public async Task <IHttpActionResult> GetHistoryKhamBenh(int id)
        {
            HistoryKhamBenh historyKhamBenh = await db.HistoryKhamBenhs.FindAsync(id);

            if (historyKhamBenh == null)
            {
                return(NotFound());
            }

            if (LoginHelper.CheckAccount(historyKhamBenh.Register.IDAccount ?? 0) == false)
            {
                return(NotFound());
            }

            return(Ok(ConvertToHistoryKhamBenhDTO(historyKhamBenh)));
        }
 private HistoryKhamBenhDTO ConvertToHistoryKhamBenhDTO(HistoryKhamBenh item)
 {
     return(new HistoryKhamBenhDTO
     {
         CanNang = item.CanNang,
         ChieuCao = item.ChieuCao,
         ChuanDoanSoBo = item.ChuanDoanSoBo,
         CreateTime = item.CreateTime,
         HuyetApTD = item.HuyetApTD,
         HuyetApTT = item.HuyetApTT,
         ICD = item.ICD,
         IDDoctor = item.IDDoctor,
         IDHistory = item.IDHistory,
         IDRegister = item.IDRegister,
         Mach = item.Mach,
         NhietDo = item.NhieuDo,
         NhipTho = item.NhipTho,
         TrieuChungLS = item.TrieuChungLS,
         Doctor_FullName = item.Doctor.FullName,
         Register_CreateTime = item.Register.CreateDate,
         CachGiaiQuyet = item.CachGiaiQuyet,
         Specia_Name = item.Register.Doctor.Specia.Name
     });
 }