public JsonResult LogChange(string storeId) { using (var db = new DBContext()) { Guser user = UserContext.user; List <Store> stores = db.Store.Where(q => q.UserId.Equals(user.ID)).OrderBy(q => q.StoreCode).ToList(); if (stores.Count > 0) { Store selectStore = stores.Where(q => q.ID.Equals(storeId)).FirstOrDefault(); if (selectStore == null) { return(Json(new { code = -1, msg = "找不到对应分店" })); } UserContext.store = selectStore; stores.Remove(selectStore); UserContext.stores = stores; string returnUrl = GetFirstMenu(MenuContext.menus, Convert.ToInt32(UserContext.user.Role.RoleVal)); return(Json(new { code = 1, url = returnUrl })); } return(Json(new { code = -2, msg = "账户存在异常,请重新登录" })); } }
public JsonResult Edit(Department dept) { Department oldDept = _context.Department.Where(q => q.ID.Equals(dept.ID)).FirstOrDefault(); if (oldDept == null) { Guser user = HttpContext.Session.Get <Guser>("SESSION-ACCOUNT-KEY"); dept.Creator = user.DisplayName; dept.CreatorID = user.ID; dept.Status = Status.enable; _context.Department.Add(dept); } else { oldDept.ModifyTime = DateTime.Now; oldDept.Name = dept.Name; //只有部门的编号可以修改 if (!string.IsNullOrEmpty(oldDept.ParentID)) { oldDept.Code = dept.Code; } oldDept.Status = dept.Status; _context.Entry(oldDept).State = EntityState.Modified; } _context.SaveChanges(); return(Json(new { code = 1, msg = "保存成功" })); }
public object queryDialog(string userId) { using (DBContext db = new DBContext()) { ViewBag.roles = db.GuserRole.Select(q => new SelectListItem { Text = q.RoleName, Value = q.ID }).ToList(); if (!string.IsNullOrEmpty(userId)) { Guser user = db.Guser.Where(q => q.ID.Equals(userId)).FirstOrDefault(); if (user == null) { return(Json(new { code = -1, msg = "找不到指定用户" })); } ViewBag.user = user; return(PartialView("Edit")); } return(PartialView("Add")); } }
public JsonResult editCourier(Courier courier) { using (DBContext db = new DBContext()) { Courier oldCourier = db.Courier.Where(q => q.ID.Equals(courier.ID)).FirstOrDefault(); if (oldCourier == null) { Guser user = UserContext.user; Store store = UserContext.store; courier.CreatorID = user.ID; courier.Creator = user.DisplayName; courier.StoreId = store.ID; courier.Status = Status.enable; db.Courier.Add(courier); } else { oldCourier.ModifyTime = DateTime.Now; oldCourier.CourierTel = courier.CourierTel; oldCourier.Status = courier.Status; db.Entry(oldCourier).State = EntityState.Modified; } db.SaveChanges(); } return(Json(new { code = 1, msg = "保存成功" })); }
public JsonResult Edit(Cabinet cabinet) { Cabinet oldCab = _context.Cabinet.Where(q => q.ID.Equals(cabinet.ID)).FirstOrDefault(); if (oldCab == null) { Guser user = HttpContext.Session.Get <Guser>("SESSION-ACCOUNT-KEY"); cabinet.CreatorID = user.ID; cabinet.Creator = user.DisplayName; cabinet.Status = Status.enable; _context.Cabinet.Add(cabinet); } else { oldCab.ModifyTime = DateTime.Now; oldCab.StationCode = oldCab.StationCode; oldCab.Name = cabinet.Name; oldCab.Sort = cabinet.Sort; //oldCab.Status = cabinet.Status; _context.Entry(oldCab).State = EntityState.Modified; } _context.SaveChanges(); return(Json(new { code = 1, msg = "保存成功" })); }
public JsonResult Measure(string stationCode) { Guser user = HttpContext.Session.Get <Guser>("SESSION-ACCOUNT-KEY"); if (!(user.Roles.Equals("Administrator") || user.Roles.Equals("Operator"))) { return(Json(new { code = -1, msg = "只有管理员或者操作人员可以遥控设备" })); } Operate operate = _context.Operate.Where(q => q.ClientCode.Equals(stationCode) && q.FunctionCode.Equals("B0") && (q.State == OperateState.Before || q.State == OperateState.Sended)).FirstOrDefault(); if (operate != null) { return(Json(new { code = 1, msg = "命令已下发" })); } operate = new Operate() { ClientCode = stationCode, FunctionCode = "B0" }; _context.Operate.Add(operate); _context.SaveChanges(); return(Json(new { code = 1, msg = "命令已下发" })); }
public JsonResult Edit(Guser user) { Guser oldUser = _context.Guser.Where(q => q.ID.Equals(user.ID)).FirstOrDefault(); if (oldUser == null) { Guser currentUser = HttpContext.Session.Get <Guser>("SESSION-ACCOUNT-KEY"); user.PassWord = StringUtil.Md5Encrypt(user.PassWord); user.CreatorID = currentUser.ID; user.Creator = currentUser.DisplayName; user.Status = Status.enable; _context.Guser.Add(user); } else { oldUser.DisplayName = user.DisplayName; oldUser.Tel = user.Tel; oldUser.ModifyTime = DateTime.Now; oldUser.Status = user.Status; oldUser.DeptID = user.DeptID; oldUser.Roles = user.Roles; _context.Entry(oldUser).State = EntityState.Modified; } _context.SaveChanges(); return(Json(new { code = 1, msg = "保存成功" })); }
public object Dialog(string userID) { ViewBag.userDept = HttpContext.Session.Get <Department>("SESSION-DEPARTMENT-KEY"); if (!string.IsNullOrEmpty(userID)) { Guser account = _context.Guser.Where(q => q.ID.Equals(userID)).FirstOrDefault(); if (account == null) { return(Json(new { code = -1, msg = "该用户不存在" })); } Dictionary <string, string> roles = _memoryCache.Get <Dictionary <string, string> >("Roles"); ViewBag.account = account; Department depart = string.IsNullOrEmpty(account.DeptID) ? new Department() : _context.Department.Where(q => q.ID.Equals(account.DeptID)).FirstOrDefault(); ViewBag.Dept = depart; ViewBag.Dw = string.IsNullOrEmpty(depart.ParentID) ? new Department() : _context.Department.Where(q => q.ID.Equals(depart.ParentID)).FirstOrDefault(); ViewBag.RoleName = !string.IsNullOrEmpty(account.Roles) && roles.Keys.Contains(account.Roles) ? roles[account.Roles] : string.Empty; return(PartialView("Edit")); } return(PartialView("Add")); }
public ActionResult Index() { HttpRequest request = System.Web.HttpContext.Current.Request; HttpCookie cookie = request.Cookies["session-cookie-name"]; if (cookie == null) { return(View()); } string cookieAccountId = cookie["cookie-account-id-key"]; if (string.IsNullOrEmpty(cookieAccountId)) { cookie.Expires = DateTime.Now.AddDays(-1); System.Web.HttpContext.Current.Response.Cookies.Add(cookie); return(View()); } using (var db = new DBContext()) { Guser user = db.Guser.Include("Role").Where(q => q.ID.Equals(cookieAccountId)).FirstOrDefault(); if (user == null || user.Status == Status.disable || Convert.ToInt32(user.Role.RoleVal) == 0) { cookie.Expires = DateTime.Now.AddDays(-1); System.Web.HttpContext.Current.Response.Cookies.Add(cookie); return(View()); } UserContext.user = user; List <Store> stores = db.Store.Where(q => q.UserId.Equals(user.ID)).OrderBy(q => q.StoreCode).ToList(); if (stores.Count > 0) { Store selectStore = stores[0]; UserContext.store = selectStore; stores.RemoveAt(0); UserContext.stores = stores; } List <Menu> menus = XmlHelper.XmlDeserializeFromFile <List <Menu> >(Server.MapPath("~/route.config"), Encoding.UTF8); MenuContext.menus = menus; string url = GetFirstMenu(menus, Convert.ToInt32(user.Role.RoleVal)); return(RedirectToAction("Index", url)); } }
public ActionResult addOrder() { Guser user = UserContext.user; Store store = UserContext.store; if (store == null) { return(null); } using (DBContext db = new DBContext()) { DateTime now = DateTime.Now; string code = db.Order.Where(q => q.StoreId.Equals(store.ID)).Max(q => q.OrderCode); string start = string.Format("{0}{1}", store.StoreCode, now.ToString("yyMMdd")); if (code == null || !code.StartsWith(start)) { code = string.Format("{0}{1}00", store.StoreCode, now.ToString("yyMMdd")); } else { int num = Convert.ToInt16(code.Substring(start.Length)) + 1; if (num > 99) { return(null); } string numStr = num > 9 ? num.ToString() : "0" + num; code = start + numStr; } Order order = new Order() { Creator = user.DisplayName, CreatorID = user.ID, OrderCode = code, StoreId = store.ID, StoreName = store.StoreName, Tel = user.Tel, Status = OrderStatus.BeforeSubmit, SubmitTime = now }; db.Order.Add(order); db.SaveChanges(); return(RedirectToAction("Index", "OrderEdit", new { orderId = order.ID })); } }
public JsonResult Edit(Station station) { Station sameCode = _context.Station.Where(q => q.Code.Equals(station.Code) && !q.ID.Equals(station.ID)).FirstOrDefault(); if (sameCode != null) { return(Json(new { code = -1, msg = "已存在相同编号的环网柜" })); } Department department = HttpContext.Session.Get <Department>("SESSION-DEPARTMENT-KEY"); Station oldStat = _context.Station.Where(q => q.ID.Equals(station.ID)).FirstOrDefault(); if (oldStat == null) { Guser user = HttpContext.Session.Get <Guser>("SESSION-ACCOUNT-KEY"); if (department != null) { station.DeptID = department.ID; } station.CreatorID = user.ID; station.Creator = user.DisplayName; station.Status = Status.enable; _context.Station.Add(station); } else { if (department == null) { oldStat.DeptID = station.DeptID; } oldStat.ModifyTime = DateTime.Now; oldStat.Name = station.Name; oldStat.Province = station.Province; oldStat.City = station.City; oldStat.Country = station.Country; oldStat.CityCode = station.CityCode; oldStat.Address = station.Address; oldStat.Lat = station.Lat; oldStat.Lng = station.Lng; oldStat.Status = station.Status; _context.Entry(oldStat).State = EntityState.Modified; } _context.SaveChanges(); return(Json(new { code = 1, msg = "保存成功" })); }
public async Task <IViewComponentResult> InvokeAsync() { await Task.Run(() => { }); List <Pmenu> menus = new List <Pmenu>(); Guser user = HttpContext.Session.Get <Guser>("SESSION-ACCOUNT-KEY"); if (user == null || string.IsNullOrWhiteSpace(user.Roles)) { return(View(menus)); } string currentRole = user.Roles.ToLower(); XDocument xml = XDocument.Load(_host.ContentRootPath + "/Xmls/Menus.xml"); if (!string.IsNullOrWhiteSpace(currentRole) && xml != null && xml.Nodes().Count() > 0) { foreach (XElement element in xml.Root.Elements("menu").ToList()) { string eRole = element.Attribute("roles").Value; if (string.IsNullOrWhiteSpace(eRole) || eRole.ToLower().Split(',').Contains(currentRole)) { Pmenu menu = new Pmenu(); menu.Name = element.Element("name").Value; menu.Href = element.Element("href").Value; menu.Iclass = element.Element("iclass").Value; XElement subEle = element.Element("subMenus"); if (subEle != null && subEle.Nodes().Count() > 0) { menu.SubMenuStyle = subEle.Element("style").Value; menu.SubMenus = new Dictionary <string, string>(); ArrayList subMenus = new ArrayList(); foreach (XElement child in subEle.Elements("subMenu").ToList()) { string cRole = child.Attribute("roles").Value; if (string.IsNullOrWhiteSpace(cRole) || cRole.ToLower().Split(',').Contains(currentRole)) { menu.SubMenus.Add(child.Element("name").Value, child.Element("href").Value); } } } menus.Add(menu); } } } return(View(menus)); }
public JsonResult Delete(string userID) { Guser account = _context.Guser.Where(q => q.ID.Equals(userID)).FirstOrDefault(); if (account == null) { return(Json(new { code = -1, msg = "您要删除的用户不存在" })); } _context.Guser.Remove(account); _context.SaveChanges(); return(Json(new { code = 1, msg = "操作成功" })); }
public JsonResult Password(string oldPassWord, string newPassWord) { Guser user = HttpContext.Session.Get <Guser>("SESSION-ACCOUNT-KEY"); if (!user.PassWord.Equals(StringUtil.Md5Encrypt(oldPassWord))) { return(Json(new { code = -1, msg = "原密码错误,修改密码失败" })); } user.PassWord = StringUtil.Md5Encrypt(newPassWord); _context.Entry(user).State = EntityState.Modified; _context.SaveChanges(); return(Json(new { code = 1, msg = "保存成功" })); }
public JsonResult Command(string stationCode, string functionCode, DeviceOperate operate) { Guser user = HttpContext.Session.Get <Guser>("SESSION-ACCOUNT-KEY"); if (!(user.Roles.Equals("Administrator") || user.Roles.Equals("Operator"))) { return(Json(new { code = -1, msg = "只有管理员或者操作人员可以遥控设备" })); } Operate parent = _context.Operate.Where(q => q.ClientCode.Equals(stationCode) && q.FunctionCode.Equals(functionCode) && q.State == OperateState.Before).FirstOrDefault(); if (parent == null) { parent = new Operate { ClientCode = stationCode, FunctionCode = functionCode }; _context.Operate.Add(parent); DeviceOperate newOperate = new DeviceOperate(parent.ID, operate); _context.DeviceOperate.Add(newOperate); } else { DeviceOperate oldOperate = _context.DeviceOperate.Where(q => q.OperateID.Equals(parent.ID) && q.DeviceCode.Equals(operate.DeviceCode)).FirstOrDefault(); if (oldOperate == null) { DeviceOperate newOperate = new DeviceOperate(parent.ID, operate); _context.DeviceOperate.Add(newOperate); } else { oldOperate.Update(operate); _context.Entry(oldOperate).State = EntityState.Modified; } } _context.SaveChanges(); return(Json(new { code = 1, msg = "命令已下发" })); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { Guser user = HttpContext.Session.Get<Guser>("SESSION-ACCOUNT-KEY"); if (user == null) { if (Request.Headers["X-Requested-With"] == "XMLHttpRequest") { filterContext.Result = new StatusCodeResult(499); } else { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Login", action = "Index" })); } } base.OnActionExecuting(filterContext); }
public JsonResult deleteUser(string userId) { using (DBContext db = new DBContext()) { Guser user = db.Guser.Where(q => q.ID.Equals(userId)).FirstOrDefault(); if (user == null) { return(Json(new { code = -1, msg = "您要删除的用户不存在" })); } db.Guser.Remove(user); db.SaveChanges(); return(Json(new { code = 1, msg = "删除成功" })); } }
public JsonResult editUser(Guser user) { using (DBContext db = new DBContext()) { //判断编号是否重复 Guser sameAccount = db.Guser.Where(q => q.Account.Equals(user.Account) && !q.ID.Equals(user.ID)).FirstOrDefault(); if (sameAccount != null) { return(Json(new { code = -1, msg = "用户编号已被注册" })); } Guser oldUser = db.Guser.Where(q => q.ID.Equals(user.ID)).FirstOrDefault(); if (oldUser == null) { user.CreatorID = UserContext.user.ID; user.Creator = UserContext.user.DisplayName; user.Name = user.DisplayName; user.PassWord = StringUtil.Md5Encrypt("888"); user.Status = Status.enable; db.Guser.Add(user); } else { oldUser.ModifyTime = DateTime.Now; oldUser.CardNumber = user.CardNumber; oldUser.Name = user.DisplayName; oldUser.RoleId = user.RoleId; oldUser.Sex = user.Sex; oldUser.Tel = user.Tel; oldUser.Status = user.Status; db.Entry(oldUser).State = EntityState.Modified; } db.SaveChanges(); } return(Json(new { code = 1, msg = "保存成功" })); }
public JsonResult changePassword(string oldPass, string newPass) { using (DBContext db = new DBContext()) { string _oldPass = StringUtil.Md5Encrypt(oldPass); Guser user = UserContext.user; if (!user.PassWord.Equals(_oldPass)) { return(Json(new { code = -1, msg = "原密码错误" })); } user.PassWord = StringUtil.Md5Encrypt(newPass); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(Json(new { code = 1, msg = "修改成功,3秒后跳转到登录页面", url = "Login/LogOff" })); } }
public JsonResult sendProduct(string orderId, decimal pay, string expressCode, string expressUrl) { if (pay <= 0) { return(Json(new { code = -1, msg = "订单金额必须为正数" })); } using (DBContext db = new DBContext()) { Order order = db.Order.Where(q => q.ID.Equals(orderId)).FirstOrDefault(); if (order == null) { return(Json(new { code = -2, msg = "找不到对应订单" })); } if (order.Status != OrderStatus.BeforeSend) { return(Json(new { code = -3, msg = "订单已发货,无法重复发货" })); } Guser user = UserContext.user; order.ModifyTime = DateTime.Now; order.Paid = pay; order.ExpressCode = expressCode; order.ExpressUrl = expressUrl; order.DeliverId = user.ID; order.DeliverName = user.DisplayName; order.DeliverTel = user.Tel; order.Status = OrderStatus.Sended; db.SaveChanges(); } return(Json(new { code = 1, msg = "提交订单成功" })); }
public JsonResult signIn(string account, string pwd, string remeberMe) { string returnUrl = string.Empty; using (var db = new DBContext()) { string _pass = StringUtil.Md5Encrypt(pwd); Guser user = db.Guser.Include("Role").Where(q => q.Account.Equals(account) && q.PassWord.Equals(_pass)).FirstOrDefault(); if (user == null) { return(Json(new { code = -1, msg = "用户名或密码错误" })); } if (user.Status == Status.disable) { return(Json(new { code = -2, msg = "此用户已禁用,请联系管理员" })); } int roleVal = Convert.ToInt32(user.Role.RoleVal); if (roleVal == 0) { return(Json(new { code = -3, msg = "此用户角色未分配权限,请联系管理员" })); } UserContext.user = user; List <Store> stores = db.Store.Where(q => q.UserId.Equals(user.ID)).OrderBy(q => q.StoreCode).ToList(); if (stores.Count > 0) { Store selectStore = stores[0]; UserContext.store = selectStore; stores.RemoveAt(0); UserContext.stores = stores; } List <Menu> menus = XmlHelper.XmlDeserializeFromFile <List <Menu> >(Server.MapPath("~/route.config"), Encoding.UTF8); MenuContext.menus = menus; //暂时设置为自动保存自动登录 remeberMe = ""; if (!string.IsNullOrEmpty(remeberMe)) { HttpCookie cookie = new HttpCookie("session-cookie-name"); cookie["cookie-account-id-key"] = UserContext.user.ID; cookie.Expires = DateTime.Now.AddDays(7); System.Web.HttpContext.Current.Response.Cookies.Add(cookie); } returnUrl = GetFirstMenu(menus, roleVal); } return(Json(new { code = 1, msg = "登录成功", url = returnUrl })); }
public object signIn(string account, string pwd, string remeberMe) { string returnUrl = string.Empty; string _pass = StringUtil.Md5Encrypt(pwd); Guser user = _context.Guser.Where(q => q.Account.Equals(account) && q.PassWord.Equals(_pass)).FirstOrDefault(); if (user == null) { return(Json(new { code = -1, msg = "用户名或密码错误" })); } if (user.Status == Status.disable) { return(Json(new { code = -2, msg = "此用户已禁用,请联系管理员" })); } if (!string.IsNullOrEmpty(user.DeptID)) { Department dept = _context.Department.Where(q => q.ID.Equals(user.DeptID)).FirstOrDefault(); if (dept == null) { return(Json(new { code = -3, msg = "抱歉,未找到此用户所属的部门" })); } if (dept.Status == Status.disable) { return(Json(new { code = -4, msg = "此用户所属部门已禁用,请联系管理员" })); } Department dw = _context.Department.Where(q => q.ID.Equals(dept.ParentID)).FirstOrDefault(); if (dw == null) { return(Json(new { code = -5, msg = "抱歉,未找到此用户所属的单位" })); } if (dw.Status == Status.disable) { return(Json(new { code = -6, msg = "此用户所属单位已禁用,请联系管理员" })); } HttpContext.Session.Set("SESSION-DEPARTMENT-KEY", dw); } HttpContext.Session.Set("SESSION-ACCOUNT-KEY", user); //暂时设置为不自动登录 //remeberMe = "1"; //if (!string.IsNullOrEmpty(remeberMe)) //{ // HttpCookie cookie = new HttpCookie("session-cookie-name"); // cookie["cookie-account-id-key"] = UserContext.user.ID; // cookie.Expires = DateTime.Now.AddDays(7); // System.Web.HttpContext.Current.Response.Cookies.Add(cookie); //} //returnUrl = SiteUtils.isMobile() ? "MobileHome" : "NewImage"; return(Json(new { code = 1, msg = "登录成功", url = "Home" })); }