Beispiel #1
0
 public int CreateRole(MyRoles role, int[] function)
 {
     using (var scope = EFContextFactory.GetCurrentDbContext().Database.BeginTransaction())
     {
         try
         {
             foreach (var item in function)
             {
                 DataRepository.Add <RoleFunction>(new RoleFunction()
                 {
                     RoleID     = role.Id,
                     FunctionID = item,
                 });
             }
             DataRepository.Add <MyRoles>(role);
             scope.Commit();
             LogHelper.WriteLog("添加角色及权限", "1" + role.ObjectToJson());
             return(1);
         }
         catch (Exception ex)
         {
             ErrorLogHelper.WriteLog(ex);
             scope.Rollback();
             return(0);
         }
     }
 }
Beispiel #2
0
 public int EditRole(MyRoles role, int[] function)
 {
     using (var scope = EFContextFactory.GetCurrentDbContext().Database.BeginTransaction())
     {
         try
         {
             DataRepository.DB.Database.ExecuteSqlCommand("delete from rolefunction where roleid='" + role.Id + "'");
             foreach (var item in function)
             {
                 DataRepository.DB.Set <RoleFunction>().Add(new RoleFunction
                 {
                     RoleID     = role.Id,
                     FunctionID = item,
                 });
             }
             List <string> fields = new List <string>();
             fields.Add("Description");
             fields.Add("Name");
             DataRepository.UpdateSetEntityFields <MyRoles>(role, fields);
             DataRepository.DB.SaveChanges();
             scope.Commit();
             LogHelper.WriteLog("修改角色及权限", "1", function + role.ObjectToJson());
             return(1);
         }
         catch (Exception ex)
         {
             ErrorLogHelper.WriteLog(ex);
             scope.Rollback();
             return(0);
         }
     }
 }
        public ActionResult Gen(string url, string type)
        {
            //string url = Request.Url.AbsoluteUri;


            string contentType = "application/pdf";
            string ext         = ".pdf";
            string folder      = "Pdfs";
            string genExe      = "wkhtmltopdf.exe ";

            if ("image".Equals(type, StringComparison.InvariantCultureIgnoreCase))
            {
                contentType = "image/jpeg";
                ext         = ".jpg";
                folder      = "Images";
                genExe      = "wkhtmltoimage.exe ";
            }

            var rootUrl = Server.MapPath("/");

            var file = rootUrl + @"wkhtmltoX\" + genExe;

            string fName = Guid.NewGuid().ToString();

            string flileName = folder + "/" + fName + ext;

            try
            {
                List <string> list = new List <string>();
                list.Add("d:");
                list.Add("cd " + Path.GetDirectoryName(file));
                list.Add(genExe + string.Format(" {0} {1}", url, flileName));
                string result = CmdHandle.ExeCommand(list.ToArray());
                return(Content(result));
            }
            catch (Exception ex)
            {
                ErrorLogHelper.WriteLog(ex);
                return(Content("生成失败. 请多试几次..."));
            }

            if (System.IO.File.Exists(flileName))
            {
                var f = new FileStreamResult(new FileStream(flileName, FileMode.Open), contentType);
                f.FileDownloadName = fName + ext;

                return(f);
            }

            return(Content("生成失败. 请多试几次..."));
        }
Beispiel #4
0
        protected void Application_Error(object sender, EventArgs e)
        {
            Exception err = HttpContext.Current.Error;

            ErrorLogHelper.WriteLog(new LogContent()
            {
                UserName      = User.Identity.Name,
                EventCategory = "ERROR",
                Description   = err.StackTrace,
                Source        = err.Message,
                SourceUrl     = Request.Url.AbsoluteUri,
                ComputerName  = UserHelper.GetUserIp(),
                Mac_Address   = Utility.OperateHelper.GetMacAddress()
            });
        }
Beispiel #5
0
        public static int DeleteRange <T>(IEnumerable <T> ts) where T : class
        {
            try
            {
                DB.Set <T>().RemoveRange(ts);
                int result = DB.SaveChanges();

                LogHelper.WriteLog("Delete" + ts.GetType(), result.ToString() + ts.ObjectToJson());
                return(result);
            }
            catch (Exception ex)
            {
                ErrorLogHelper.WriteLog(ex);
                return(0);
            }
        }
Beispiel #6
0
        public static int Add <T>(T t) where T : class
        {
            try
            {
                DB.Set <T>().Add(t);
                int result = DB.SaveChanges();

                LogHelper.WriteLog("Add:" + t.GetType(), "结果:" + result.ToString() + ";" + t.ObjectToJson());
                return(result);
            }
            catch (Exception ex)
            {
                ErrorLogHelper.WriteLog(ex);
                return(0);
            }
        }