예제 #1
0
 public bool create_hoso([FromBody] Tblhoso dv)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             if (dv.Minhchung != null)
             {
                 var arrData = dv.Minhchung.Split(';');
                 if (arrData.Length == 3)
                 {
                     var savePath = $@"assets/file/{arrData[0]}";
                     dv.Minhchung = $"{arrData[0]}";
                     SaveFileFromBase64String(savePath, arrData[2]);
                 }
             }
             db.Tblhosos.Add(dv);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #2
0
        public Tblhoso get_hoso_id(int id)
        {
            Tblhoso dv = new Tblhoso();

            using (sql_NCKHContext db = new sql_NCKHContext())
            {
                dv = db.Tblhosos.SingleOrDefault(x => x.Id == id);
            }
            return(dv);
        }
예제 #3
0
 public bool delete_hoso(int id)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             Tblhoso d = db.Tblhosos.SingleOrDefault(x => x.Id == id);
             if (string.IsNullOrEmpty(d.ToString()))
             {
                 return(true);
             }
             db.Tblhosos.Remove(d);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #4
0
 public bool edit_hoso(int id, [FromBody] Tblhoso hs)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             Tblhoso d = db.Tblhosos.SingleOrDefault(x => x.Id == id);
             if (string.IsNullOrEmpty(d.ToString()))
             {
                 return(false);
             }
             if (hs.Minhchung != null)
             {
                 var arrData = hs.Minhchung.Split(';');
                 if (arrData.Length == 3)
                 {
                     var savePath = $@"assets/file/{arrData[0]}";
                     hs.Minhchung = $"{arrData[0]}";
                     SaveFileFromBase64String(savePath, arrData[2]);
                 }
             }
             else
             {
                 hs.Minhchung = d.Minhchung;
             }
             d.Ten       = hs.Ten;
             d.Ngay      = hs.Ngay;
             d.Minhchung = hs.Minhchung;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }