Esempio n. 1
0
 public ActionResult Create(UpdateLogViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (string.IsNullOrWhiteSpace(model.Content))
         {
             ModelState.AddModelError("Content", "填写更新内容");
         }
         if (string.IsNullOrWhiteSpace(model.Ver))
         {
             ModelState.AddModelError("Ver", "填写版本号");
         }
         if (model.Type == Enums.UpdateLogType.Android)
         {
             if (model.FileUpload.Images.Count() <= 0)
             {
                 ModelState.AddModelError("Url", "上传文件");
             }
         }
         else
         {
             if (string.IsNullOrWhiteSpace(model.Url))
             {
                 ModelState.AddModelError("Url", "下载链接");
             }
         }
         if (ModelState.IsValid)
         {
             var updateLog = new UpdateLog()
             {
                 Content        = model.Content,
                 CreateDateTime = model.CreateDateTime,
                 Type           = model.Type,
                 Ver            = model.Ver,
                 Url            = model.Url,
             };
             if (model.Type == Enums.UpdateLogType.Android)
             {
                 updateLog.Url = model.FileUpload.Images.First();
             }
             db.UpdateLogs.Add(updateLog);
             db.SaveChanges();
             string sourceFile = Server.MapPath($"{updateLog.Url}");
             string destFile   = Server.MapPath($"~/download/malieme.apk");
             System.IO.File.Copy(sourceFile, destFile, true);
             return(RedirectToAction("Index"));
         }
     }
     return(View(model));
 }
Esempio n. 2
0
        public ActionResult Create()
        {
            Sidebar();
            var model = new UpdateLogViewModel()
            {
                FileUpload = new FileUpload()
                {
                    FilePath    = "~/download/hisver",
                    IsResetName = true,
                    Name        = "AndroidUrl",
                    Type        = FileType.File,
                },
                CreateDateTime = DateTime.Now,
                Type           = Enums.UpdateLogType.Android,
            };

            return(View(model));
        }