示例#1
0
        public ActionResult AddMonitor(bool IsCopy, Monitor model)
        {
            try
            {
                int  MonitorConditionNum = 0;
                Guid OldMonitorID        = Guid.Empty;
                if (model != null)
                {
                    model.Editor   = Session["LoginedUser"] != null ? Session["LoginedUser"].ToString() : "";
                    model.EditTime = DateTime.Now.ToLocalTime();
                    model.IsActive = false;
                    model.IsAudit  = false;
                    if (IsCopy)
                    {
                        OldMonitorID    = model.MonitorID;
                        model.MonitorID = Guid.NewGuid();
                    }
                    Monitor addModel = MonitorRepository.Add(model);

                    if (IsCopy)
                    {
                        List <MonitorCondition> lmc = MonitorConditionRepository.FindList(m => m.MonitorID == OldMonitorID, string.Empty, false).ToList();
                        if (lmc != null && lmc.Count != 0)
                        {
                            foreach (var item in lmc)
                            {
                                item.Contract           = model.Contract;
                                item.MonitorDate        = model.MonitorDate;
                                item.MonitorConditionID = Guid.NewGuid();
                                item.MonitorID          = addModel.MonitorID;
                            }
                            MonitorConditionNum = MonitorConditionRepository.AddRange(lmc);
                        }
                    }
                    if (addModel != null)
                    {
                        return(Json(new { Success = true, Msg = "新增监控条件" + MonitorConditionNum }));
                    }
                }
                return(Json(new { Success = false, Msg = "参数有误" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Success = false, Msg = ex.ToString() }));
            }
        }