Ejemplo n.º 1
0
        public alter edit_nhomtg(int id, [FromBody] Tblnhomtg ntg)
        {
            alter result = new alter();

            try
            {
                using (sql_NCKHContext db = new sql_NCKHContext())
                {
                    Tblnhomtg d = db.Tblnhomtgs.SingleOrDefault(x => x.Id == id);
                    if (d == null)
                    {
                        result.ketqua   = false;
                        result.thongbao = "Không tồn tại tác giả";
                        return(result);
                    }
                    if (ntg.Idnv != null)
                    {
                        Tblnhomtg nhomtg = db.Tblnhomtgs.SingleOrDefault(x => x.Iddetai == ntg.Iddetai && x.Idnv == ntg.Idnv && x.Chucvu == ntg.Chucvu);
                        if (nhomtg == null)
                        {
                            d.Idnv   = ntg.Idnv;
                            d.Hoten  = db.Tblnhanviens.SingleOrDefault(x => x.Id == ntg.Idnv).Hoten;
                            d.Chucvu = ntg.Chucvu;
                            db.SaveChanges();
                            result.ketqua   = true;
                            result.thongbao = "Sửa thành công";
                        }
                        else
                        {
                            result.ketqua   = false;
                            result.thongbao = "Tác giả đã tồn tại trong đề tài!! Không nên để trống họ tên";
                        }
                    }
                    else
                    {
                        Tblnhomtg nhomtg = db.Tblnhomtgs.SingleOrDefault(x => x.Iddetai == ntg.Iddetai && x.Hoten == ntg.Hoten && x.Chucvu == ntg.Chucvu);
                        if (nhomtg == null)
                        {
                            d.Hoten  = ntg.Hoten;
                            d.Chucvu = ntg.Chucvu;
                            db.SaveChanges();
                            result.ketqua   = true;
                            result.thongbao = "Sửa thành công";
                        }
                        else
                        {
                            result.ketqua   = false;
                            result.thongbao = "Tác giả đã tồn tại trong đề tài!! Không nên để trống họ tên";
                        }
                    }
                    return(result);
                }
            }
            catch (Exception ex)
            {
                result.ketqua   = false;
                result.thongbao = ex.Message;
                return(result);
            }
        }
Ejemplo n.º 2
0
 public bool edit_congtac(int id, [FromBody] Tblcongtac dv)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             Tblcongtac d = db.Tblcongtacs.SingleOrDefault(x => x.Id == id);
             if (string.IsNullOrEmpty(d.ToString()))
             {
                 return(false);
             }
             d.Noict    = dv.Noict;
             d.Ngaybad  = dv.Ngaybad;
             d.Ngaykt   = dv.Ngaykt;
             d.Chucvu   = dv.Chucvu;
             d.Chucdanh = dv.Chucdanh;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
0
 public bool create_user([FromBody] User us)
 {
     try
     {
         if (us.Hinhanh != null)
         {
             var arrData = us.Hinhanh.Split(';');
             if (arrData.Length == 3)
             {
                 var savePath = $@"assets/images/user/{arrData[0]}";
                 us.Hinhanh = $"{arrData[0]}";
                 SaveFileFromBase64String(savePath, arrData[2]);
             }
         }
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             us.Trangthai = 1;
             db.Users.Add(us);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 5
0
 public bool create_nhanvien([FromBody] Tblnhanvien nv)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             if (nv.Hinhanh != null)
             {
                 var arrData = nv.Hinhanh.Split(';');
                 if (arrData.Length == 3)
                 {
                     var savePath = $@"assets/images/emloye/{arrData[0]}";
                     nv.Hinhanh = $"{arrData[0]}";
                     SaveFileFromBase64String(savePath, arrData[2]);
                 }
             }
             db.Tblnhanviens.Add(nv);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 6
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);
     }
 }
Ejemplo n.º 7
0
 public bool create_donvi([FromBody] Tbldonvi dv)
 {
     try {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             db.Tbldonvis.Add(dv);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 8
0
 public bool create_sohuu([FromBody] Tblsohuu sh)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             db.Tblsohuus.Add(sh);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 9
0
 public bool create_congtac([FromBody] Tblcongtac ct)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             db.Tblcongtacs.Add(ct);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool create_loaitintuc([FromBody] Tblloaitt ltt)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             db.Tblloaitts.Add(ltt);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 11
0
 public bool create_boiduong([FromBody] Tblboiduong bd)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             db.Tblboiduongs.Add(bd);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool create_hoatdongnckh([FromBody] Tblhoatdongnckh nc)
 {
     using (sql_NCKHContext db = new sql_NCKHContext())
     {
         try
         {
             db.Tblhoatdongnckhs.Add(nc);
             db.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
 public bool create_loainhiemvu([FromBody] Tblloainhiemvu lnv)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             db.Tblloainhiemvus.Add(lnv);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 14
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);
     }
 }
Ejemplo n.º 15
0
        public bool chuyen_trang_thai(int id, int trangthai, string time)
        {
            try
            {
                using (sql_NCKHContext db = new sql_NCKHContext())
                {
                    Tbldetai dt = db.Tbldetais.SingleOrDefault(x => x.Id == id);
                    if (string.IsNullOrEmpty(dt.ToString()))
                    {
                        return(false);
                    }
                    switch (trangthai)
                    {
                    case 2:
                        dt.Tinhtrang  = 2;    //duyệt
                        dt.Thoigianbd = DateTime.Now;
                        dt.Thoigiannt = tinhthoigiannt(dt, Convert.ToDateTime(dt.Thoigianbd));
                        break;

                    case 3:
                        dt.Tinhtrang = 3;     //Hoan thanh
                        break;

                    case 4:
                        dt.Thoigiangiahan = giahan(time);
                        dt.Tinhtrang      = 4; //Xin them thoi gian
                        break;

                    case 5:
                        dt.Tinhtrang = 5;     //áp dụng thực tế
                        break;

                    case -1:
                        dt.Tinhtrang = -1;     //huỷ
                        break;
                    }
                    db.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
 public bool delete_sohuudetai(int id)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             Tblsohuudetai d = db.Tblsohuudetais.SingleOrDefault(x => x.Id == id);
             if (string.IsNullOrEmpty(d.ToString()))
                 return true;
             db.Tblsohuudetais.Remove(d);
             db.SaveChanges();
             return true;
         }
     }
     catch (Exception)
     {
         return false;
     }
 }
 public alter create_sohuudetai([FromBody] List<Tblsohuudetai> sh)
 {
     alter al = new alter();
     try
     {
         if(sh.Count() == 0)
         {
             al.ketqua = false;
             al.thongbao = "Không để rỗng";
             return al;
         }
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             int dem = 0;
             foreach(var item in sh)
             {
                 Tblsohuudetai result = db.Tblsohuudetais.SingleOrDefault(x => x.Iddetai == item.Iddetai && x.Idsohuu == item.Idsohuu);
                 if (result ==null)
                 {
                     Tblsohuudetai a = new Tblsohuudetai();
                     a.Iddetai = item.Iddetai;
                     a.Idsohuu = item.Idsohuu;
                     db.Tblsohuudetais.Add(a);
                     db.SaveChanges();
                 }
                 else
                 {
                     dem++;
                 }
             }
             al.ketqua = true;
             al.thongbao = string.Format("Thêm thành công {0}, lỗi {1} ", sh.Count() - dem, dem);
              return al;
         }
     }
     catch (Exception ex)
     {
         al.ketqua = false;
         al.thongbao = ex.Message;
         return al;
     }
 }
 public bool edit_sohuudetai(int id, [FromBody] Tblsohuudetai sh)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             Tblsohuudetai d = db.Tblsohuudetais.SingleOrDefault(x => x.Id == id);
             if (string.IsNullOrEmpty(d.ToString()))
                 return false;
             d.Idsohuu = sh.Idsohuu;
             d.Ghichu = sh.Ghichu;
             db.SaveChanges();
             return true;
         }
     }
     catch (Exception)
     {
         return false;
     }
 }
Ejemplo n.º 19
0
 public bool edit_role(int id, [FromBody] Role rl)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             Role d = db.Roles.SingleOrDefault(x => x.Id == id);
             if (string.IsNullOrEmpty(d.ToString()))
             {
                 return(false);
             }
             d.Ten = rl.Ten;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool delete_loainhiemvu(int id)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             Tblloainhiemvu d = db.Tblloainhiemvus.SingleOrDefault(x => x.Id == id);
             if (string.IsNullOrEmpty(d.ToString()))
             {
                 return(true);
             }
             db.Tblloainhiemvus.Remove(d);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool delete_hoatdongnckh(int id, [FromBody] Tblhoatdongnckh nc)
 {
     using (sql_NCKHContext db = new sql_NCKHContext())
     {
         try
         {
             Tblhoatdongnckh kh = db.Tblhoatdongnckhs.SingleOrDefault(x => x.Id == id);
             if (kh == null)
             {
                 return(false);
             }
             db.Tblhoatdongnckhs.Remove(kh);
             db.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
Ejemplo n.º 22
0
 public bool change_pass(int id, string pass)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             User result = db.Users.SingleOrDefault(x => x.Id == id);
             if (string.IsNullOrEmpty(result.ToString()))
             {
                 return(false);
             }
             result.Matkhau = pass;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 23
0
 public bool edit_linhvuc(int id, [FromBody] Tbllinhvuc lv)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             Tbllinhvuc d = db.Tbllinhvucs.SingleOrDefault(x => x.Id == id);
             if (string.IsNullOrEmpty(d.ToString()))
             {
                 return(false);
             }
             d.Tenlinhvuc = lv.Tenlinhvuc;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool edit_loaitintuc(int id, [FromBody] Tblloaitt ltt)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             Tblloaitt d = db.Tblloaitts.SingleOrDefault(x => x.Id == id);
             if (string.IsNullOrEmpty(d.ToString()))
             {
                 return(false);
             }
             d.Tenloaitt = ltt.Tenloaitt;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 25
0
        public bool edit_phanhoi(int id, [FromBody] Tblphanhoi ph)
        {
            try
            {
                using (sql_NCKHContext db = new sql_NCKHContext())
                {
                    Tblphanhoi d = db.Tblphanhois.SingleOrDefault(x => x.Id == id);
                    if (string.IsNullOrEmpty(d.ToString()))
                    {
                        return(false);
                    }

                    db.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 26
0
 public bool edit_lylich(int id, [FromBody] lylich ll)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             Tbllylich d = db.Tbllyliches.SingleOrDefault(x => x.Id == id);
             if (string.IsNullOrEmpty(d.ToString()))
             {
                 return(false);
             }
             d.Hocham   = ll.Hocham;
             d.Namphong = ll.Namphong;
             d.Hocvi    = ll.Hocvi;
             d.Namcap   = ll.Namcap;
             // Dai hoc
             d.Hedaotao      = ll.Hedaotao;
             d.Noidaotao     = ll.Noidaotao;
             d.Nganhhoc      = ll.Nganhhoc;
             d.Nuocdaotao    = ll.Nuocdaotao;
             d.Namtotnghiep  = ll.Namtotnghiep;
             d.Bangdaihoc    = ll.Bangdaihoc;
             d.Namtotnghiep2 = ll.Namtotnghiep2;
             // sau dai hoc
             d.Bangthacsi  = ll.Bangthacsi;
             d.Namcapbang  = ll.Namcapbang;
             d.Noidaotaoa2 = ll.Noidaotao2;
             d.Bangtiensi  = ll.Bangtiensi;
             d.Namcapbang2 = ll.Namcapbang2;
             d.Noidaotao2  = ll.Noidaotao2;
             d.Tenchuyende = ll.Tenchuyende;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 27
0
 public bool edit_phongban(int id, [FromBody] Tblphongban pb)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             Tblphongban d = db.Tblphongbans.SingleOrDefault(x => x.Id == id);
             if (string.IsNullOrEmpty(d.ToString()))
             {
                 return(false);
             }
             d.Tenphongban = pb.Tenphongban;
             d.Iddv        = pb.Iddv;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 28
0
        public alter create_nhomtg([FromBody] List <Tblnhomtg> ntg)
        {
            alter result = new alter();

            try
            {
                using (sql_NCKHContext db = new sql_NCKHContext())
                {
                    int dem = 0;
                    foreach (var item in ntg)
                    {
                        Tblnhomtg tg = db.Tblnhomtgs.Where(x => (x.Chucvu == item.Chucvu && x.Iddetai == item.Iddetai && x.Idnv == item.Idnv) || (x.Chucvu == item.Chucvu && x.Iddetai == item.Iddetai && x.Hoten == item.Hoten)).SingleOrDefault();
                        if (tg == null)
                        {
                            if (item.Idnv != null)
                            {
                                Tblnhanvien nv = db.Tblnhanviens.SingleOrDefault(x => x.Id == item.Idnv);
                                item.Hoten = nv.Hoten;
                            }
                            db.Tblnhomtgs.Add(item);
                            db.SaveChanges();
                        }
                        else
                        {
                            dem++;
                        }
                        result.ketqua   = true;
                        result.thongbao = string.Format("Thêm thành công {0}, lỗi {1}", ntg.Count() - dem, dem);
                    }
                    return(result);
                }
            }
            catch (Exception ex)
            {
                result.ketqua   = false;
                result.thongbao = ex.Message;
                return(result);
            }
        }
Ejemplo n.º 29
0
        public alter change_status(int id)
        {
            alter result = new alter();

            try
            {
                using (sql_NCKHContext db = new sql_NCKHContext())
                {
                    User nguoidung = db.Users.SingleOrDefault(x => x.Id == id);
                    if (nguoidung == null)
                    {
                        result.ketqua   = false;
                        result.thongbao = "Không tồn tại tài khoản này";
                    }
                    else
                    {
                        if (nguoidung.Trangthai == 1)
                        {
                            nguoidung.Trangthai = 2;
                            result.thongbao     = "Tầi khoản này đã bị vô hiệu hoá";
                        }
                        else
                        {
                            nguoidung.Trangthai = 1;
                            result.thongbao     = "Tầi khoản này hoạt động bình thường";
                        }
                        result.ketqua = true;
                        db.SaveChanges();
                    }
                    return(result);
                }
            }
            catch (Exception ex)
            {
                result.ketqua   = false;
                result.thongbao = ex.Message;
                return(result);
            }
        }
Ejemplo n.º 30
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);
     }
 }