public ActionResult Create(int?parent, bool isFolder = false)
        {
            var model = new TaiNguyen
            {
                idTaiNguyen = parent,
                laThuMuc    = isFolder
            };

            model.Include(db);
            return(View(model));
        }
 public ActionResult Create(TaiNguyen model)
 {
     if (ModelState.IsValid)
     {
         using (var scope = new TransactionScope())
         {
             db.TaiNguyen.Add(model);
             db.SaveChanges();
             model.Include(db);
             if (model.laThuMuc)
             {
                 try
                 {
                     Create(model.getFolder());
                     scope.Complete();
                     return(RedirectToAction("Index", new { parent = model.idTaiNguyen }));
                 }
                 catch (Exception e)
                 {
                     ModelState.AddModelError("tenTaiNguyen", e.Message);
                 }
             }
             else
             {
                 try
                 {
                     if (!String.IsNullOrEmpty(model.tepDinhKem))
                     {
                         var file = Request.Files[0];
                         model.tepDinhKem = file.FileName;
                         db.SaveChanges();
                         Upload(file, model.getFolder());
                     }
                     scope.Complete();
                     return(RedirectToAction("Index", new { parent = model.idTaiNguyen }));
                 }
                 catch (Exception e)
                 {
                     ModelState.AddModelError("tepDinhKem", e.Message);
                 }
             }
         }
     }
     return(View(model));
 }
 public ActionResult Rename(TaiNguyen model, string folder)
 {
     if (ModelState.IsValid)
     {
         using (var scope = new TransactionScope())
             try
             {
                 db.Entry(model).State = EntityState.Modified;
                 db.SaveChanges();
                 model.Include(db);
                 if (model.laThuMuc)
                 {
                     Rename(folder, model.getFolder());
                 }
                 scope.Complete();
                 return(RedirectToAction("Index", new { parent = model.idTaiNguyen }));
             }
             catch (Exception e)
             {
                 ModelState.AddModelError("tenTaiNguyen", e.Message);
             }
     }
     return(View(model));
 }