public virtual bool Insert(T entity) { try { _dbContext.Add(entity); _dbContext.SaveChanges(); return(true); } catch (Exception ex) { _logger.LogError("Insertion Failed. Please check error Message" + ex.Message, entity); return(false); } }
public string MakePayment(PaymentBM payment) { Payment newPayment = null; //Payment to this account var payeeAccount = _context.Account.Where(x => x.AccountNumber == payment.PayeeAccountNumber).FirstOrDefault(); //Payment from this account var payorAccount = _context.Account.Where(x => x.AccountNumber == payment.PayorAccountNumber).FirstOrDefault(); string transactionId = ""; if (payorAccount != null && payeeAccount != null) { var paymentMethodId = _context.PaymentMethod.Where(x => x.PaymentMethodCode == payment.PaymentMethod).Select(x => x.Id).FirstOrDefault(); var statusId = _context.PaymentStatus.Where(x => x.Status == PaymentSatus.Completed.ToString()).Select(x => x.Id).FirstOrDefault(); //ToDo: Below needs to be reviewed and removed if not needed transactionId = PaymentHelper.GenerateTransactionId(); if (_context.Payment.Any(x => x.TransactionId == transactionId)) { transactionId = PaymentHelper.GenerateTransactionId(); } payeeAccount.CurrentBalance = payment.TransactionType == TransactionType.Credit.ToString() ? payeeAccount.CurrentBalance + payment.Amount : payeeAccount.CurrentBalance - payment.Amount; payorAccount.CurrentBalance = payment.TransactionType == TransactionType.Credit.ToString() ? payorAccount.CurrentBalance - payment.Amount : payorAccount.CurrentBalance + payment.Amount; newPayment = new Payment { PayorAccountId = payorAccount.Id, PayorCustomerId = payorAccount.CustomerId.Value, PayeeAccountId = payeeAccount.Id, PayeeCustomerId = payeeAccount.CustomerId.Value, PaymentMethodId = paymentMethodId, PaymentStatusId = statusId, PaymentAmount = payment.Amount, TransactionId = transactionId, PaymentDate = payment.PaymentDate.IsDate() ? Convert.ToDateTime(payment.PaymentDate) : DateTime.Now, TransactionType = payment.TransactionType, Remarks = $"Amount {payment.Amount.ToString()} has been {payment.TransactionType}ed to account {payment.PayeeAccountNumber}. The current balance is {payeeAccount.CurrentBalance} in Payee account {payment.PayeeAccountNumber}. The current balance is {payorAccount.CurrentBalance} in Payor account {payment.PayeeAccountNumber}." }; _context.Payment.Add(newPayment); _context.SaveChanges(); } return(newPayment != null && newPayment.Id != null ? transactionId : string.Empty); }
/// <summary> /// This will save the changes made to the database context. /// </summary> /// <returns></returns> public bool SaveChanges() { try { return(_context.SaveChanges() > 0); } catch (DbUpdateConcurrencyException ex) { _logger.LogError("SaveChange", ex); } catch (Exception ex) { _logger.LogError("SaveChange", ex); } return(false); }
public HttpResponseMessage Post([FromBody] ReqProp reqProp) { try { PaymentState payState = new PaymentState(); HttpResponseMessage message; if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } bool reqValid = VerifyPaymentReq.ShouldPaymentProcess(reqProp); if (reqValid) { double _amount = reqProp.amount; if (_amount < 20) { } else if (_amount >= 21 && _amount <= 500) { } else { } db.reqProps.Add(reqProp); message = Request.CreateResponse(HttpStatusCode.OK); } else { message = Request.CreateResponse(HttpStatusCode.BadRequest); } payState.state = message.ToString(); db.paymentStates.Add(payState); db.SaveChanges(); return(message); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }
public int Save() { int isSave = 0; try { isSave = DBContext.SaveChanges(); return(isSave); } catch (DbEntityValidationException DBContext) { foreach (var validationErrors in DBContext.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { System.Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } return(isSave); } }
public void Save() { Context.SaveChanges(); }