/// <summary> /// 简单的Model创建,直接返回视图 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="model"></param> /// <returns></returns> protected ActionResult CreateModel <T>(T model) { JsonResult ret = new JsonResult(); try { var t = model.GetType(); //设置模型值 var prop = t.GetProperty("CreatorID"); if (prop != null) { prop.SetValue(model, LoginUser.ID); } prop = t.GetProperty("CreationTime"); if (prop != null) { prop.SetValue(model, DateTime.Now); } var tDB = db.GetType(); //获取DbSet属性 var modelSet = tDB.GetProperty(t.Name); //属性实例 var modelSetInst = modelSet.GetValue(db); //获取Add方法 var mAdd = modelSet.PropertyType.GetMethod("Add"); //用实例调用Add mAdd.Invoke(modelSetInst, new object[] { model }); db.SaveChanges(); ret.Data = JsonConvert.SerializeObject(new { status = 0, message = "", data = model }); } catch (Exception ex) { ret.Data = JsonConvert.SerializeObject(new { status = 1, message = ex.Message, data = model }); } return(ret); }
public ActionResult Edit(MachineRoom room) { var json = new JsonResult(); try { using (var ctx = new GlsunViewEntities()) { var loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); var roomModify = (from r in ctx.MachineRoom where r.ID == room.ID select r).FirstOrDefault(); roomModify.MRName = room.MRName; roomModify.MRAddress = room.MRAddress; roomModify.MRDescription = room.MRDescription; roomModify.MRIcon = room.MRIcon; roomModify.Remark = room.Remark; roomModify.EditorID = loginUser.ID; roomModify.EditingTime = DateTime.Now; ctx.SaveChanges(); } json.Data = new { Code = "", Data = "", Message = "保存成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = "", Message = ex.Message }; } return(json); }
public ActionResult Create(MachineShelf shelf) { var json = new JsonResult(); try { using (var ctx = new GlsunViewEntities()) { var loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); if (loginUser != null) { shelf.CreatorID = loginUser.ID; shelf.CreationTime = DateTime.Now; } ctx.MachineShelf.Add(shelf); ctx.SaveChanges(); } json.Data = new { Code = "", Data = "", Message = "保存成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = "", Message = ex.Message }; } return(json); }
public ActionResult Create(RouteGroup group, HttpPostedFileBase iconFile) { var json = new JsonResult(); User loginUser = null; try { string iconFileName = ""; if (iconFile != null) { iconFileName = SaveIcon(iconFile); } using (var ctx = new GlsunViewEntities()) { loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); group.CreatorID = loginUser.ID; group.CreationTime = DateTime.Now; //图标没值 if (string.IsNullOrWhiteSpace(group.RGIcon)) { group.RGIcon = iconFileName; } ctx.RouteGroup.Add(group); ctx.SaveChanges(); } json.Data = new { Code = "", Data = "", Message = "保存成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = "", Message = ex.Message }; } return(json); }
public ActionResult Delete(int id, FormCollection collection) { var json = new JsonResult(); try { using (var ctx = new GlsunViewEntities()) { using (var tran = new TransactionScope()) { var authDelete = ctx.Authority.Find(id); var moduleAuth = ctx.ModuleAuthority.Where(m => m.AID == id); //删除外键引用记录 foreach (var ma in moduleAuth) { var roleAuth = ctx.RoleAuthority.Where(r => r.MAID == ma.ID); ctx.RoleAuthority.RemoveRange(roleAuth); ctx.ModuleAuthority.Remove(ma); } ctx.Authority.Remove(authDelete); ctx.SaveChanges(); tran.Complete(); } } json.Data = new { Code = "", Data = id, Message = "删除成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = id, Message = ex.Message }; } return(json); }
public ActionResult Edit(MachineShelf shelf) { var json = new JsonResult(); try { using (var ctx = new GlsunViewEntities()) { var loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); var shelfModify = (from r in ctx.MachineShelf where r.ID == shelf.ID select r).FirstOrDefault(); shelfModify.MSName = shelf.MSName; shelfModify.MSNumber = shelf.MSNumber; shelfModify.MSLayers = shelf.MSLayers; shelfModify.MSIcon = shelf.MSIcon; shelfModify.MRID = shelf.MRID; shelfModify.Remark = shelf.Remark; shelfModify.EditorID = loginUser.ID; shelfModify.EditingTime = DateTime.Now; ctx.SaveChanges(); } json.Data = new { Code = "", Data = "", Message = "保存成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = "", Message = ex.Message }; } return(json); }
public ActionResult Rename(int id, string name) { var json = new JsonResult(); User loginUser = null; Subnet net = null; try { using (var ctx = new GlsunViewEntities()) { loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); var subnetModify = (from s in ctx.Subnet where s.ID == id select s).FirstOrDefault(); subnetModify.SName = name; subnetModify.EditorID = loginUser.ID; subnetModify.EditingTime = DateTime.Now; net = subnetModify.CopyProperty(); net.Device = null; ctx.SaveChanges(); } json.Data = new { Code = "", Data = net, Message = "重命名成功" }; //日志记录 _topoLogger.Record(loginUser, "修改子网", "重命名", "成功", "", net.ID, net.SName, "子网"); } catch (Exception ex) { json.Data = new { Code = "Exception", Data = net, Message = ex.Message }; //日志记录 _topoLogger.Record(loginUser, "修改子网", "重命名", "失败", string.Format("发生异常:{0}", ex.Message), net.ID, net.SName, "子网"); } return json; }
public ActionResult ConfirmFast(string confirmIds) { JsonResult json = new JsonResult(); var arrIds = confirmIds.Split(','); List <int> Ids = new List <int>(); if (arrIds.Length > 0) { Ids = (from id in arrIds select int.Parse(id)).ToList(); using (var ctx = new GlsunViewEntities()) { var loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); var alarmInfos = ctx.AlarmInformation.Where(a => Ids.Contains(a.ID)); foreach (var info in alarmInfos) { info.AIConfirm = true; info.AIConfirmTime = DateTime.Now; info.UID = loginUser.ID; info.ULoginName = loginUser.ULoginName; info.UName = loginUser.UName; } ctx.SaveChanges(); } } json.Data = Ids; return(json); }
public string Delete(int id) { object result = null; User loginUser = null; string details = ""; DeviceLine line = null; try { using (var ctx = new GlsunViewEntities()) { loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); var deviceLineDel = ctx.DeviceLine.Find(id); line = deviceLineDel.CopyProperty(); ctx.DeviceLine.Remove(deviceLineDel); ctx.SaveChanges(); var dA = ctx.Device.Find(line.DIDA); var dB = ctx.Device.Find(line.DIDB); details = string.Format("{0}-{1}", dA.DName, dB.DName); } result = new { Code = "", Data = id, Message = "删除成功" }; //日志记录 _topoLogger.Record(loginUser, "删除设备连线", details, "成功", "", line.ID, line.DLName, "设备连线"); } catch (Exception ex) { result = new { Code = "Exception", Data = id, Message = ex.Message }; //日志记录 _topoLogger.Record(loginUser, "删除设备连线", details, "失败", string.Format("发生异常:{0}", ex.Message), line.ID, line.DLName, "设备连线"); } return(new JavaScriptSerializer().Serialize(result)); }
public ActionResult Edit(DeviceLine line) { var json = new JsonResult(); User loginUser = null; try { using (var ctx = new GlsunViewEntities()) { loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); var route = ctx.Route.Find(line.RID); var modifyLine = ctx.DeviceLine.Find(line.ID); modifyLine.DLName = route.RName; modifyLine.RID = line.RID; modifyLine.EditorID = loginUser.ID; modifyLine.EditingTime = DateTime.Now; ctx.SaveChanges(); } json.Data = new { Code = "", Data = "", Message = "保存成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = "", Message = ex.Message }; } return(json); }
public ActionResult Create(Route route) { var json = new JsonResult(); User loginUser = null; try { using (var ctx = new GlsunViewEntities()) { loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); var frameA = ctx.MachineFrame.Find(route.RAMFID); var frameB = ctx.MachineFrame.Find(route.RBMFID); route.RAIP = frameA.MFIP; route.RBIP = frameB.MFIP; route.CreationTime = DateTime.Now; route.CreatorID = loginUser.ID; ctx.Route.Add(route); ctx.SaveChanges(); } json.Data = new { Code = "", Data = "", Message = "保存成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = "", Message = ex.Message }; } return(json); }
public JsonResult Delete(int id, FormCollection collection) { var json = new JsonResult(); try { using (var ctx = new GlsunViewEntities()) { var module = (from m in ctx.Module where m.ID == id select m).First(); DeleteChildModule(module.ID); var moduleAuthority = from ma in ctx.ModuleAuthority where ma.MID == id select ma; ctx.ModuleAuthority.RemoveRange(moduleAuthority); ctx.Module.Remove(module); ctx.SaveChanges(); } json.Data = new { Code = "", Data = id, Message = "删除成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = id, Message = ex.Message }; } return(json); }
public ActionResult Edit(Device device, HttpPostedFileBase iconFile) { var json = new JsonResult(); User loginUser = null; try { string iconFileName = ""; if (iconFile != null) { iconFileName = SaveIcon(iconFile); } using (var ctx = new GlsunViewEntities()) { loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); var deviceModify = ctx.Device.Find(device.ID); deviceModify.DName = device.DName; deviceModify.DAddress = device.DAddress; deviceModify.DPort = device.DPort; deviceModify.DType = device.DType; deviceModify.DIcon = device.DIcon; deviceModify.DProtocal = device.DProtocal; deviceModify.CoordinateX = device.CoordinateX; deviceModify.CoordinateY = device.CoordinateY; deviceModify.Remark = device.Remark; deviceModify.EditorID = loginUser.ID; deviceModify.EditingTime = DateTime.Now; deviceModify.MFID = device.MFID; if (!string.IsNullOrWhiteSpace(iconFileName)) { deviceModify.DIcon = iconFileName; device.DIcon = iconFileName; } ctx.SaveChanges(); } var data = new TopologyNode { ID = device.ID, Name = device.DName, Address = device.DAddress, Icon = device.DIcon, X = device.CoordinateX.Value, Y = device.CoordinateY.Value }; json.Data = new { Code = "", Data = data, Message = "保存成功" }; //日志记录 _topoLogger.Record(loginUser, "修改设备", "", "成功", "", device.ID, device.DName, "设备"); } catch (Exception ex) { json.Data = new { Code = "Exception", Data = device, Message = ex.Message }; //日志记录 _topoLogger.Record(loginUser, "修改设备", "", "失败", string.Format("发生异常:{0}"), device.ID, device.DName, "设备"); } return(json); }
public JsonResult Delete(int id, FormCollection collection) { var json = new JsonResult(); try { using (var ctx = new GlsunViewEntities()) { var userDel = (from u in ctx.User where u.ID == id select u).FirstOrDefault(); var userRoleDel = from ur in ctx.UserRole where ur.UID == id select ur; ctx.User.Remove(userDel); ctx.UserRole.RemoveRange(userRoleDel); ctx.SaveChanges(); } json.Data = new { Code = "", Data = id, Message = "删除成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = id, Message = ex.Message }; } return(json); }
public ActionResult Edit(Role role) { var json = new JsonResult(); try { using (var ctx = new GlsunViewEntities()) { var loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); var roleModify = (from r in ctx.Role where r.ID == role.ID select r).FirstOrDefault(); roleModify.RName = role.RName; roleModify.RCode = role.RCode; roleModify.EditorID = loginUser.ID; roleModify.EditingTime = DateTime.Now; ctx.SaveChanges(); } json.Data = new { Code = "", Data = role, Message = "保存成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = role, Message = ex.Message }; } return(json); }
public void SaveSceneLocation(SceneLocation location) { using (var ctx = new GlsunViewEntities()) { var loc = (from l in ctx.SceneLocation where l.ID == location.ID select l).FirstOrDefault(); loc.CoordinateX = location.CoordinateX; loc.CoordinateY = location.CoordinateY; ctx.SaveChanges(); } }
// GET: Subnet public ActionResult Index(int id) { IEnumerable<TopologyNode> nodes = null; IEnumerable<TopologyLine> lines = null; SceneLocation sceneLoc = null; using (var ctx = new GlsunViewEntities()) { var subnet = ctx.Subnet.Find(id); nodes = (from d in ctx.Device where d.SID == id select new TopologyNode { ID = d.ID, Name = d.DName, Address = d.DAddress, Icon = d.DIcon, X = d.CoordinateX.Value, Y = d.CoordinateY.Value }).ToList(); var nodeIds = (from n in nodes select n.ID).ToList(); lines = (from l in ctx.DeviceLine where nodeIds.Contains(l.DIDA.Value) || nodeIds.Contains(l.DIDB.Value) select new TopologyLine { ID = l.ID, Name = l.DLName, NodeIDA = l.DIDA.Value, NodeIDZ = l.DIDB.Value }).ToList(); sceneLoc = (from l in ctx.SceneLocation where l.SceneType == "device" && l.UserID == id select l).FirstOrDefault(); if (sceneLoc == null) { sceneLoc = new SceneLocation { CoordinateX = 0, CoordinateY = 0, SceneType = "device", UserID = id }; ctx.SceneLocation.Add(sceneLoc); ctx.SaveChanges(); } } ViewBag.Nodes = new JavaScriptSerializer().Serialize(nodes); ViewBag.Lines = new JavaScriptSerializer().Serialize(lines); ViewBag.SceneLocation = new JavaScriptSerializer().Serialize(sceneLoc); ViewBag.SubnetId = id; SetAuthorityData(); return View(); }
public ActionResult Authorize(RoleAuthrizeInfo roleAuthInfo) { var json = new JsonResult(); try { using (var ctx = new GlsunViewEntities()) { var loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); //移除未勾选 if (roleAuthInfo.UnCheckedId != null) { foreach (var sId in roleAuthInfo.UnCheckedId) { int maId = Convert.ToInt32(sId); var roleAuth = (from ra in ctx.RoleAuthority where ra.MAID == maId && ra.RID == roleAuthInfo.RoleId select ra).FirstOrDefault(); if (roleAuth != null) { ctx.RoleAuthority.Remove(roleAuth); } } } //添加勾选 if (roleAuthInfo.CheckedId != null) { foreach (var sId in roleAuthInfo.CheckedId) { int maId = Convert.ToInt32(sId); var roleAuth = new RoleAuthority { RID = roleAuthInfo.RoleId, MAID = maId, CreatorID = loginUser.ID, CreationTime = DateTime.Now }; ctx.RoleAuthority.Add(roleAuth); } } ctx.SaveChanges(); } json.Data = new { Code = "", Data = roleAuthInfo, Message = "保存成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = roleAuthInfo, Message = ex.Message }; } return(json); }
// GET: Topology public ActionResult Index() { IEnumerable <Subnet> subnets = null; IEnumerable <TopologyNode> nodes = null; IEnumerable <TopologyLine> lines = null; SceneLocation sceneLoc = null; var nodesJSON = string.Empty; using (var ctx = new GlsunViewEntities()) { subnets = ctx.Subnet.ToList(); lines = (from l in ctx.SubnetLine select new TopologyLine { ID = l.ID, Name = l.SLName, NodeIDA = l.SIDA.Value, NodeIDZ = l.SIDB.Value }).ToList(); sceneLoc = (from l in ctx.SceneLocation where l.SceneType == "subnet" select l).FirstOrDefault(); if (sceneLoc == null) { sceneLoc = new SceneLocation { CoordinateX = 0, CoordinateY = 0, SceneType = "subnet" }; ctx.SceneLocation.Add(sceneLoc); ctx.SaveChanges(); } } nodes = (from n in subnets select new TopologyNode { ID = n.ID, Name = n.SName, Address = n.SAddress, Icon = n.SIcon, X = n.CoordinateX.Value, Y = n.CoordinateY.Value }).ToList(); JavaScriptSerializer serializer = new JavaScriptSerializer(); ViewBag.Nodes = serializer.Serialize(nodes); ViewBag.Lines = serializer.Serialize(lines); ViewBag.SceneLocation = serializer.Serialize(sceneLoc); SetAuthorityData(); return(View()); }
public JsonResult Create(User user, List <int> SelectedRoleId) { var json = new JsonResult(); try { var userId = 0; using (var ctx = new GlsunViewEntities()) { var loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); if (loginUser != null) { user.CreatorID = loginUser.ID; user.CreationTime = DateTime.Now; } ctx.User.Add(user); ctx.SaveChanges(); userId = user.ID; } if (SelectedRoleId != null) { using (var ctx = new GlsunViewEntities()) { var loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); foreach (var id in SelectedRoleId) { UserRole userRole = new UserRole { UID = userId, RID = id, CreatorID = loginUser.ID, CreationTime = DateTime.Now }; ctx.UserRole.Add(userRole); } ctx.SaveChanges(); } } json.Data = new { Code = "", Data = "", Message = "保存成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = "", Message = ex.Message }; } return(json); }
public string Add(TopologyLine line) { object result = null; User loginUser = null; string details = ""; try { using (var ctx = new GlsunViewEntities()) { loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); var newLine = ctx.DeviceLine.Create(); Device dA = ctx.Device.Find(line.NodeIDA); Device dB = ctx.Device.Find(line.NodeIDZ); /*Route route = ctx.Route.Where(r => (r.RAMFID == dA.MFID && r.RBMFID == dB.MFID) || * (r.RAMFID == dB.MFID && r.RBMFID == dA.MFID)).FirstOrDefault(); * if(route != null) * { * newLine.DLName = route.RName; * } * else * { * newLine.DLName = string.Format("{0}-{1}", dA.DName, dB.DName); * }*/ newLine.DIDA = line.NodeIDA; newLine.DIDB = line.NodeIDZ; newLine.CreatorID = loginUser.ID; newLine.CreationTime = DateTime.Now; ctx.DeviceLine.Add(newLine); ctx.SaveChanges(); line.ID = newLine.ID; //line.Name = newLine.DLName; details = string.Format("{0}-{1}", dA.DName, dB.DName); } result = new { Code = "", Data = line, Message = "保存成功" }; //日志记录 _topoLogger.Record(loginUser, "添加设备连线", details, "成功", "", line.ID, line.Name, "设备连线"); } catch (Exception ex) { result = new { Code = "Exception", Data = line, Message = ex.Message }; //日志记录 _topoLogger.Record(loginUser, "添加设备连线", details, "失败", string.Format("发生异常:{0}", ex.Message), line.ID, line.Name, "设备连线"); } return(new JavaScriptSerializer().Serialize(result)); }
public ActionResult Create(Device device, HttpPostedFileBase iconFile) { var json = new JsonResult(); User loginUser = null; try { string iconFileName = ""; if (iconFile != null) { iconFileName = SaveIcon(iconFile); } using (var ctx = new GlsunViewEntities()) { loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); var newDevice = device.CopyProperty(); newDevice.CreatorID = loginUser.ID; newDevice.CreationTime = DateTime.Now; if (string.IsNullOrWhiteSpace(newDevice.DIcon)) { newDevice.DIcon = iconFileName; } ctx.Device.Add(newDevice); ctx.SaveChanges(); device.ID = newDevice.ID; device.DIcon = newDevice.DIcon; } var data = new TopologyNode { ID = device.ID, Name = device.DName, Address = device.DAddress, Icon = device.DIcon, X = device.CoordinateX.Value, Y = device.CoordinateY.Value }; json.Data = new { Code = "", Data = data, Message = "保存成功" }; //日志记录 _topoLogger.Record(loginUser, "添加设备", "", "成功", "", device.ID, device.DName, "设备"); } catch (Exception ex) { json.Data = new { Code = "Exception", Data = device, Message = ex.Message }; //日志记录 _topoLogger.Record(loginUser, "添加设备", "", "失败", string.Format("发生异常:{0}"), device.ID, device.DName, "设备"); } return(json); }
public ActionResult Create(Authority authority) { var json = new JsonResult(); try { using (var ctx = new GlsunViewEntities()) { using (var tran = new TransactionScope())//开启事务 { var loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); authority.CreatorID = loginUser.ID; authority.CreationTime = DateTime.Now; ctx.Authority.Add(authority); //给模块添加新权限--通用权限才添加 if (authority.AIsCommon == true) { var moduleList = ctx.Module.Where(m => m.MParentID != 0 && m.MType == "menu"); foreach (var module in moduleList) { ModuleAuthority ma = new ModuleAuthority { AID = authority.ID, MID = module.ID, CreatorID = loginUser.ID, CreationTime = DateTime.Now }; ctx.ModuleAuthority.Add(ma); } } ctx.SaveChanges(); tran.Complete();//必须调用.Complete(),不然数据不会保存 }//出了using代码块如果还没调用Complete(),所有操作就会自动回滚 } json.Data = new { Code = "", Data = "", Message = "保存成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = "", Message = ex.Message }; } return(json); }
public ActionResult Edit(Subnet net, HttpPostedFileBase iconFile) { var json = new JsonResult(); User loginUser = null; try { string iconFileName = ""; if (iconFile != null) { iconFileName = SaveIcon(iconFile); } using (var ctx = new GlsunViewEntities()) { loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); var subnetEdit = (from s in ctx.Subnet where s.ID == net.ID select s).FirstOrDefault(); subnetEdit.SName = net.SName; subnetEdit.SAddress = net.SAddress; subnetEdit.SIcon = net.SIcon; subnetEdit.CoordinateX = net.CoordinateX; subnetEdit.CoordinateY = net.CoordinateY; subnetEdit.Remark = net.Remark; subnetEdit.EditorID = loginUser.ID; subnetEdit.EditingTime = DateTime.Now; //不为空说明上传了图片 if (!string.IsNullOrEmpty(iconFileName)) { subnetEdit.SIcon = iconFileName; net.SIcon = iconFileName; } ctx.SaveChanges(); } json.Data = new { Code = "", Data = net, Message = "保存成功" }; //日志记录 _topoLogger.Record(loginUser, "修改子网", "", "成功", "", net.ID, net.SName, "子网"); } catch (Exception ex) { json.Data = new { Code = "Exception", Data = net, Message = ex.Message }; //日志记录 _topoLogger.Record(loginUser, "修改子网", "", "失败", string.Format("发生异常:{0}", ex.Message), net.ID, net.SName, "子网"); } return json; }
public JsonResult Create(Module module) { var json = new JsonResult(); try { using (var ctx = new GlsunViewEntities()) { using (var tran = new TransactionScope()) { var loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); if (loginUser != null) { module.CreatorID = loginUser.ID; module.CreationTime = DateTime.Now; } ctx.Module.Add(module); //添加操作权限 if (module.MParentID != 0 && module.MType == "menu") { foreach (var e in ctx.Authority.Where(a => a.IsEnabled.Value && a.AIsCommon.Value)) { ModuleAuthority ma = new ModuleAuthority { AID = e.ID, MID = module.ID, CreatorID = loginUser.ID, CreationTime = DateTime.Now }; ctx.ModuleAuthority.Add(ma); } } ctx.SaveChanges(); tran.Complete(); //必须调用.Complete(),不然数据不会保存 }//出了using代码块如果还没调用Complete(),所有操作就会自动回滚 } json.Data = new { Code = "", Data = "", Message = "保存成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = "", Message = ex.Message }; } return(json); }
public ActionResult Rename(int id, string name) { //序列化有外键约束的EF实体对象会报错 var json = new JsonResult(); TopologyNode node = null; User loginUser = null; Device device = null; try { using (var ctx = new GlsunViewEntities()) { loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); var deviceModify = ctx.Device.Find(id); device = deviceModify.CopyProperty(); if (deviceModify != null) { deviceModify.DName = name; deviceModify.EditorID = loginUser.ID; deviceModify.EditingTime = DateTime.Now; node = new TopologyNode { ID = deviceModify.ID, Name = deviceModify.DName, Address = deviceModify.DAddress, Icon = deviceModify.DIcon, X = deviceModify.CoordinateX.Value, Y = deviceModify.CoordinateY.Value }; ctx.SaveChanges(); } } json.Data = new { Code = "", Data = node, Message = "重命名成功" }; //日志记录 _topoLogger.Record(loginUser, "修改设备", "重命名", "成功", "", device.ID, device.DName, "设备"); } catch (Exception ex) { json.Data = new { Code = "Exception", Data = node, Message = ex.Message }; //日志记录 _topoLogger.Record(loginUser, "修改设备", "重命名", "失败", string.Format("发生异常:{0}"), device.ID, device.DName, "设备"); } return(json); }
public ActionResult Edit(MachineFrame frame, HttpPostedFileBase iconFile) { var json = new JsonResult(); try { string iconFileName = ""; if (iconFile != null) { iconFileName = SaveIcon(iconFile); } using (var ctx = new GlsunViewEntities()) { var loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); var frameModify = (from r in ctx.MachineFrame where r.ID == frame.ID select r).FirstOrDefault(); frameModify.MFName = frame.MFName; frameModify.MFIP = frame.MFIP; frameModify.MFPort = frame.MFPort; frameModify.MSID = frame.MSID; frameModify.MFMCUType = frame.MFMCUType; frameModify.MSLayer = frame.MSLayer; frameModify.MFIcon = frame.MFIcon; frameModify.Remark = frame.Remark; frameModify.EditorID = loginUser.ID; frameModify.EditingTime = DateTime.Now; //图标没值 if (string.IsNullOrWhiteSpace(frameModify.MFIcon)) { frameModify.MFIcon = iconFileName; } ctx.SaveChanges(); } json.Data = new { Code = "", Data = "", Message = "保存成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = "", Message = ex.Message }; } return(json); }
public ActionResult Delete(int id, FormCollection collection) { var json = new JsonResult(); try { using (var ctx = new GlsunViewEntities()) { ctx.RouteGroup.Remove(ctx.RouteGroup.Find(id)); ctx.SaveChanges(); } json.Data = new { Code = "", Data = "", Message = "删除成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = "", Message = ex.Message }; } return(json); }
public ActionResult Delete(int id, FormCollection collection) { var json = new JsonResult(); User loginUser = null; Device device = null; try { using (var ctx = new GlsunViewEntities()) { loginUser = (from u in ctx.User where u.ULoginName == HttpContext.User.Identity.Name select u).FirstOrDefault(); var deviceDel = ctx.Device.Find(id); device = deviceDel.CopyProperty(); var deviceLineDel = from l in ctx.DeviceLine where l.DIDA == id || l.DIDB == id select l; ctx.Device.Remove(deviceDel); //ctx.DeviceLine.RemoveRange(deviceLineDel); foreach (var l in deviceLineDel) { var dA = ctx.Device.Find(l.DIDA); var dB = ctx.Device.Find(l.DIDB); var detail = string.Format("{0}-{1}", dA.DName, dB.DName); _topoLogger.Record(loginUser, "删除设备连线", detail, "成功", "删除设备时关联删除", l.ID, l.DLName, "设备连线"); ctx.DeviceLine.Remove(l); } ctx.SaveChanges(); } json.Data = new { Code = "", Data = id, Message = "删除成功" }; //日志记录 _topoLogger.Record(loginUser, "删除设备", "", "成功", "", device.ID, device.DName, "设备"); } catch (Exception ex) { json.Data = new { Code = "Exception", Data = id, Message = ex.Message }; //日志记录 _topoLogger.Record(loginUser, "删除设备", "", "失败", string.Format("发生异常:{0}"), device.ID, device.DName, "设备"); } return(json); }
public ActionResult Delete(int id, FormCollection collection) { var json = new JsonResult(); try { using (var ctx = new GlsunViewEntities()) { var shelfDelete = ctx.MachineShelf.Find(id); ctx.MachineShelf.Remove(shelfDelete); ctx.SaveChanges(); } json.Data = new { Code = "", Data = id, Message = "删除成功" }; } catch (Exception ex) { json.Data = new { Code = "Exception", Data = id, Message = ex.Message }; } return(json); }