コード例 #1
0
 public ActionResult Index(int?type)
 {
     ViewBag.BtnList  = CommonHelper.GetBtnAuthorityForPage("服务管理");
     ViewBag.hostList = BusinessContext.ServiceList.GetHostList((ServiceTypeEnum?)type);
     ViewBag.Type     = type;
     return(View());
 }
コード例 #2
0
ファイル: Global.asax.cs プロジェクト: radtek/ServiceMonitor
        protected void Application_Start()
        {
            CommonHelper.InitBasicType();
            AreaRegistration.RegisterAllAreas();
            ConfigHelper.InitConfig <AppSetting>();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            var t = CurrentHelper.SerCfg;

            BundleTable.EnableOptimizations = true;
            //InitGroupNameCol();
        }
コード例 #3
0
        public JsonResult Upload()
        {
            var rm = new ReturnMessage(false);

            if (Request.Files.Count > 0)
            {
                var file = Request.Files[0];
                if (file != null && file.ContentLength > 0)
                {
                    var size  = file.ContentLength;
                    var md5   = CommonHelper.GetMd5HashFromFile(file);
                    var model = BusinessContext.Files.Get(Query <FileEntity> .EQ(t => t.Md5, md5));
                    if (model != null)
                    {
                        rm.Message = "文件已存在!";
                        return(Json(rm));
                    }
                    var path = AppDomain.CurrentDomain.BaseDirectory + "uploads\\";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    var filename = Path.GetFileName(file.FileName);
                    if (filename == null)
                    {
                        rm.Message = "空文件名";
                        return(Json(rm));
                    }

                    var extStart = filename.LastIndexOf(".", StringComparison.Ordinal);
                    var ext      = filename.Substring(extStart);
                    var newName  = string.Format("{0}_{1}{2}", filename.Substring(0, extStart), Guid.NewGuid(), ext);

                    try
                    {
                        var url    = Path.Combine(path, filename);
                        var entity = new FileEntity
                        {
                            Author      = CurrentHelper.UserName,
                            DateTime    = DateTime.Now,
                            FileName    = filename,
                            Md5         = md5,
                            Size        = size,
                            SecondaryId = int.Parse(Request["SecondaryId"])
                        };
                        if (global::System.IO.File.Exists(url))
                        {
                            url             = Path.Combine(path, newName);
                            entity.FileName = newName;
                        }
                        file.SaveAs(url);
                        entity.Url   = url;
                        rm.IsSuccess = BusinessContext.Files.Add(entity);
                    }
                    catch (Exception e)
                    {
                        rm.Message = e.Message;
                    }
                }
            }
            return(Json(rm));
        }