Esempio n. 1
0
        public ActionResult Download(int id, string type)
        {
            var clothes = DbContext.Clothes.SingleOrDefault(t => t.Id == id && t.IsDeleted == false);
            if (clothes == null || String.IsNullOrEmpty(type))
                return new HttpNotFoundResult();
            else
            {
                var log = new OperationLog() { Clothes = clothes, User = CurrentUser, OperationType = OperationType.DownLoadFile.ToString() };
                DbContext.OperationLogs.Add(log);
                DbContext.SaveChanges();

                var filePath = GetPathFile(clothes, type);
                if (String.IsNullOrEmpty(filePath) || filePath == "NOTFOUND") return new HttpNotFoundResult();

                if (filePath.LastIndexOf('.') > -1)
                {
                    var extenstion = filePath.Substring(filePath.LastIndexOf('.') + 1);
                    return new FilePathResult(Server.MapPath(filePath), "application/octet-strea") { FileDownloadName = String.Format("{0}{1}.{2}", clothes.SampleNO, GetDownloadFileName(type), extenstion) };
                }
                else
                {
                    return new FilePathResult(Server.MapPath(filePath), "application/octet-strea") { FileDownloadName = String.Format("{0}{1}", clothes.SampleNO, GetDownloadFileName(type)) };
                }
            }
        }
Esempio n. 2
0
        public ActionResult Detail(int id)
        {
            var clothes = DbContext.Clothes.SingleOrDefault(t => t.Id == id && t.IsDeleted == false);
            if (clothes != null)
            {
                ViewBag.CurrentClothesType = clothes.ClothesType;
                clothes.ViewCount = clothes.ViewCount + 1;

                OperationLog log = new OperationLog()
                {
                    Clothes = clothes,
                    OperationType = OperationType.ViewClothes.ToString(),
                    User = CurrentUser
                };
                DbContext.OperationLogs.Add(log);

                DbContext.SaveChanges();
                return View(clothes);
            }
            else
                return new ContentResult() { Content = "未找到相应的记录" };
        }