예제 #1
0
        internal string GetFileFolderLink(as_files item)
        {
            string res;

            res = string.Format("/uploads/images/{0}", item.itemID);
            return(res);
        }
예제 #2
0
 public int SaveFile(as_files item)
 {
     try
     {
         if (item.id == 0)
         {
             db.as_files.Add(item);
             db.SaveChanges();
         }
         else
         {
             try
             {
                 db.Entry(item).State = EntityState.Modified;
                 db.SaveChanges();
             }
             catch (OptimisticConcurrencyException ex)
             {
                 Debug.LogError(ex);
             }
         }
         CacheManager.PurgeCacheItems(GetCacheKey(item));
     }
     catch (Exception ex)
     {
         Debug.LogError(ex);
     }
     return(item.id);
 }
예제 #3
0
        internal void UploadFile(as_files item, HttpPostedFileBase file)
        {
            var folderPath = HttpContext.Current.Server.MapPath(GetFileFolderLink(item));

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            file.SaveAs(Path.Combine(folderPath, item.filename));
        }
예제 #4
0
        public ActionResult Upload()
        {
            try
            {
                var file   = HttpContext.Request.Files["Filedata"];
                var itemID = Convert.StrToInt(HttpContext.Request.Form["itemID"], 0);

                var item = new as_files
                {
                    filename = string.Format("{0}{1}", Guid.NewGuid(), Path.GetExtension(file.FileName)),
                    name     = file.FileName,
                    itemID   = itemID,
                    ord      = _mng.GetNextOrder()
                };

                _mng.SaveFile(item);
                _mng.UploadFile(item, file);
            }
            catch (Exception ex)
            {
                Debug.LogError(ex);
            }
            return(Content("0"));
        }
예제 #5
0
 private string GetCacheKey(as_files item)
 {
     return(GetCacheKey(item.itemID ?? 0));
 }