public static void Add(WithdrawalsDTO withdrawalDTO) { withdrawing withdrawal = WithdrawalsConvert.DTOtoDAL(withdrawalDTO); db DB = new db(); DB.Withdrawing.Add(withdrawal); DB.SaveChanges(); if (withdrawalDTO.Status == "performed") { FundBL.Subtract_Balance(withdrawalDTO.Amount, withdrawalDTO.FundId); User_in_fund user = DB.UserInFunds.FirstOrDefault(u => u.UserId == withdrawal.UserId && u.FundId == withdrawal.FundId); user.balance -= withdrawal.Amount; } DB.SaveChanges(); }
public static void Updete(WithdrawalsDTO withdrawalDTO) { db DB = new db(); withdrawing withdrawal = DB.Withdrawing.FirstOrDefault(w => w.Id == withdrawalDTO.Id); //if it changed to Approved if (withdrawal.NameStatus != "performed" && withdrawalDTO.Status == "performed") { FundBL.Subtract_Balance(withdrawalDTO.Amount, withdrawalDTO.FundId); } else { //if it was performed and changed to canceled if (withdrawal.NameStatus == "performed" && withdrawalDTO.Status == "canceled") { FundBL.AddBalance(withdrawalDTO.Amount, withdrawalDTO.FundId); } } withdrawal.Amount = withdrawalDTO.Amount; withdrawal.Date = withdrawalDTO.Date; // withdrawal.paymentMethod = withdrawalDTO.PaymentMethod; withdrawal.NameStatus = withdrawalDTO.Status; DB.SaveChanges(); }