public ActionResult UploadFileTaiLieu(int id, HttpPostedFileBase fileTaiLieu)
 {
     using (var kHKTKhoaHocKiThuatRepository = new KHKTKhoaHocKiThuatService())
     {
         try
         {
             if (fileTaiLieu.ContentLength > 0)
             {
                 //string filename = Path.GetFileName(fileTaiLieu.FileName);
                 KhoaHocKiThuat khoaHocKiThuat = kHKTKhoaHocKiThuatRepository.GetKhoaHocKiThuatById(id);
                 if (khoaHocKiThuat == null)
                 {
                     return(Json("failed"));
                 }
                 string filename = String.Format("{0:00}", khoaHocKiThuat.LinhVucId) + '-' + khoaHocKiThuat.Id.ToString() + Path.GetExtension(fileTaiLieu.FileName);
                 string _path    = Path.Combine(Server.MapPath("~/UploadedFiles/KhoaHocKiThuat"), filename);
                 fileTaiLieu.SaveAs(_path);
                 kHKTKhoaHocKiThuatRepository.UpdateFileTaiLieuKhoaHocKiThuat(id, filename.Trim());
                 return(Json(new ReturnFormat(200, "success", null), JsonRequestBehavior.AllowGet));
             }
             else
             {
                 kHKTKhoaHocKiThuatRepository.DeleteKHKTById(id);
                 return(Json("failed"));
             }
         }
         catch
         {
             kHKTKhoaHocKiThuatRepository.DeleteKHKTById(id);
             return(Json("failed"));
         }
     }
 }
Example #2
0
 public KhoaHocKiThuat CreateKhoaHocKiThuat(KhoaHocKithuatDTO khoaHocKithuatDTO)
 {
     using (var _db = new HoatDongTraiNghiemDB())
     {
         KhoaHocKiThuat khoaHocKiThuat = new KhoaHocKiThuat();
         khoaHocKiThuat.DongGopHs1    = khoaHocKithuatDTO.DongGopHs1;
         khoaHocKiThuat.DongGopHs2    = khoaHocKithuatDTO.DongGopHs2;
         khoaHocKiThuat.HocSinh1      = khoaHocKithuatDTO.HocSinh1;
         khoaHocKiThuat.HocSinh2      = khoaHocKithuatDTO.HocSinh2;
         khoaHocKiThuat.IsCaNhan      = khoaHocKithuatDTO.IsCaNhan;
         khoaHocKiThuat.LinhVucId     = khoaHocKithuatDTO.LinhVucId;
         khoaHocKiThuat.LopIdHocSinh1 = khoaHocKithuatDTO.LopIdHocSinh1;
         khoaHocKiThuat.LopIdhocSinh2 = khoaHocKithuatDTO.LopIdhocSinh2;
         khoaHocKiThuat.TenDeTai      = khoaHocKithuatDTO.TenDeTai;
         khoaHocKiThuat.SchoolId      = khoaHocKithuatDTO.SchoolId;
         khoaHocKiThuat.CreatedAt     = DateTime.Now;
         khoaHocKiThuat.GVHD          = khoaHocKithuatDTO.GVHD;
         khoaHocKiThuat.Email         = khoaHocKithuatDTO.Email;
         khoaHocKiThuat.SDT           = khoaHocKithuatDTO.SDT;
         khoaHocKiThuat.DVCongTac     = khoaHocKithuatDTO.DVCongTac;
         _db.KhoaHocKiThuats.Add(khoaHocKiThuat);
         _db.SaveChanges();
         return(khoaHocKiThuat);
     }
 }
Example #3
0
 public KhoaHocKiThuat GetKhoaHocKiThuatById(int id)
 {
     using (var _db = new HoatDongTraiNghiemDB())
     {
         KhoaHocKiThuat khoaHocKiThuat = _db.KhoaHocKiThuats.Where(s => s.Id == id).SingleOrDefault();
         return(khoaHocKiThuat);
     }
 }
Example #4
0
 public KhoaHocKiThuat UpdateFileTaiLieuKhoaHocKiThuat(int id, string tenFile)
 {
     using (var _db = new HoatDongTraiNghiemDB())
     {
         KhoaHocKiThuat khoaHocKiThuat = _db.KhoaHocKiThuats.Where(s => s.Id == id).SingleOrDefault();
         khoaHocKiThuat.FileTaiLieu      = tenFile.Trim();
         _db.Entry(khoaHocKiThuat).State = EntityState.Modified;
         try
         {
             _db.SaveChanges();
         }
         catch (Exception)
         {
             return(null);
         }
         return(khoaHocKiThuat);
     }
 }
        public ActionResult DangKiKHKT(KhoaHocKithuatDTO khoaHocKithuatDTO)
        {
            var school = (T_DM_Truong)Session[Constant.SCHOOL_SESSION];

            if (school == null)
            {
                return(RedirectToRoute("login"));
            }
            khoaHocKithuatDTO.SchoolId = school.SchoolID;
            using (var kHKTKhoaHocKiThuatRepository = new KHKTKhoaHocKiThuatService())
            {
                KhoaHocKiThuat khoaHocKiThuat = kHKTKhoaHocKiThuatRepository.CreateKhoaHocKiThuat(khoaHocKithuatDTO);
                if (khoaHocKiThuat == null)
                {
                    return(Json(new ReturnFormat(400, "failed", null), JsonRequestBehavior.AllowGet));
                }
                return(Json(new ReturnFormat(200, "success", khoaHocKiThuat.Id), JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult TaiFileTaiLieuKHKT(int id)
        {
            Account account = (Account)Session[Utils.Constant.MANAGER_SESSION];

            if (account == null)
            {
                return(RedirectToRoute("login"));
            }
            using (var kHKTKhoaHocKiThuatRepository = new KHKTKhoaHocKiThuatService())
            {
                KhoaHocKiThuat khoaHocKiThuat = kHKTKhoaHocKiThuatRepository.GetKhoaHocKiThuatById(id);
                string         filePath       = System.Web.HttpContext.Current.Server.MapPath("~/UploadedFiles/KhoaHocKiThuat/" + khoaHocKiThuat.FileTaiLieu.Trim());
                if (khoaHocKiThuat.FileTaiLieu.Contains(".docx"))
                {
                    return(File(filePath, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", khoaHocKiThuat.FileTaiLieu));
                }
                else if (khoaHocKiThuat.FileTaiLieu.Contains(".xlsx"))
                {
                    return(File(filePath, "application/vnd.ms-excel", khoaHocKiThuat.FileTaiLieu));
                }
                return(File(filePath, "application/msword", khoaHocKiThuat.FileTaiLieu));
            }
        }