Пример #1
0
        /// <summary>
        /// 删除借还信息
        /// </summary>
        /// <param name="familyID">家庭ID</param>
        /// <param name="borrowRepayID">借还ID</param>
        public async Task <bool> DeleteBorrowRepayAsync(int familyID, int borrowRepayID)
        {
            using (IOSysContext db = new IOSysContext())
            {
                using (var trans = db.Database.BeginTransaction())
                {
                    //获取原数据
                    var model = db.BorrowRepays.Where(m => m.ID == borrowRepayID && m.FamilyID == familyID).FirstOrDefault();
                    if (model == null)
                    {
                        return(false);
                    }

                    //删除
                    db.BorrowRepays.Remove(model);

                    //账户金额变动值
                    var amount = this.GetAmountDirectionForBorrowRepay(model.BRType, model.Amount);

                    //修改账户信息
                    await BasicDAL.Inst.UnUseAmountAccount(model.FamilyID, model.AmountAccountID, amount, db);

                    await db.SaveChangesAsync();

                    //提交事务
                    trans.Commit();

                    //移除最小交易流水日期缓存
                    this.RemoveMinTurnoverDate(familyID, model.BRDate);

                    return(true);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 删除转账信息
        /// </summary>
        /// <param name="familyID">家庭ID</param>
        /// <param name="transferID">转账ID</param>
        public async Task <bool> DeleteTransferAsync(int familyID, int transferID)
        {
            using (IOSysContext db = new IOSysContext())
            {
                using (var trans = db.Database.BeginTransaction())
                {
                    //获取原数据
                    var model = db.AmountAccountTransfers.Where(m => m.ID == transferID && m.FamilyID == familyID).FirstOrDefault();
                    if (model == null)
                    {
                        return(false);
                    }

                    //删除
                    db.AmountAccountTransfers.Remove(model);

                    //修改账户信息
                    await BasicDAL.Inst.UnUseAmountAccount(model.FamilyID, model.FromAmountAccountID, -model.Amount, db);

                    await BasicDAL.Inst.UnUseAmountAccount(model.FamilyID, model.ToAmountAccountID, model.Amount, db);

                    await db.SaveChangesAsync();

                    //提交事务
                    trans.Commit();

                    //移除最小交易流水日期缓存
                    this.RemoveMinTurnoverDate(familyID, model.TransferDate);

                    return(true);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 保存用户
        /// </summary>
        /// <param name="model">用户</param>
        /// <returns>主键ID</returns>
        public async Task <int> SaveUserAsync(User model)
        {
            using (IOSysContext db = new IOSysContext())
            {
                //更新
                if (model.ID > 0)
                {
                    db.Entry(model).State = EntityState.Modified;
                }
                //新增
                else
                {
                    await db.Users.AddAsync(model);
                }

                await db.SaveChangesAsync();
            }

            //移除缓存
            var key = string.Format(SysConst.Cache.UserList_FamilyID, model.FamilyID);

            CacheHelper.Remove(key);

            return(model.ID);
        }
Пример #4
0
        /// <summary>
        /// 保存支出类型
        /// </summary>
        /// <param name="list">支出类型</param>
        /// <returns>改动条数</returns>
        public async Task <int> SaveOutTypesAsync(List <OutType> list)
        {
            int retCount = 0;

            using (IOSysContext db = new IOSysContext())
            {
                foreach (var model in list)
                {
                    //更新
                    if (model.ID > 0)
                    {
                        db.Entry(model).State = EntityState.Modified;
                    }
                    //新增
                    else
                    {
                        await db.OutTypes.AddAsync(model);
                    }
                }

                retCount = await db.SaveChangesAsync();
            }

            //家庭ID
            var lstFamilyID = list.Select(m => m.FamilyID).Distinct().ToList();

            foreach (var familyID in lstFamilyID)
            {
                //移除缓存
                var key = string.Format(SysConst.Cache.OutTypeList_FamilyID, familyID);
                CacheHelper.Remove(key);
            }

            return(retCount);
        }
Пример #5
0
        /// <summary>
        /// 保存更新账户排序权重字段
        /// </summary>
        /// <param name="list">账户</param>
        /// <returns>修改条数</returns>
        public async Task <int> UpdateAmountAccountSortWeightAsync(List <AmountAccount> list)
        {
            int retCount = 0;

            using (IOSysContext db = new IOSysContext())
            {
                foreach (var model in list)
                {
                    //更新
                    if (model.ID > 0)
                    {
                        db.Entry(model).Property(m => m.SortWeight).IsModified = true;
                    }
                }

                retCount = await db.SaveChangesAsync();
            }

            //家庭ID
            var lstFamilyID = list.Select(m => m.FamilyID).Distinct().ToList();

            foreach (var familyID in lstFamilyID)
            {
                //移除缓存
                var key = string.Format(SysConst.Cache.AmountAccountList_FamilyID, familyID);
                CacheHelper.Remove(key);
            }

            return(retCount);
        }
Пример #6
0
        /// <summary>
        /// 异步添加登录日志
        /// </summary>
        /// <param name="log">登录日志</param>
        /// <returns></returns>
        public async Task AddLogAsync(LoginLog log)
        {
            using (var db = new IOSysContext())
            {
                await db.LoginLogs.AddAsync(log);

                await db.SaveChangesAsync();
            }
        }
Пример #7
0
        /// <summary>
        /// 删除支出类型
        /// </summary>
        /// <param name="model">支出类型</param>
        public async Task DeleteOutTypeAsync(OutType model)
        {
            using (IOSysContext db = new IOSysContext())
            {
                db.OutTypes.Remove(model);
                await db.SaveChangesAsync();
            }

            //移除缓存
            var key = string.Format(SysConst.Cache.OutTypeList_FamilyID, model.FamilyID);

            CacheHelper.Remove(key);
        }
Пример #8
0
        /// <summary>
        /// 删除账户
        /// </summary>
        /// <param name="model">账户</param>
        public async Task DeleteAmountAccountAsync(AmountAccount model)
        {
            using (IOSysContext db = new IOSysContext())
            {
                db.AmountAccounts.Remove(model);
                await db.SaveChangesAsync();
            }

            //移除缓存
            var key = string.Format(SysConst.Cache.AmountAccountList_FamilyID, model.FamilyID);

            CacheHelper.Remove(key);
        }
Пример #9
0
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="familyID">家庭ID</param>
        /// <param name="userID">用户ID</param>
        public async Task DeleteUserAsync(int familyID, int userID)
        {
            //获取原数据
            var model = await this.GetUserAsync(familyID, userID);

            if (model == null)
            {
                return;
            }

            //设删除标识
            model.IsDelete = true;

            using (IOSysContext db = new IOSysContext())
            {
                db.Entry(model).State = EntityState.Modified;
                await db.SaveChangesAsync();
            }

            //移除缓存
            var key = string.Format(SysConst.Cache.UserList_FamilyID, familyID);

            CacheHelper.Remove(key);
        }
Пример #10
0
        /// <summary>
        /// 保存收入信息
        /// </summary>
        /// <param name="model">收入信息</param>
        /// <returns>主键ID</returns>
        public async Task <int> SaveInComeAsync(InCome model)
        {
            using (IOSysContext db = new IOSysContext())
            {
                using (var trans = db.Database.BeginTransaction())
                {
                    InCome oldModel = null;

                    //尝试查找原数据
                    if (model.ID > 0)
                    {
                        oldModel = db.InComes.AsNoTracking().Where(m => m.ID == model.ID && m.FamilyID == model.FamilyID).FirstOrDefault();

                        if (oldModel == null)
                        {
                            model.CreatorID  = model.UpdateID.Value;
                            model.CreateTime = model.UpdateTime.Value;
                        }
                    }

                    //新增
                    if (oldModel == null)
                    {
                        //新增
                        await db.InComes.AddAsync(model);

                        //修改账户信息
                        await BasicDAL.Inst.UseAmountAccount(model.FamilyID, model.AmountAccountID, model.Amount, db);

                        ////修改收入类型信息
                        //await BasicDAL.Inst.UseInType(model.FamilyID, model.InTypeID, db);
                    }
                    //更新
                    else
                    {
                        //设置更新者信息
                        model.UpdateID   = model.UpdateID;
                        model.UpdateTime = model.UpdateTime;
                        model.CreatorID  = oldModel.CreatorID;
                        model.CreateTime = oldModel.CreateTime;

                        //更新
                        db.Entry(model).State = EntityState.Modified;

                        //修改账户信息
                        await BasicDAL.Inst.ChangeAmountAccount(model.FamilyID, model.AmountAccountID, model.Amount, oldModel.AmountAccountID, oldModel.Amount, db);

                        ////修改收入类型信息
                        //await BasicDAL.Inst.ChangeInType(model.FamilyID, model.InTypeID, oldModel.InTypeID, db);
                    }

                    //保存修改
                    await db.SaveChangesAsync();

                    //提交事务
                    trans.Commit();
                }
            }

            //更新最小交易流水日期缓存
            this.UpdateMinTurnoverDate(model.FamilyID, model.InDate);

            return(model.ID);
        }
Пример #11
0
        /// <summary>
        /// 保存借还信息
        /// </summary>
        /// <param name="model">借还信息</param>
        /// <returns>主键ID</returns>
        public async Task <int> SaveBorrowRepayAsync(BorrowRepay model)
        {
            using (IOSysContext db = new IOSysContext())
            {
                using (var trans = db.Database.BeginTransaction())
                {
                    BorrowRepay oldModel = null;

                    //尝试查找原数据
                    if (model.ID > 0)
                    {
                        oldModel = db.BorrowRepays.AsNoTracking().Where(m => m.ID == model.ID && m.FamilyID == model.FamilyID).FirstOrDefault();

                        if (oldModel == null)
                        {
                            model.CreatorID  = model.UpdateID.Value;
                            model.CreateTime = model.UpdateTime.Value;
                        }
                    }

                    //新增
                    if (oldModel == null)
                    {
                        //新增
                        await db.BorrowRepays.AddAsync(model);

                        //账户金额变动值
                        var amount = this.GetAmountDirectionForBorrowRepay(model.BRType, model.Amount);

                        //修改账户信息
                        await BasicDAL.Inst.UseAmountAccount(model.FamilyID, model.AmountAccountID, amount, db);
                    }
                    //更新
                    else
                    {
                        //设置更新者信息
                        model.UpdateID   = model.UpdateID;
                        model.UpdateTime = model.UpdateTime;
                        model.CreatorID  = oldModel.CreatorID;
                        model.CreateTime = oldModel.CreateTime;

                        //更新
                        db.Entry(model).State = EntityState.Modified;

                        //账户金额变动值
                        var newAmount = this.GetAmountDirectionForBorrowRepay(model.BRType, model.Amount);
                        var oldAmount = this.GetAmountDirectionForBorrowRepay(oldModel.BRType, oldModel.Amount);

                        //修改账户信息
                        await BasicDAL.Inst.ChangeAmountAccount(model.FamilyID, model.AmountAccountID, newAmount, oldModel.AmountAccountID, oldAmount, db);
                    }

                    //保存修改
                    await db.SaveChangesAsync();

                    //提交事务
                    trans.Commit();
                }
            }

            //更新最小交易流水日期缓存
            this.UpdateMinTurnoverDate(model.FamilyID, model.BRDate);

            return(model.ID);
        }