Skip to content

Instantly share code, notes, and snippets.

@ashkanRmk
Created January 3, 2018 19:56
Show Gist options
  • Save ashkanRmk/c633f804a0e76dbf200f714b905ca9e6 to your computer and use it in GitHub Desktop.
Save ashkanRmk/c633f804a0e76dbf200f714b905ca9e6 to your computer and use it in GitHub Desktop.
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using System.Globalization;
using System.Data.EntityClient;
using System.Data.SqlClient;
using System.Data.Common;
using Payments.DomainClasses.Entity;
namespace PayPing.Ipg.Entities
{
public class Wrapper
{
public async Task<IEnumerable<Withdraw>> query(int userID)
{
var allDailyPayment = await _payments.GetAllQueryable()
.Where(payment => payment.IsBusiness == false && payment.IsRepaid == true
&& payment.UserID == userID)
.GroupBy(payment => payment.PayDate).ToListAsync();
var withdrawLists = new List<Withdraw>();
var sumAmount = 0;
var checkedDays = new List<int>();
bool insert = false;
foreach (var item in allDailyPayment)
{
insert = false;
sumAmount = 0;
foreach (var p in allDailyPayment)
{
if (item.PayDate.Day == p.PayDate.Day && !checkedDays.Contains(item.PayDate.Day))
{
sumAmount += p.Amount;
insert = true;
}
}
checkedDays.add(item.PayDate.Day);
if (insert)
{
var tempWithdraw = new Withdraw{
Amount = sumAmount,
RepayDate = ReqDate = CreatedDate = ModifiedDate = item.PayDate,
IsRepaid = true,
RefId = item.RefId,
UserID = item.UserID,
};
withdrawLists.add(tempWithdraw);
_contex.Withdraws.add(tempWithdraw);
}
}
await _contex.SaveChangesAsync();
return withdrawLists;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment