Beispiel #1
0
        /// <summary>
        /// 保存收入类型
        /// </summary>
        /// <param name="info">收入类型</param>
        /// <returns>主键ID</returns>
        public async Task <ResultInfo <int> > SaveInTypeAsync(InTypeInfo info)
        {
            //获取原有列表
            var list = await BasicDAL.Inst.QueryInTypeAsync(this.LoginInfo.FamilyID);

            //判断名称是否已被使用
            if (list.Exists(m => m.ID != info.ID && m.Name == info.Name))
            {
                return(new ResultInfo <int>(false, this.Res.Bas.NameExisted, -1));
            }

            //判断默认账户是否存在
            var modelAmountAccount = await BasicDAL.Inst.GetAmountAccountAsync(this.LoginInfo.FamilyID, info.AmountAccountID);

            if (modelAmountAccount == null)
            {
                return(new ResultInfo <int>(false, this.Res.Bas.AmountAccountUnexist, -1));
            }

            //尝试查找原数据
            var model = list.Find(m => m.ID == info.ID);

            //新建
            if (model == null)
            {
                model          = new InType();
                model.FamilyID = this.LoginInfo.FamilyID;
            }

            model.Name            = info.Name;
            model.AmountAccountID = info.AmountAccountID;
            model.IsActive        = info.IsActive;
            model.Remark          = info.Remark;

            //设置创建者/更新者字段值
            this.SetCreateUpdateFields(model);

            //保存到数据库
            await BasicDAL.Inst.SaveInTypeAsync(model);

            return(new ResultInfo <int>(true, Res.Gen.OK, model.ID));
        }
Beispiel #2
0
        /// <summary>
        /// 获取收入类型
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns></returns>
        public async Task <InTypeInfo> GetInTypeAsync(int id)
        {
            //获取数据库信息
            var model = await BasicDAL.Inst.GetInTypeAsync(this.LoginInfo.FamilyID, id);

            if (model == null)
            {
                return(null);
            }

            //结果
            var info = new InTypeInfo();

            info.ID              = model.ID;
            info.Name            = model.Name;
            info.AmountAccountID = model.AmountAccountID;
            info.IsActive        = model.IsActive;
            info.Remark          = model.Remark;

            return(info);
        }
Beispiel #3
0
        public async Task <ResultInfo <int> > SaveInTypeAsync([FromBody] InTypeInfo info)
        {
            var result = await this.bll.SaveInTypeAsync(info);

            return(result);
        }