/// <summary> /// 删除一条数据 /// </summary> public string DelInfo(string id) { if (id.Length > 0) { Common_BLL pg = new Common_BLL(); Sys_MenuBLL bllMenu = new Sys_MenuBLL(); SessionUserModel userInfo = CurrUserInfo(); Workflow_TasksExBLL bll = new Workflow_TasksExBLL(); if (pg.Delete(UCEasyUIDataGrid.TableName, UCEasyUIDataGrid.TableKey, "'" + id + "'", "")) { //删除待办事项 new RoleConfig().DeleteMatterTasks(id.Replace("'", "")); string rtnUrl = Request.RawUrl; Sys_Menu MenuModel = bllMenu.FindByURL(rtnUrl); if (MenuModel != null) { if (!string.IsNullOrEmpty(MenuModel.Menu_Name)) { pg.AddLog(MenuModel.Menu_Name, id, "删除", "ID=" + id + "", userInfo.UserID, userInfo.DepartmentCode); } } return("1"); } else { return("0"); } } else { return("0"); } }
public void ModifyPassWord(HttpContext context) { string ypwd = DESEncrypt.Encrypt(HttpUtility.UrlDecode(context.Request.QueryString["ypwd"].ToString())); string pwd = HttpUtility.UrlDecode(context.Request.QueryString["pwd"].ToString()); SessionUserModel currUserInfo = context.Session["UserInfo"] as SessionUserModel; Sys_UserInfoBLL bllUserInfo = new Sys_UserInfoBLL(); List <Sys_UserInfo> userModelList = bllUserInfo.GetList(p => p.UserInfo_LoginUserName == currUserInfo.LoginUserName && p.UserInfo_LoginUserPwd == ypwd).ToList(); if (userModelList.Count > 0) { userModelList[0].UserInfo_LoginUserPwd = DESEncrypt.Encrypt(pwd); string msg = string.Empty; if (bllUserInfo.Update(userModelList[0])) { context.Response.Write("success"); } else { context.Response.Write("error_pwd"); } } else { context.Response.Write("error_pwd"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Request.ContentEncoding = Encoding.GetEncoding("UTF-8"); string method = context.Request.QueryString["method"]; try { currentUser = context.Session["UserInfo"] as SessionUserModel; } catch { context.Response.Redirect("~/Login.aspx"); } if (currentUser == null) { context.Response.Redirect("~/Login.aspx"); } if (method == "modifypwd") { ModifyPassWord(context); } if (method == "LoadMenuTree") { LoadMenuTree(context); } }
public async Task <IHttpActionResult> Login(LoginViewModel model) { model.RememberMe = false; var token = Guid.NewGuid(); var response = new SessionUserModel() { SessionToken = token }; try { var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, false); if (result == SignInStatus.Success) { var user = DbContext.Users.First(u => u.UserName.ToLower() == model.UserName.ToLower()); user.ApiSessionToken = token; await DbContext.SaveChangesAsync(); response.Avatar = user.GetProfilePictureUrl(GetBaseAddress()); response.Username = user.UserName; response.Id = user.Id; } else { throw new HttpResponseException(HttpStatusCode.Unauthorized); } } catch (Exception ex) { return(InternalServerError(ex)); } return(Ok(response)); }
/// <summary> /// 加载菜单树 /// </summary> /// <returns></returns> public string LoadMuenu() { List <Sys_Department> list = null; CurrUserInfo = new BasePage().CurrUserInfo(); list = bll.GetList(p => p.Department_IsDel == "0").OrderBy(p => p.Department_Sequence).ToList(); StringBuilder strMenu = new StringBuilder(); strMenu.Append("{\"total\":" + list.Count + ",\"rows\":["); int index = 0; foreach (Sys_Department menu in list) { index++; if (menu.Department_ParentCode == "0") { strMenu.Append("{\"id\":\"" + menu.Department_Code + "\",\"name\":\"" + menu.Department_Name + "\",\"sort\":\"" + menu.Department_Sequence + "\",\"type\":\"" + Common_BLL.GetDataDictNameByCode(menu.Department_Type) + "\",\"personCharge\":\"" + index + "\",\"teachers\":\"" + index + "\",\"students\":\"" + index + "\"},"); } else { strMenu.Append("{\"id\":\"" + menu.Department_Code + "\",\"name\":\"" + menu.Department_Name + "\",\"sort\":\"" + menu.Department_Sequence + "\",\"type\":\"" + Common_BLL.GetDataDictNameByCode(menu.Department_Type) + "\",\"personCharge\":\"" + index + "\",\"teachers\":\"" + index + "\",\"students\":\"" + index + "\",\"_parentId\":\"" + menu.Department_ParentCode + "\"}"); if (index != list.Count) { strMenu.Append(","); } } } strMenu.Append("]}"); return(strMenu.ToString()); }
public string LoadHolidy() { List <Sys_Holiday> list = null; CurrUserInfo = new BasePage().CurrUserInfo(); list = holidayBLL.GetAll().OrderBy(p => p.Holiday_UpdateTime).ToList(); //节假日管理中未考虑 Holiday_IsDelete 字段值,因此此处也不考虑 //list = holidayBLL.FindWhere(p=>p.Holiday_IsDelete ==false).OrderBy(p => p.Holiday_UpdateTime).ToList(); StringBuilder strData = new StringBuilder(); int index = 0; foreach (Sys_Holiday obj in list) { //事件开始时间 string sStartTime = Convert.ToDateTime(obj.Holiday_StartDate).ToString("yyyy-MM-dd HH:mm"); //时间结束时间 string sEndTime = Convert.ToDateTime(obj.Holiday_EndDate).ToString("yyyy-MM-dd HH:mm"); string title = obj.Holiday_Name; if (title.Length > 29) { title = title.Substring(0, 23) + "......"; } string day = Convert.ToDateTime(obj.Holiday_StartDate).ToString("yyyy-MM-dd"); DateTime sDate = Convert.ToDateTime(Convert.ToDateTime(obj.Holiday_StartDate).ToString("yyyy-MM-dd")); DateTime eDate = Convert.ToDateTime(Convert.ToDateTime(obj.Holiday_EndDate).ToString("yyyy-MM-dd")); int interval = new TimeSpan(eDate.Ticks - sDate.Ticks).Days; if (interval > 0) { for (int i = 0; i < interval; i++) { DateTime dateTemp = sDate.AddDays(i); string dayTemp = Convert.ToDateTime(dateTemp).ToString("yyyy-MM-dd"); strData.Append("<div class=\"holidy\" data-date=\"" + dayTemp + "\" data-stime=\"" + sStartTime + "\" data-etime=\"" + sEndTime + "\"data-title=\"" + title + "\"data-sid=\"" + obj.HolidayId + "\"></div>"); } string end = Convert.ToDateTime(obj.Holiday_EndDate).ToString("HH:mm"); if (end != "00:00") { DateTime dateTemp = sDate.AddDays(interval); string dayTemp = Convert.ToDateTime(dateTemp).ToString("yyyy-MM-dd"); strData.Append("<div class=\"holidy\" data-date=\"" + dayTemp + "\" data-stime=\"" + sStartTime + "\" data-etime=\"" + sEndTime + "\"data-title=\"" + title + "\"data-sid=\"" + obj.HolidayId + "\"></div>"); } } else { strData.Append("<div class=\"holidy\" data-date=\"" + day + "\" data-stime=\"" + sStartTime + "\" data-etime=\"" + sEndTime + "\"data-title=\"" + title + "\"data-sid=\"" + obj.HolidayId + "\"></div>"); } index++; } return(strData.ToString()); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { userInfo = base.CurrUserInfo(); Bind(1); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SessionUserModel userInfo = base.CurrUserInfo(); //this.HomeTime.Text = DateTimeUtil.getCurrDataToChinese(); LoginName.Text = userInfo.UserName; } }
protected void Session_End(object sender, EventArgs e) { Application.Lock(); Application["LiveSessionsCount"] = (int)Application["LiveSessionsCount"] - 1; SessionUserModel deletedModel = SessionCountHelper.SessionUserList.FirstOrDefault(x => x.SessionID == Session.SessionID); SessionCountHelper.SessionUserList.Remove(deletedModel); SessionCountHelper.SessionCount = (int)Application["LiveSessionsCount"]; Application.UnLock(); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Request.ContentEncoding = Encoding.GetEncoding("UTF-8"); try { currentUser = context.Session["UserInfo"] as SessionUserModel; } catch { context.Response.Redirect("~/UserLogin.aspx"); } if (currentUser == null) { context.Response.Redirect("~/UserLogin.aspx"); } string active = context.Request.QueryString["active"]; switch (active) { case "Tree": this.getTreeData(context); break; case "Add": this.getAddData(context); break; case "Update": this.getUpdateData(context); break; case "Delete": this.getDeleteData(context); break; case "up": this.getUpData(context); break; case "down": this.getDownData(context); break; case "sort": this.getSortData(context); break; case "OpenHistoryList": this.OpenHistoryList(context); break; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { userInfo = base.CurrUserInfo(); this.LoadPendingMatterInfo(); this.LoadInfo(); //this.LoadWarnPersonelInfo(); //Nzhsoft.Tester.WebCodeTimer.Initialize(); //Response.Write(Nzhsoft.Tester.WebCodeTimer.Time("LoadPendingMatterInfo()执行时间", 1, () => { this.LoadPendingMatterInfo(); })); } }
public static void SetHmacToken(this ISession session, string hmacToken) { try { _sessionUserModel = _sessionUserModel ?? session.Get <SessionUserModel>("CurrentUser"); _sessionUserModel.HmacToken = hmacToken; var token = _sessionUserModel.HmacToken; } catch (Exception ex) { } }
public async Task <IActionResult> BodyProp() { var user = HttpContext.Session.Get <SessionUserModel>("CurrentUser"); var ff = JsonConvert.SerializeObject(user); _distributedCache.SetString("userTestObj", JsonConvert.SerializeObject(user)); SessionUserModel model = JsonConvert.DeserializeObject <SessionUserModel>(_distributedCache.GetString("userTestObj")); var userName = model.Email; var user2 = JsonConvert.DeserializeObject <SessionUserModel>(await _distributedCache.GetStringAsync(user.ConcurrencyStamp)); var userNmae2 = user2.Email; return(View()); }
public ActionResult OnlineUserCount() { SessionUserModel activeSessionUser = SessionCountHelper.SessionUserList.FirstOrDefault(x => x.SessionID == Session.SessionID); SessionCountHelper.SessionUserList.Select(x => { x.IsActiveSession = false; return(x); }).ToList(); if (activeSessionUser != null) { activeSessionUser.IsActiveSession = true; } SessionCountHelper.SessionUserList = SessionCountHelper.SessionUserList.OrderByDescending(x => x.IsActiveSession).Take(10).ToList(); ViewData["SessionCount"] = SessionCountHelper.SessionCount; ViewData["SessionUserList"] = RazorViewToString.RenderRazorViewToString(this, "~/Views/User/_SessionUserList.cshtml", SessionCountHelper.SessionUserList); return(PartialView("~/Views/Shared/PartialLayout/_SessionCount.cshtml")); }
public static string GetUserPublicKey(this ISession session) { try { _sessionUserModel = _sessionUserModel ?? session.Get <SessionUserModel>("CurrentUser"); if (_sessionUserModel != null && !string.IsNullOrEmpty(_sessionUserModel.ConcurrencyStamp)) { return(_sessionUserModel.ConcurrencyStamp); } return(""); } catch (Exception ex) { } return(""); }
public static string GetUserPassword(this ISession session) { try { _sessionUserModel = _sessionUserModel ?? session.Get <SessionUserModel>("CurrentUser"); if (_sessionUserModel != null && !string.IsNullOrEmpty(_sessionUserModel.Password)) { return(_sessionUserModel.Password); } return(""); } catch (Exception ex) { } return(""); }
protected void Session_Start(object sender, EventArgs e) { Application.Lock(); Application["LiveSessionsCount"] = (int)Application["LiveSessionsCount"] + 1; SessionUserModel sessionUserModel = new SessionUserModel { IsMobile = Request.Browser.IsMobileDevice ? "Mobile" : "Web", IPAddress = Request.UserHostAddress, SessionID = Session.SessionID, OperatingSystem = GetUserPlatform(Request.UserAgent), CreatedTime = DateTime.Now }; SessionCountHelper.SessionUserList.Add(sessionUserModel); SessionCountHelper.SessionCount = (int)Application["LiveSessionsCount"]; Application.UnLock(); }
//[Route("en-US/Adm/Dsh")] public async Task <IActionResult> Dsh() { var user = HttpContext.Session.Get <SessionUserModel>("CurrentUser"); var ff = JsonConvert.SerializeObject(user); _distributedCache.SetString("userTestObj", JsonConvert.SerializeObject(user)); SessionUserModel model = JsonConvert.DeserializeObject <SessionUserModel>(_distributedCache.GetString("userTestObj")); var userName = model.Email; var user2 = JsonConvert.DeserializeObject <SessionUserModel>(await _distributedCache.GetStringAsync(user.ConcurrencyStamp)); var userNmae2 = user2.Email; //ViewData["Message"] = _requestCultureFinder.GetRequestCultureInfo(); return(View()); }
public async Task <ActionResult> Login(UserLoginModel model) { if (ModelState.IsValid) { AppUser user = null; user = await userManager.FindByEmailAsync(model.UserNameOrEmail); if (user == null) { user = await userManager.FindByNameAsync(model.UserNameOrEmail); } if (user != null) { PasswordVerificationResult verificationResult = passwordHasher.VerifyHashedPassword(user, user.PasswordHash, model.Password); if (PasswordVerificationResult.Success == verificationResult) { IList <string> str = await userManager.GetRolesAsync(user); SessionUserModel sessionUser = new SessionUserModel() { UserName = user.UserName, Email = user.Email, Id = user.Id, Photo = user.Photo, Role = str[0] }; HttpContext.Session.SetObjectAsJson("UserData", sessionUser); await signInManager.SignInAsync(user, true); return(RedirectToAction("AllEmployee", "Employee", new { area = "Admin" })); } else { ModelState.AddModelError("", "Password incorrect"); } } else { ModelState.AddModelError("", "UserName or Email incorrect"); } } return(View()); }
public static string GetUserName(this ISession session) { try { _sessionUserModel = _sessionUserModel ?? session.Get <SessionUserModel>("CurrentUser"); //SessionUserModel user = session.Get<SessionUserModel>("CurrentUser"); if (_sessionUserModel != null && !string.IsNullOrEmpty(_sessionUserModel.Email)) { return(_sessionUserModel.Email); } return(""); } catch (Exception ex) { } return(""); }
private void UserSesson() { string userName = HttpContext.Current.Request.Cookies["SessionUserName"].Value; View_Sys_UserInfo userInfo = new View_Sys_UserInfoBLL().Get(p => p.UserInfo_LoginUserName == userName); SessionUserModel model = new SessionUserModel(); model.UserID = userInfo.UserInfoID; model.UserName = userInfo.UserInfo_FullName; model.LoginUserName = userInfo.UserInfo_LoginUserName; model.DepartmentName = userInfo.Department_Name; model.DepartmentCode = userInfo.UserInfo_DepCode; model.PostID = userInfo.UserInfo_Post; model.PostName = userInfo.UserInfo_PostName; model.RoleID = userInfo.UserInfo_RoleID; model.RoleName = userInfo.UserInfo_RoleName; model.UserType = userInfo.UserInfo_Type; model.DepType = userInfo.Department_Type; Session["UserInfo"] = model; }
public async Task <ActionResult> Profil() { SessionUserModel sessionUser = HttpContext.Session.GetObjectFromJson <SessionUserModel>("UserData"); var data = await userManager.FindByIdAsync(sessionUser.Id); AdminModel admin = new AdminModel() { FirstName = data.FirstName, SecondName = data.SecondName, Image = data.Photo, Email = data.Email, Address = data.Adress, Birthday = data.Birth, PhoneNumber = data.PhoneNumber, Role = sessionUser.Role }; return(View(admin)); }
public static string GetHmacToken(this ISession session) { try { _sessionUserModel = _sessionUserModel ?? session.Get <SessionUserModel>("CurrentUser"); var token = _sessionUserModel.HmacToken; if (_sessionUserModel != null && !string.IsNullOrEmpty(_sessionUserModel.HmacToken)) { return(_sessionUserModel.HmacToken); } else { return(""); } } catch (Exception ex) { } return(""); }
///// <summary> ///// 通过模块菜单名称获取 有审核按钮权限的角色 ///// </summary> ///// <param name="moduleName">功能菜单名称</param> ///// <param name="buttonName">操作按钮名称</param> ///// <returns></returns> //public string GetAuditRoleByMouleName(string moduleName, string buttonName) //{ // string rtnRoleStr = string.Empty; // if (!moduleName.Equals("")) // { // List<View_PendingMatterToRolePurview> roleList = new View_PendingMatterToRolePurviewBLL().GetList(p => p.Menu_Name == moduleName && p.RolePurview_OperatePurview.Contains(buttonName)).ToList();//" Menu_Name='" + moduleName + "' and RolePurview_OperatePurview like '%" + buttonName + "%'"); // foreach (View_PendingMatterToRolePurview role in roleList) // { // rtnRoleStr += role.Role_Name + ","; // } // } // if (rtnRoleStr != "") // { // rtnRoleStr = rtnRoleStr.Substring(0, rtnRoleStr.Length - 1); // BasePage basePage = new BasePage(); // SessionUserModel CurrUser = basePage.CurrUserInfo(); // if (!string.IsNullOrEmpty(CurrUser.RoleName)) // { // string[] currUserRoleArray = CurrUser.RoleName.Split(','); // foreach (string currRole in currUserRoleArray) // { // if (rtnRoleStr.Contains(currRole)) // { // rtnRoleStr = string.Empty;//当前角色已经是 待审核角色 // break; // } // } // } // } // return rtnRoleStr; //} #endregion /// <summary> /// 增加待办事项(审核退回) /// </summary> /// <param name="moduleID">业务模块ID</param> /// <param name="moduleName">功能菜单名称</param> /// <param name="SessionUserModel">用户信息</param> /// <param name="title">待办事项标题</param> /// <param name="url">待办事项地址</param> /// <param name="toUserId">业务的操作用户</param> /// <returns></returns> public bool AddMatterTasks(string moduleID, string moduleName, SessionUserModel userInfo, string title, string url, string toUserId) { try { Sys_PendingMatter pendingMatter = new Sys_PendingMatter(); pendingMatter.PendingMatterID = Guid.NewGuid().ToString(); pendingMatter.PendingMatter_ModuleID = moduleID; pendingMatter.PendingMatter_Title = title; pendingMatter.PendingMatter_ModuleName = moduleName; pendingMatter.PendingMatter_ToRoleName = toUserId; pendingMatter.PendingMatter_URL = url; pendingMatter.PendingMatter_AddTime = DateTime.Now; pendingMatter.PendingMatter_AddUserID = userInfo.UserID; new Sys_PendingMatterBLL().Add(pendingMatter); return(true); } catch { return(false); } }
/// <summary> /// 增加待办事项 /// </summary> /// <param name="moduleID">业务模块ID</param> /// <param name="moduleName">业务模块名称</param> /// <param name="SessionUserModel">用户信息</param> /// <param name="tasksInstanceID">工作流程ID</param> /// <param name="step">工作流程步骤(这里指当前步骤)</param> /// <param name="title">待办事项标题</param> /// <param name="url">待办事项地址</param> /// <returns></returns> public bool AddMatterTasks(string moduleID, string moduleName, SessionUserModel userInfo, string tasksInstanceID, int step, string title, string url) { try { string toRoleName = GetWorkFlowAuditObject(tasksInstanceID, step); if (!toRoleName.Equals("")) { string[] roleArray = toRoleName.Split(','); List <Sys_PendingMatter> pendingMatterList = new List <Sys_PendingMatter>(); foreach (string role in roleArray)//多角色 { if (role != "") { Sys_PendingMatter pendingMatter = new Sys_PendingMatter(); pendingMatter.PendingMatterID = Guid.NewGuid().ToString(); pendingMatter.PendingMatter_ModuleID = moduleID; pendingMatter.PendingMatter_Title = title; pendingMatter.PendingMatter_ModuleName = moduleName; pendingMatter.PendingMatter_ToRoleName = role; pendingMatter.PendingMatter_URL = url; pendingMatter.PendingMatter_AddTime = DateTime.Now; pendingMatter.PendingMatter_AddUserID = userInfo.UserID; pendingMatterList.Add(pendingMatter); } } if (pendingMatterList.Count > 0) { this.DeleteMatterTasks(moduleID);//先删除 string msg = string.Empty; new Sys_PendingMatterBLL().Add(pendingMatterList); } } return(true); } catch { return(false); } }
public async Task Invoke(HttpContext context, SessionUserModel sessionUserModel) { _sessionUserModel = sessionUserModel; var headerList = context.Request.Headers.ToList(); var xPublic = headerList.Where(x => x.Key == "X-PublicKey").FirstOrDefault(); if (!string.IsNullOrEmpty(xPublic.Value)) { var publicKey = context.Items["PublicKey"].ToString(); if (!string.IsNullOrEmpty(publicKey)) { var userTestObj = _distributedCache.GetString(publicKey); _sessionUserModel = JsonConvert.DeserializeObject <SessionUserModel>(userTestObj); if (_sessionUserModel != null) { context.Items["MiyaUser"] = _sessionUserModel; context.Items["MiyaUserName"] = _sessionUserModel.Email; context.Items["MiyaUserPassword"] = _sessionUserModel.Password; context.Items["PrivateKey"] = _sessionUserModel.SecurityStamp; context.Items["UserAgent"] = _sessionUserModel.UserAgent; } var dene = _sessionUserModel.Email; await _next(context); } else { context.Response.StatusCode = 503; context.Response.ContentType = "application/json"; using (StreamWriter writer = new StreamWriter(context.Response.Body)) { await writer.WriteLineAsync("{Message : 'User Not Found Due To Public Key'}"); }; } } else { //await _next(context); } }
/// <summary> /// 附件添加 /// </summary> /// <param name="context"></param> public void FilseAdd(HttpContext context) { string OperationID = context.Request.QueryString["OperationID"]; //业务ID string SessionID = context.Request.QueryString["SessionID"]; //SessionID string FileType = context.Request.QueryString["FileType"]; //附件的类型 SessionUserModel currentUser = context.Session["UserInfo"] as SessionUserModel; string pt = context.Request["Filename"].ToString(); HttpPostedFile postedFile = context.Request.Files["Filedata"]; //获取上传信息对象 string filename = postedFile.FileName; //获取上传的文件 名字 string tempPath = FileType == "系统必备工具" ? "/Download/" : UploadFileCommon.CreateDir("File"); //获取保存文件夹路径。 string savepath = context.Server.MapPath(tempPath); //获取保存路径 string sExtension = filename.Substring(filename.LastIndexOf('.')); //获取拓展名 int fileLength = postedFile.ContentLength; //获取文件大小 string fileContentLength = fileSizs(postedFile.ContentLength); //转换成MB,GB,TB if (!Directory.Exists(savepath)) //查看当前文件夹是否存在 { Directory.CreateDirectory(savepath); } //string sNewFileName = DESEncrypt.Encrypt(DateTime.Now.ToString("yyyyMMddhhmmsfff"));//上传后的文件名字 string sNewFileName = Guid.NewGuid().ToString(); if (OperationID != "" && SessionID != "" && OperationID != null) { List <Sys_ModelFile> ModelFilelist = null; if (context.Session[SessionID] == null) { ModelFilelist = new List <Sys_ModelFile>(); } else { ModelFilelist = context.Session[SessionID] as List <Sys_ModelFile>; } Sys_ModelFile model = new Sys_ModelFile(); model.FileID = Guid.NewGuid().ToString(); model.File_Name = filename; model.File_Extension = sExtension; model.File_Size = fileLength; model.File_Path = tempPath + sNewFileName + sExtension; model.File_AddTime = DateTime.Now; model.File_OperationID = OperationID; model.File_UserID = currentUser.UserID; model.File_Type = FileType; try { //postedFile.SaveAs(savepath + "@/" + sNewFileName + sExtension);//保存 postedFile.SaveAs(savepath + sNewFileName + sExtension);//保存 postedFile = null; ModelFilelist.Add(model); context.Session[SessionID] = ModelFilelist; string fileUrl = "/Files/Download.aspx?path=" + model.File_Path + "&filename=" + model.File_Name; context.Response.Write("{filadd:'true',id:'" + model.FileID + "',filename:'" + model.File_Name + "',filesize:'" + fileContentLength + "',uploaddate:'" + Convert.ToDateTime(model.File_AddTime).ToString("yyyy年MM月dd日") + "',fileUrl:'" + fileUrl + "',filePicUrl:'" + model.File_Path + "'}"); } catch { context.Response.Write("{filadd:'false',filename:'" + model.File_Name + "'}"); } } else { context.Response.Write("{filadd:'false',filename:'" + filename + "'}");//在没有业务ID时候,SessionID不能为空 } //context.Response.End(); }
/// <summary> /// 背景图片添加 /// </summary> /// <param name="context"></param> public void FilseAddbeijing(HttpContext context) { SessionUserModel currentUser = context.Session["UserInfo"] as SessionUserModel; string pt = context.Request["Filename"].ToString(); HttpPostedFile postedFile = context.Request.Files["Filedata"]; //获取上传信息对象 string filename = postedFile.FileName; //获取上传的文件 名字 string tempPath = "/Styles/login/beijing/"; //获取保存文件夹路径。 string savepath = context.Server.MapPath(tempPath); //获取保存路径 string sExtension = filename.Substring(filename.LastIndexOf('.')); //获取拓展名 int fileLength = postedFile.ContentLength; //获取文件大小 string fileContentLength = fileSizs(postedFile.ContentLength); //转换成MB,GB,TB if (!Directory.Exists(savepath)) //查看当前文件夹是否存在 { Directory.CreateDirectory(savepath); } //string sNewFileName = DESEncrypt.Encrypt(DateTime.Now.ToString("yyyyMMddhhmmsfff"));//上传后的文件名字 string sNewFileName = Guid.NewGuid().ToString(); string OperationID = context.Request.QueryString["OperationID"]; //业务ID string SessionID = context.Request.QueryString["SessionID"]; //SessionID string FileType = context.Request.QueryString["FileType"]; //附件的类型 if (OperationID != "" && SessionID != "" && OperationID != null) { List <Sys_ModelFile> ModelFilelist = null; if (context.Session[SessionID] == null) { ModelFilelist = new List <Sys_ModelFile>(); } else { ModelFilelist = context.Session[SessionID] as List <Sys_ModelFile>; } Sys_ModelFile model = new Sys_ModelFile(); model.FileID = Guid.NewGuid().ToString(); model.File_Name = filename; model.File_Extension = sExtension; model.File_Size = fileLength; model.File_Path = tempPath + sNewFileName + sExtension; model.File_AddTime = DateTime.Now; model.File_OperationID = OperationID; model.File_UserID = currentUser.UserID; model.File_Type = FileType; try { //postedFile.SaveAs(savepath + "@/" + sNewFileName + sExtension);//保存 postedFile.SaveAs(savepath + sNewFileName + sExtension);//保存 string url = tempPath + sNewFileName + sExtension; postedFile = null; System.Drawing.Image pic = System.Drawing.Image.FromFile(savepath + sNewFileName + sExtension); //strFilePath是该图片的绝对路径 int intWidth = pic.Width; //长度像素值 int intHeight = pic.Height; //高度像素值 if (FileType == "登陆背景图片") { if (intWidth == 1920 && intHeight == 1080) { ModelFilelist.Add(model); context.Session[SessionID] = ModelFilelist; string fileUrl = "/Files/Download.aspx?path=" + model.File_Path + "&filename=" + model.File_Name; pic.Dispose(); context.Response.Write("{filadd:'true',url:'" + url + "',id:'" + model.FileID + "',filename:'" + model.File_Name + "',filesize:'" + fileContentLength + "',uploaddate:'" + Convert.ToDateTime(model.File_AddTime).ToString("yyyy年MM月dd日") + "',fileUrl:'" + fileUrl + "'}"); } else { pic.Dispose(); File.Delete(HttpContext.Current.Server.MapPath(model.File_Path)); context.Response.Write("{filadd:'false',name:'2',filename:'请上传分辨率为1920*1080的图片'}"); } } else if (FileType == "主框架LOGO背景图片") { if (intWidth == 417 && intHeight == 50) { ModelFilelist.Add(model); context.Session[SessionID] = ModelFilelist; string fileUrl = "/Files/Download.aspx?path=" + model.File_Path + "&filename=" + model.File_Name; pic.Dispose(); context.Response.Write("{filadd:'true',url:'" + url + "',id:'" + model.FileID + "',filename:'" + model.File_Name + "',filesize:'" + fileContentLength + "',uploaddate:'" + Convert.ToDateTime(model.File_AddTime).ToString("yyyy年MM月dd日") + "',fileUrl:'" + fileUrl + "'}"); } else { pic.Dispose(); File.Delete(HttpContext.Current.Server.MapPath(model.File_Path)); context.Response.Write("{filadd:'false',name:'2',filename:'请上传分辨率为417*50的图片'}"); } } } catch { context.Response.Write("{filadd:'false',name:'1',filename:'" + model.File_Name + "'}"); } } else { context.Response.Write("{filadd:'false',name:'1',filename:'" + filename + "'}");//在没有业务ID时候,SessionID不能为空 } //context.Response.End(); }
public void DataFilseAdd(HttpContext context) { SessionUserModel currentUser = context.Session["UserInfo"] as SessionUserModel; string pt = context.Request["Filename"].ToString(); HttpPostedFile postedFile = context.Request.Files["Filedata"]; //获取上传信息对象 string filename = postedFile.FileName; //获取上传的文件 名字 string tempPath = UploadFileCommon.CreateDir("File"); //获取保存文件夹路径。 string savepath = context.Server.MapPath(tempPath); //获取保存路径 string sExtension = filename.Substring(filename.LastIndexOf('.')); //获取拓展名 int fileLength = postedFile.ContentLength; //获取文件大小 string fileContentLength = fileSizs(postedFile.ContentLength); //转换成MB,GB,TB if (!Directory.Exists(savepath)) //查看当前文件夹是否存在 { Directory.CreateDirectory(savepath); } //string sNewFileName =DESEncrypt.Encrypt(DateTime.Now.ToString("yyyyMMddhhmmsfff"));//上传后的文件名字 string sNewFileName = Guid.NewGuid().ToString(); string OperationID = context.Request.QueryString["OperationID"]; //业务ID string SessionID = context.Request.QueryString["SessionID"]; //SessionID string FileType = context.Request.QueryString["FileType"]; //附件的类型 if (!string.IsNullOrEmpty(FileType)) { FileType = "未归类"; } //if (!filename.Contains("-")) //{ // FileType = context.Request.QueryString["FileType"];//附件的类型 // if (!string.IsNullOrEmpty(FileType)) // { // FileType = HttpUtility.UrlDecode(FileType); // } //} //else //{ // string[] fname = filename.Split('-'); // if (fname.Count() > 0) // { // FileType = fname[0]; // } // else // { // FileType = context.Request.QueryString["FileType"];//附件的类型 // if (!string.IsNullOrEmpty(FileType)) // { // FileType = HttpUtility.UrlDecode(FileType); // } // } //} //string types = context.Request.QueryString["FileType2"];//当前选中的类别节点 //if (!string.IsNullOrEmpty(types)) //{ // types = HttpUtility.UrlDecode(types); //} if (OperationID != "" && SessionID != "" && OperationID != null) { List <Sys_ModelFile> ModelFilelist = null; if (context.Session[SessionID] == null) { ModelFilelist = new List <Sys_ModelFile>(); } else { ModelFilelist = context.Session[SessionID] as List <Sys_ModelFile>; } Sys_ModelFile model = new Sys_ModelFile(); model.FileID = Guid.NewGuid().ToString(); model.File_Name = filename; model.File_Extension = sExtension; model.File_Size = fileLength; model.File_Path = tempPath + sNewFileName + sExtension; model.File_AddTime = DateTime.Now; model.File_OperationID = OperationID; model.File_UserID = currentUser.UserID; model.File_Type = FileType; string hz = ""; Regex r = new Regex(@"[\u4e00-\u9fa5]+"); Match mc1 = r.Match(FileType); if (mc1.Length != 0) //类别中含有汉字 { hz = "..(未归类)"; } try { postedFile.SaveAs(savepath + sNewFileName + sExtension);//保存 postedFile = null; ModelFilelist.Add(model); context.Session[SessionID] = ModelFilelist; string filename2 = model.File_Name; if (filename2.Length > 9) { Match mc = r.Match(filename2); if (mc.Length != 0) //名称中含有汉字 { filename2 = filename2.Substring(0, 7) + hz; } else { filename2 = filename2.Substring(0, 9) + hz; } } else { filename2 = filename2 + hz; } context.Response.Write("{filadd:'true',id:'" + model.FileID + "',filename:'" + model.File_Name + "',filesize:'" + fileContentLength + "',uploaddate:'" + Convert.ToDateTime(model.File_AddTime).ToString("yyyy年MM月dd日") + "',fileUrl:'" + model.File_Path + "',filetitle:'" + filename2 + "'}"); } catch { context.Response.Write("{filadd:'false',filename:'" + model.File_Name + "'}"); } } else { context.Response.Write("{filadd:'false',filename:'" + filename + "'}");//在没有业务ID时候,SessionID不能为空 } //context.Response.End(); }
public async Task <ActionResult> Edit(AdminModel adminModel, IFormFile Image) { SessionUserModel sessionUser = HttpContext.Session.GetObjectFromJson <SessionUserModel>("UserData"); AppUser user = userManager.Users.Where(x => x.Id == sessionUser.Id).First(); user.PhoneNumber = adminModel.PhoneNumber; user.FirstName = adminModel.FirstName; user.SecondName = adminModel.SecondName; user.Birth = adminModel.Birthday.ToUniversalTime(); user.Adress = adminModel.Address; if (ModelState.IsValid) { if (adminModel.OldPassword != null) { IList <string> str = await userManager.GetRolesAsync(user); PasswordVerificationResult result = passwordHasher.VerifyHashedPassword(user, user.PasswordHash, adminModel.OldPassword); if (PasswordVerificationResult.Success == result) { if (Image != null) { if (Image.IsFilePhotoFormat()) { string fullPath = hostingEnvironment.GetFolder(); string format = Image.GetFileFormat(); string fileName = nameGenerator.GetFileName(format); string fullFilePath = Path.Combine(fullPath, fileName); await Image.SaveFileAsync(fullFilePath); user.Photo = fileName; ImageRemove.PhotoPathDelete(user.Photo, fullPath); if (adminModel.NewPassword == null) { ModelState.AddModelError("", "New Password empty"); } else { user.PasswordHash = passwordHasher.HashPassword(user, adminModel.NewPassword); SessionUserModel session = new SessionUserModel() { Id = user.Id, UserName = user.UserName, Email = user.Email, Photo = fileName, Role = str[0] }; HttpContext.Session.SetObjectAsJson("UserData", session); payrollDb.Update <AppUser>(user); await payrollDb.SaveChangesAsync(); ModelState.AddModelError("", "Succes"); } } else { ModelState.AddModelError("", "Photo is not Format and format (jpg,png)"); } } else { if (adminModel.NewPassword == null) { ModelState.AddModelError("", "New Password empty"); } else { user.PasswordHash = passwordHasher.HashPassword(user, adminModel.NewPassword); SessionUserModel session = new SessionUserModel() { Id = user.Id, UserName = user.UserName, Email = user.Email, Photo = user.Photo, Role = str[0] }; HttpContext.Session.SetObjectAsJson("UserData", session); payrollDb.Update <AppUser>(user); await payrollDb.SaveChangesAsync(); ModelState.AddModelError("", "Succes"); } } } else { ModelState.AddModelError("", "Old Password Incorrect"); } } else { IList <string> str = await userManager.GetRolesAsync(user); if (Image != null) { if (Image.IsFilePhotoFormat()) { string fullPath = hostingEnvironment.GetFolder(); string format = Image.GetFileFormat(); string fileName = nameGenerator.GetFileName(format); string fullFilePath = Path.Combine(fullPath, fileName); ImageRemove.PhotoPathDelete(user.Photo, fullPath); await Image.SaveFileAsync(fullFilePath); user.Photo = fileName; SessionUserModel session = new SessionUserModel() { Id = user.Id, UserName = user.UserName, Email = user.Email, Photo = fileName, Role = str[0] }; HttpContext.Session.SetObjectAsJson("UserData", session); payrollDb.Update <AppUser>(user); await payrollDb.SaveChangesAsync(); ModelState.AddModelError("", "Succes"); } else { ModelState.AddModelError("", "Photo is not Format and format (jpg,png)"); } } else { SessionUserModel session = new SessionUserModel() { Id = user.Id, UserName = user.UserName, Email = user.Email, Photo = user.Photo, Role = str[0] }; HttpContext.Session.SetObjectAsJson("UserData", session); payrollDb.Update <AppUser>(user); await payrollDb.SaveChangesAsync(); ModelState.AddModelError("", "Succes"); } } } return(View(adminModel)); }