/// <summary>
        /// 初始化账户
        /// </summary>
        /// <param name="userId"></param>
        public void InitCostChannel(long userId)
        {
            List <string> channelList = new List <string>
            {
                "现金账户", "支付宝账户", "微信账户"
            };
            int i = 1;

            foreach (var s in channelList)
            {
                var oldModel = new CostChannelModel
                {
                    IsDel           = FlagEnum.HadZore,
                    IsValid         = FlagEnum.HadOne,
                    UpdateUserId    = userId,
                    UpdateTime      = DateTime.Now,
                    CostChannelName = s,
                    CostChannelNo   = "",
                    CreateTime      = DateTime.Now,
                    CreateUserId    = userId,
                    Sort            = i++,
                    UserId          = userId
                };
                try
                {
                    SaveModel(oldModel);
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e);
                }
            }
        }
        public ActionResult SaveCostChannelInfo(long id, string costChannelName, string costChannelNo, int sort, int isValid)
        {
            var resultMode = new ResponseBaseModel <dynamic>
            {
                ResultCode = ResponceCodeEnum.Fail,
            };

            if (string.IsNullOrEmpty(costChannelName))
            {
                resultMode.Message = "名称不能为空";
                return(Json(resultMode, JsonRequestBehavior.AllowGet));
            }

            var userId = CurrentModel.UserId;
            var server = new CostChannelService();
            CostChannelModel newModel = new CostChannelModel();

            if (id > 0)
            {
                newModel = server.Get(id);
                //验证权限
                if (newModel == null || newModel.UserId != userId)
                {
                    resultMode.Message = "非法访问";
                    return(Json(resultMode, JsonRequestBehavior.AllowGet));
                }
            }
            //验证参数
            newModel.Id              = id;
            newModel.IsDel           = FlagEnum.HadZore;
            newModel.IsValid         = EnumHelper.GetEnumByValue <FlagEnum>(isValid);
            newModel.CostChannelName = costChannelName;
            newModel.CostChannelNo   = costChannelNo;
            newModel.UserId          = userId;
            newModel.CreateTime      = newModel.CreateTime < new DateTime(1900, 1, 1) ? DateTime.Now : newModel.CreateTime;
            newModel.CreateUserId    = newModel.CreateUserId < 1 ? userId : newModel.CreateUserId;
            newModel.Sort            = sort;
            newModel.UpdateTime      = DateTime.Now;
            newModel.UpdateUserId    = userId;

            var costTypeInfoList = server.GetList(costChannelName, userId);

            if (costTypeInfoList != null &&
                (costTypeInfoList.Count > 1 || costTypeInfoList.Count == 1 && costTypeInfoList[0].Id != id))
            {
                resultMode.Message = "账号名称已经存在";
                return(Json(resultMode, JsonRequestBehavior.AllowGet));
            }
            server.SaveModel(newModel);
            resultMode.ResultCode = ResponceCodeEnum.Success;
            return(Json(resultMode, JsonRequestBehavior.AllowGet));
        }
 /// <summary>
 /// 保存信息
 /// </summary>
 /// <param name="saveModel"></param>
 public void SaveModel(CostChannelModel saveModel)
 {
     _dataAccess.SaveModel(saveModel);
 }