Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        public string AddLine(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.SubnetLine.Create();

                    newLine.SIDA         = line.NodeIDA;
                    newLine.SIDB         = line.NodeIDZ;
                    newLine.CreatorID    = loginUser.ID;
                    newLine.CreationTime = DateTime.Now;

                    ctx.SubnetLine.Add(newLine);
                    ctx.SaveChanges();
                    line.ID = newLine.ID;

                    var sA = ctx.Subnet.Find(line.NodeIDA);
                    var sB = ctx.Subnet.Find(line.NodeIDZ);
                    details = string.Format("{0}-{1}", sA.SName, sB.SName);
                }
                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));
        }