public DTOresellerSentVoucher_withUserDetails(DTOvouchertransaction voucherTransaction, DTOuser user) { amount = voucherTransaction.transactionAmount; dateSent = voucherTransaction.transactionDate; userFirstName = user.userFirstName; userName = user.userName; }
public async Task <DTOvouchertransaction> Postvouchertransaction(DTOvouchertransaction newDTO) { vouchertransaction newProd = EntityMapper.updateEntity(null, newDTO); db.vouchertransactions.Add(newProd); await db.SaveChangesAsync(); return(newDTO); }
public async Task <IHttpActionResult> Putvouchertransaction(int ID, DTOvouchertransaction editedDTO) { vouchertransaction toUpdate = db.vouchertransactions.Find(ID); toUpdate = EntityMapper.updateEntity(toUpdate, editedDTO); db.Entry(toUpdate).State = EntityState.Modified; await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); }
public static vouchertransaction updateEntity(vouchertransaction entityObjct, DTOvouchertransaction dto) { if (entityObjct == null) { entityObjct = new vouchertransaction(); } entityObjct.Voucher_ID = dto.Voucher_ID; entityObjct.VoucherSentTo = dto.VoucherSentTo; entityObjct.Sender_ID = dto.Sender_ID; entityObjct.Receiver_ID = dto.Receiver_ID; entityObjct.TransactionType_ID = dto.TransactionType_ID; entityObjct.transactionAmount = dto.transactionAmount; entityObjct.transactionDescription = dto.transactionDescription; entityObjct.transactionDate = dto.transactionDate; return(entityObjct); }
public IHttpActionResult getSentBulkVoucherUserDetails(int resellerUserID) { if (isUserReseller(resellerUserID)) { List <vouchertransaction> rawVoucherTransactionList = (from c in db.vouchertransactions where c.Sender_ID == resellerUserID && c.TransactionType_ID == 2 orderby c.VoucherSentTo select c).ToList(); if (rawVoucherTransactionList == null) { return(NotFound()); } else { List <DTOvouchertransaction> voucherTransactionList = new List <DTOvouchertransaction>(); int voucherSentToID = rawVoucherTransactionList.First().VoucherSentTo; decimal tmpTransactionValue = 0; int index = 0; foreach (vouchertransaction vt in rawVoucherTransactionList) { if (index + 1 == rawVoucherTransactionList.Count) { tmpTransactionValue += Math.Abs(vt.transactionAmount); DTOvouchertransaction tmpVoucherTransaction = new DTOvouchertransaction(); tmpVoucherTransaction.Sender_ID = rawVoucherTransactionList.ElementAt(index - 1).Sender_ID; tmpVoucherTransaction.Receiver_ID = rawVoucherTransactionList.ElementAt(index - 1).Receiver_ID; tmpVoucherTransaction.TransactionType_ID = 2; tmpVoucherTransaction.transactionAmount = tmpTransactionValue; tmpVoucherTransaction.transactionDate = rawVoucherTransactionList.ElementAt(index - 1).transactionDate; tmpVoucherTransaction.VoucherSentTo = rawVoucherTransactionList.ElementAt(index - 1).VoucherSentTo; voucherTransactionList.Add(tmpVoucherTransaction); } else if (voucherSentToID == vt.VoucherSentTo) { tmpTransactionValue += Math.Abs(vt.transactionAmount); } else { DTOvouchertransaction tmpVoucherTransaction = new DTOvouchertransaction(); tmpVoucherTransaction.Sender_ID = rawVoucherTransactionList.ElementAt(index - 1).Sender_ID; tmpVoucherTransaction.Receiver_ID = rawVoucherTransactionList.ElementAt(index - 1).Receiver_ID; tmpVoucherTransaction.TransactionType_ID = 2; tmpVoucherTransaction.transactionAmount = tmpTransactionValue; tmpVoucherTransaction.transactionDate = rawVoucherTransactionList.ElementAt(index - 1).transactionDate; tmpVoucherTransaction.VoucherSentTo = rawVoucherTransactionList.ElementAt(index - 1).VoucherSentTo; voucherTransactionList.Add(tmpVoucherTransaction); voucherSentToID = vt.VoucherSentTo; tmpTransactionValue = Math.Abs(vt.transactionAmount); } index++; } List <DTOresellerSentVoucher_withUserDetails> list = new List <DTOresellerSentVoucher_withUserDetails>(); foreach (DTOvouchertransaction v in voucherTransactionList) { DTOuser tmp = new DTOuser(db.users.Single(x => v.Receiver_ID == x.User_ID)); list.Add(new DTOresellerSentVoucher_withUserDetails(v, tmp)); } return(Ok(list)); } } else { return(BadRequest("User is not a valid reseller")); } }