Exemplo n.º 1
0
 public bool create_tintuc([FromBody] Tbltintuc tt)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             if (tt.Hinhanh != null)
             {
                 var arrData = tt.Hinhanh.Split(';');
                 if (arrData.Length == 3)
                 {
                     var savePath = $@"assets/images/news/{arrData[0]}";
                     tt.Hinhanh = $"{arrData[0]}";
                     SaveFileFromBase64String(savePath, arrData[2]);
                 }
             }
             tt.Luotem = 0;
             db.Tbltintucs.Add(tt);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Exemplo n.º 2
0
        public Tbltintuc get_tintuc_id(int id)
        {
            Tbltintuc ltt = new Tbltintuc();

            using (sql_NCKHContext db = new sql_NCKHContext())
            {
                ltt = db.Tbltintucs.SingleOrDefault(x => x.Id == id);
            }
            return(ltt);
        }
Exemplo n.º 3
0
 public bool set_tintuc_luotxem(int id)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             Tbltintuc tt = db.Tbltintucs.SingleOrDefault(x => x.Id == id);
             tt.Luotem = tt.Luotem + 1;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 4
0
 public bool delete_tintuc(int id)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             Tbltintuc d = db.Tbltintucs.SingleOrDefault(x => x.Id == id);
             if (string.IsNullOrEmpty(d.ToString()))
             {
                 return(true);
             }
             db.Tbltintucs.Remove(d);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 5
0
 public bool edit_tintuc(int id, [FromBody] Tbltintuc tt)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             Tbltintuc d = db.Tbltintucs.SingleOrDefault(x => x.Id == id);
             if (string.IsNullOrEmpty(d.ToString()))
             {
                 return(false);
             }
             d.Tieude = tt.Tieude;
             if (tt.Hinhanh != null)
             {
                 var arrData = tt.Hinhanh.Split(';');
                 if (arrData.Length == 3)
                 {
                     var savePath = $@"assets/images/{arrData[0]}";
                     tt.Hinhanh = $"{arrData[0]}";
                     SaveFileFromBase64String(savePath, arrData[2]);
                 }
             }
             else
             {
                 tt.Hinhanh = d.Hinhanh;
             }
             d.Hinhanh = tt.Hinhanh;
             d.Idloai  = tt.Idloai;
             d.Noidung = tt.Noidung;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }