public JsonResult SaveRouter()
        {
            var json = Request["json"];

            if (string.IsNullOrEmpty(json))
            {
                return(Json(ErrorModel.InputError));
            }

            var model = JsonHelper.Deserialize <InstructorRouterPosition>(json);

            if (model == null)
            {
                return(Json(ErrorModel.InputError));
            }

            model.AddTime = DateTime.Now;

            var updateType = model.Id > 0 ? DataUpdateType.Update : DataUpdateType.Insert;

            bool success;
            var  bll = new InstructorRouterPositionBll();

            if (model.Id > 0)
            {
                success = bll.Update(model);
            }
            else
            {
                model   = bll.Insert(model);
                success = model.Id > 0;
            }

            if (success)
            {
                DataUpdateLog.SingleUpdate(nameof(InstructorRouterPosition), model.Id, updateType);

                return(Json(ErrorModel.OperateSuccess));
            }

            return(Json(ErrorModel.OperateFailed));
        }
Example #2
0
        public JsonResult AddOrUpdateRouter(InstructorRouterPosition model)
        {
            if (model != null)
            {
                var isUpdate   = model.Id > 0;
                var updateType = isUpdate ? DataUpdateType.Update : DataUpdateType.Insert;

                var         bll      = new InstructorRouterPositionBll();
                Func <bool> doUpdate = () => bll.Insert(model).Id > 0;
                if (isUpdate)
                {
                    doUpdate = () => bll.Update(model);
                }

                var success = bll.ExecuteTransation(
                    doUpdate,
                    () => DataUpdateLog.SingleUpdate(nameof(InstructorRouterPosition), model.Id, updateType)
                    );

                return(Json(success ? ErrorModel.OperateSuccess : ErrorModel.OperateFailed));
            }

            return(Json(ErrorModel.InputError));
        }