Пример #1
0
 public void AddResource(Resource resource)
 {
     try
     {
         DB.AddToResources(resource);
     }
     catch (Exception)
     {
         throw new Exception("Lỗi thêm tài nguyên");
     }
 }
Пример #2
0
        public void UpdateResoure(Resource resource)
        {
            try
            {
                //TODO: Update Resource
            }
            catch (Exception)
            {

                throw;
            }
        }
Пример #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Resources EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToResources(Resource resource)
 {
     base.AddObject("Resources", resource);
 }
Пример #4
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});
            }
        }
Пример #5
0
 /// <summary>
 /// Create a new Resource object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="resourceName">Initial value of the ResourceName property.</param>
 /// <param name="isDeleted">Initial value of the IsDeleted property.</param>
 public static Resource CreateResource(global::System.Int32 id, global::System.String resourceName, global::System.Int32 isDeleted)
 {
     Resource resource = new Resource();
     resource.ID = id;
     resource.ResourceName = resourceName;
     resource.IsDeleted = isDeleted;
     return resource;
 }