Exemplo n.º 1
0
        public ActionResult Add(EventModel model)
        {
            if (!string.IsNullOrWhiteSpace(model.Key) && BSPConfig.EventConfig.BSPEventList.Find(x => x.Key == model.Key.Trim().ToLower()) != null)
            {
                ModelState.AddModelError("Key", "键已经存在");
            }

            if (!string.IsNullOrWhiteSpace(model.Title) && BSPConfig.EventConfig.BSPEventList.Find(x => x.Title == model.Title.Trim().ToLower()) != null)
            {
                ModelState.AddModelError("Title", "名称已经存在");
            }

            if (ModelState.IsValid)
            {
                EventInfo eventInfo = new EventInfo()
                {
                    Key       = model.Key.Trim().ToLower(),
                    Title     = model.Title.Trim().ToLower(),
                    TimeType  = model.TimeType,
                    TimeValue = model.TimeValue,
                    ClassName = model.ClassName,
                    Code      = model.Code ?? "",
                    Enabled   = model.Enabled
                };

                BSPConfig.EventConfig.BSPEventList.Add(eventInfo);
                BSPConfig.SaveEventConfig(BSPConfig.EventConfig);
                AddAdminOperateLog("添加事件", "添加事件,事件为:" + model.Title);
                return(PromptView("事件添加成功"));
            }
            ViewData["referer"] = ShopUtils.GetAdminRefererCookie();
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Edit(EventModel model)
        {
            EventInfo eventInfo = null;

            if (!string.IsNullOrWhiteSpace(model.Key))
            {
                eventInfo = BSPConfig.EventConfig.BSPEventList.Find(x => x.Key == model.Key);
            }

            if (eventInfo == null)
            {
                return(PromptView("事件不存在"));
            }

            if (!string.IsNullOrWhiteSpace(model.Title))
            {
                EventInfo temp = BSPConfig.EventConfig.BSPEventList.Find(x => x.Title == model.Title.Trim().ToLower());
                if (temp != null && temp.Key != eventInfo.Key)
                {
                    ModelState.AddModelError("Title", "名称已经存在");
                }
            }

            if (ModelState.IsValid)
            {
                //eventInfo.Key = model.Key.Trim().ToLower(),
                eventInfo.Title     = model.Title.Trim().ToLower();
                eventInfo.TimeType  = model.TimeType;
                eventInfo.TimeValue = model.TimeValue;
                eventInfo.ClassName = model.ClassName;
                eventInfo.Code      = model.Code ?? "";
                eventInfo.Enabled   = model.Enabled;

                BSPConfig.SaveEventConfig(BSPConfig.EventConfig);
                AddAdminOperateLog("编辑事件", "编辑事件,事件为:" + model.Title);
                return(PromptView("事件编辑成功"));
            }
            ViewData["referer"] = ShopUtils.GetAdminRefererCookie();
            return(View(model));
        }