示例#1
0
        public ActionResult EditResource(ResourceModel model)
        {
            if (!ModelState.IsValid)
            {
                return RedirectToAction("Error", new { eID = 0 });
            }

            try
            {
                var resource = _repository.FindResourceByID(model.ResourceID);
                resource.Description = model.Description;
                resource.Keywords = model.Keywords;
                resource.Source = model.Source;
                resource.Language = model.Language;
                resource.Copyright = model.Copyright;
                resource.LastModifiedByUserID = int.Parse(User.Identity.Name);
                resource.LastModifiedOnDate = DateTime.Now;

                if (resource.CreatedByUserID != resource.LastModifiedByUserID)
                {
                    resource.IsPublic = 1;
                }
                else
                {
                    resource.IsPublic = model.IsPublic;
                }

                string old_dir = _root + resource.Path + resource.ResourceName + resource.Extension; // Old directory
                string new_dir = _root + resource.Path + model.ResourceName + resource.Extension;    // new directory

                if (!old_dir.Equals(new_dir))
                {
                    if (!System.IO.File.Exists(new_dir))
                    {
                        System.IO.File.Move(old_dir, new_dir);
                        resource.ResourceName = model.ResourceName;
                        _repository.UpdateResoure(resource);
                        _repository.CommitChanges();
                    }
                    else
                    {
                        return RedirectToAction("Error", new { eID = 7 });
                    }
                }
                else
                {
                    _repository.UpdateResoure(resource);
                    _repository.CommitChanges();
                }
                return RedirectToAction("ShowFolder", new { folderID = resource.FolderID });
            }
            catch (Exception)
            {
                return RedirectToAction("Error", new {eID = 0});
            }
        }
示例#2
0
        public ActionResult CreateNewResource(ResourceModel model, HttpPostedFileBase file)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return RedirectToAction("Error", new { eID = 0 });
                }

                if (file == null || file.ContentLength == 0)
                {
                    return RedirectToAction("Error", new { eID = 5 });
                }

                // Max = 25MB
                if (file.ContentLength > 26214400)
                {
                    return RedirectToAction("Error", new { eID = 6 });
                }

                var folder = _repository.FindFolderByID(model.FolderID);
                var resource = new Resource
                                   {
                                       ResourceName = file.FileName.Substring(0, file.FileName.LastIndexOf(".")),
                                       Path = folder.Path + folder.FolderName + @"\",
                                       Size = GetFileSize(file.ContentLength),
                                       Description = model.Description,
                                       Keywords = model.Keywords,
                                       Source = model.Source,
                                       Language = model.Language,
                                       Copyright = model.Copyright,
                                       FolderID = folder.ID,
                                       IsDeleted = 0,
                                       IsPublic = model.IsPublic,
                                       Extension = Path.GetExtension(file.FileName),
                                       CreatedByUserID = int.Parse(HttpContext.User.Identity.Name),
                                       CreatedOnDate = DateTime.Now
                                   };
                var dir = _root + resource.Path;
                var path = Path.Combine(dir, resource.ResourceName + resource.Extension);

                if (!System.IO.File.Exists(path))
                {
                    file.SaveAs(path);
                    _repository.AddResource(resource);
                    _repository.CommitChanges();
                }
                else
                {
                    return RedirectToAction("Error", new { eID = 7 });
                }
                return RedirectToAction("ShowFolder", new { folderID = folder.ID });
            }
            catch (Exception)
            {
                return RedirectToAction("Error", new {eID = 0});
            }
        }
示例#3
0
 public PartialViewResult EditResource(int resourceID)
 {
     var resource = _repository.FindResourceByID(resourceID);
     var model = new ResourceModel
                     {
                         ResourceName = resource.ResourceName,
                         ResourceID = resource.ID,
                         Description = resource.Description,
                         Keywords = resource.Keywords,
                         Source = resource.Source,
                         Language = resource.Language,
                         Copyright = resource.Copyright,
                         IsPublic = resource.IsPublic.Value,
                         CreateByUserID = resource.CreatedByUserID
                     };
     return PartialView(model);
 }
示例#4
0
 public PartialViewResult CreateNewResource(int folderID)
 {
     var model = new ResourceModel { FolderID = folderID };
     return PartialView(model);
 }