コード例 #1
0
        public async Task <bool> DeleteGroupAsync(int id)
        {
            var group = await _Context.group.SingleOrDefaultAsync(g => g.groupID == id);

            _Context.Remove(group);
            try
            {
                return(await _Context.SaveChangesAsync() > 0 ? true : false);
            }
            catch (System.Exception exp)
            {
                _Logger.LogError($"Error in {nameof(DeleteGroupAsync)}: " + exp.Message);
            }
            return(false);
        }
コード例 #2
0
        public async Task <bool> DeleteUserAsync(int id)
        {
            var user = await _Context.User
                       .Include(c => c.BillMembers)
                       .Include(c => c.Bills)
                       .Include(c => c.Friends)
                       .Include(c => c.groupMembers)
                       .Include(c => c.Groups)
                       .Include(c => c.Payers)
                       .Include(c => c.Payersdata)
                       .Include(c => c.SharedMembers)
                       .Include(c => c.TPayers)
                       .Include(c => c.TReceivers)
                       .Include(c => c.Users)
                       .SingleOrDefaultAsync(c => c.UserId == id);

            _Context.Remove(user);

            try
            {
                return(await _Context.SaveChangesAsync() > 0 ? true : false);
            }
            catch (System.Exception exp)
            {
                _Logger.LogError($"Error in {nameof(DeleteUserAsync)}: " + exp.Message);
            }
            return(false);
        }
コード例 #3
0
        public async Task <bool> DeleteGroupAsync(int id)
        {
            var sData = await _Context.Settlement.Where(c => c.GroupId == id).ToListAsync();

            if (sData.Count > 0)
            {
                for (var i = 0; i < sData.Count; i++)
                {
                    _Context.Remove(sData[i]);
                }
                await _Context.SaveChangesAsync();
            }

            var billData = await _Context.Expense.Where(c => c.GroupId == id).ToListAsync();

            if (billData.Count > 0)
            {
                for (var i = 0; i < billData.Count; i++)
                {
                    _Context.Remove(billData[i]);
                }
                await _Context.SaveChangesAsync();
            }

            var transData = await _Context.Transactions.Where(c => c.GroupId == id).ToListAsync();

            if (transData.Count > 0)
            {
                for (var i = 0; i < transData.Count; i++)
                {
                    _Context.Remove(transData[i]);
                }
                await _Context.SaveChangesAsync();
            }
            var group = await _Context.Group.SingleOrDefaultAsync(c => c.GroupId == id);

            _Context.Remove(group);
            try
            {
                return(await _Context.SaveChangesAsync() > 0 ? true : false);
            }
            catch (System.Exception exp)
            {
                _Logger.LogError($"Error in {nameof(DeleteGroupAsync)}: " + exp.Message);
            }
            return(false);
        }
コード例 #4
0
        public async Task <bool> DeleteFriendAsync(int fid, int uid)
        {
            var data = _Context.Friend.SingleOrDefault(c => c.UserId == uid && c.FriendId == fid);

            if (data == null)
            {
                var fData = _Context.Friend.SingleOrDefault(c => c.UserId == fid && c.FriendId == uid);
                _Context.Remove(fData);
            }
            else
            {
                _Context.Remove(data);
            }
            try
            {
                return(await _Context.SaveChangesAsync() > 0 ? true : false);
            }
            catch (System.Exception exp)
            {
                _Logger.LogError($"Error in {nameof(DeleteFriendAsync)}: " + exp.Message);
            }
            return(false);
        }
コード例 #5
0
        public async Task <bool> DeleteExpenseAsync(int id)
        {
            var expense = await _Context.expense.SingleOrDefaultAsync(c => c.expenseID == id);

            _Context.Remove(expense);
            try
            {
                return(await _Context.SaveChangesAsync() > 0 ? true : false);
            }
            catch (System.Exception exp)
            {
                _Logger.LogError($"Error in {nameof(DeleteExpenseAsync)}: " + exp.Message);
            }
            return(false);
        }