Beispiel #1
0
        public async Task <List <BillGetResponse> > GetGroupBillsAsync(int groupid)
        {
            var billlist = new List <BillGetResponse>();
            var bills    = _Context.bills.Where(c => c.groupId == groupid)
                           .OrderByDescending(c => c.bill_created_at).ToList();

            for (var j = 0; j < bills.Count; j++)
            {
                BillGetResponse bill = new BillGetResponse();
                bill = await GetBillAsync(bills[j].billid);

                //bill.billid = bills[j].billid;
                //bill.bill_created_at = bills[j].bill_created_at;

                //var detail = new Detail();
                //var nameid = _Context.users.SingleOrDefault(c => c.userid == bills[j].bill_created_byId);
                //detail.name = nameid.user_name;
                //detail.id = nameid.userid;

                //bill.bill_created_by = detail;

                //var detail1 = new Detail();
                //var nameid1 = _Context.users.SingleOrDefault(c => c.userid == bills[j].bill_updated_byId);
                //detail1.name = nameid1.user_name;
                //detail1.id = nameid1.userid;

                //bill.bill_updated_by = detail1;

                //var nameid2 = _Context.groups.SingleOrDefault(c => c.groupid == bills[j].groupId);
                //var detail2 = new Detail();
                //detail2.id = nameid2.groupid;
                //detail2.name = nameid2.group_name;
                //bill.group = detail2;

                //bill.bill_date = bills[j].bill_date;
                //bill.bill_updated_at = bills[j].bill_updated_at;
                //bill.description = bills[j].description;
                //bill.total_amount = bills[j].total_amount;
                //billlist.Add(bill);

                //var x = _Context.users.Where(c => c.paid_by_id.Any(y => y.billId == bills[j].billid)).ToList();
                //var pay = new List<BillDetail>();
                //for (int i = 0; i < x.Count; i++)
                //{
                //    BillDetail billDetail = new BillDetail();
                //    var y = _Context.users.SingleOrDefault(c => c.userid == x[i].userid);
                //    billDetail.id = y.userid;
                //    billDetail.name = y.user_name;
                //    var amtid = _Context.payers.SingleOrDefault(c => c.billId == bills[j].billid && c.paid_byId == x[i].userid);
                //    billDetail.amount = amtid.amount_paid;
                //    pay.Add(billDetail);
                //}
                //bill.payers = pay;

                //var p = _Context.users.Where(c => c.shared_with.Any(y => y.billId == bills[j].billid)).ToList();
                //var share = new List<BillDetail>();
                //for (int i = 0; i < p.Count; i++)
                //{
                //    BillDetail billDetail = new BillDetail();
                //    var y = _Context.users.SingleOrDefault(c => c.userid == p[i].userid);
                //    billDetail.id = y.userid;
                //    billDetail.name = y.user_name;
                //    var amtid = _Context.sharedWiths.SingleOrDefault(c =>
                //    c.billId == bills[j].billid && c.shared_withId == p[i].userid);
                //    billDetail.amount = amtid.owes_amount;
                //    share.Add(billDetail);
                //}
                //bill.sharedwiths = share;
                billlist.Add(bill);
            }
            return(billlist);
        }
Beispiel #2
0
        public async Task <BillGetResponse> GetBillAsync(int billid)
        {
            BillGetResponse bill  = new BillGetResponse();
            var             bills = await _Context.bills.SingleOrDefaultAsync(c => c.billid == billid);

            if (bills.groupId != null)
            {
                var nameid2 = _Context.groups.SingleOrDefault(c => c.groupid == bills.groupId);
                var detail2 = new Detail();
                detail2.id   = nameid2.groupid;
                detail2.name = nameid2.group_name;
                bill.group   = detail2;
            }
            bill.billid          = bills.billid;
            bill.bill_created_at = bills.bill_created_at;

            var detail = new Detail();
            var nameid = _Context.users.SingleOrDefault(c => c.userid == bills.bill_created_byId);

            detail.name = nameid.user_name;
            detail.id   = nameid.userid;

            bill.bill_created_by = detail;

            var detail1 = new Detail();
            var nameid1 = _Context.users.SingleOrDefault(c => c.userid == bills.bill_updated_byId);

            detail1.name = nameid1.user_name;
            detail1.id   = nameid1.userid;

            bill.bill_updated_by = detail1;

            var x   = _Context.users.Where(c => c.paid_by_id.Any(y => y.billId == bills.billid)).ToList();
            var pay = new List <BillDetail>();

            for (int i = 0; i < x.Count; i++)
            {
                BillDetail billDetail = new BillDetail();
                var        y          = _Context.users.SingleOrDefault(c => c.userid == x[i].userid);
                billDetail.id   = y.userid;
                billDetail.name = y.user_name;
                var amtid = _Context.payers.SingleOrDefault(c =>
                                                            c.billId == bills.billid && c.paid_byId == x[i].userid);
                billDetail.amount = amtid.amount_paid;
                pay.Add(billDetail);
            }
            bill.payers = pay;

            var p     = _Context.users.Where(c => c.shared_with.Any(y => y.billId == bills.billid)).ToList();
            var share = new List <BillDetail>();

            for (int i = 0; i < p.Count; i++)
            {
                BillDetail billDetail = new BillDetail();
                var        y          = _Context.users.SingleOrDefault(c => c.userid == p[i].userid);
                billDetail.id   = y.userid;
                billDetail.name = y.user_name;
                var amtid = _Context.sharedWiths.SingleOrDefault(c =>
                                                                 c.billId == bills.billid && c.shared_withId == p[i].userid);
                billDetail.amount = amtid.owes_amount;
                share.Add(billDetail);
            }
            bill.sharedwiths = share;

            bill.bill_date       = bills.bill_date;
            bill.bill_updated_at = bills.bill_updated_at;
            bill.description     = bills.description;
            bill.total_amount    = bills.total_amount;
            return(bill);
        }