public static withdrawing DTOtoDAL(WithdrawalsDTO withdrawalsDTO) { withdrawing withdrawal = new withdrawing() { Amount = withdrawalsDTO.Amount, Date = withdrawalsDTO.Date, FundId = withdrawalsDTO.FundId, NameStatus = withdrawalsDTO.Status, UserId = withdrawalsDTO.FriendId, // =withdrawalsDTO.PaymentMethod }; return(withdrawal); }
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 WithdrawalsDTO DALtoDTO(withdrawing withdrawal) { WithdrawalsDTO withdrawalsDTO = new WithdrawalsDTO() { FriendId = withdrawal.UserId, // Status = withdrawal.NameStatus, Amount = withdrawal.Amount, // PaymentMethod = withdrawal.paymentMethod, Id = withdrawal.Id, Date = withdrawal.Date, FundId = withdrawal.FundId }; return(withdrawalsDTO); }
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(); }