/// <summary> /// 保存支出类型 /// </summary> /// <param name="info">支出类型</param> /// <returns>主键ID</returns> public async Task <ResultInfo <int> > SaveOutTypeAsync(OutTypeInfo info) { //获取原有列表 var list = await BasicDAL.Inst.QueryOutTypeAsync(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 OutType(); model.FamilyID = this.LoginInfo.FamilyID; } model.OutCategoryID = info.OutCategoryID; model.Name = info.Name; model.AmountAccountID = info.AmountAccountID; model.IsActive = info.IsActive; model.Remark = info.Remark; //设置创建者/更新者字段值 this.SetCreateUpdateFields(model); //保存到数据库 await BasicDAL.Inst.SaveOutTypeAsync(model); return(new ResultInfo <int>(true, Res.Gen.OK, model.ID)); }
/// <summary> /// 获取支出类型 /// </summary> /// <param name="id">主键ID</param> /// <returns></returns> public async Task <OutTypeInfo> GetOutTypeAsync(int id) { //获取数据库记录 var model = await BasicDAL.Inst.GetOutTypeAsync(this.LoginInfo.FamilyID, id); if (model == null) { return(null); } //结果 var info = new OutTypeInfo(); info.ID = model.ID; info.OutCategoryID = model.OutCategoryID; info.Name = model.Name; info.AmountAccountID = model.AmountAccountID; info.IsActive = model.IsActive; info.Remark = model.Remark; return(info); }
public async Task <ResultInfo <int> > SaveOutTypeAsync([FromBody] OutTypeInfo info) { var result = await this.bll.SaveOutTypeAsync(info); return(result); }