Ejemplo n.º 1
0
        public static WithdrawalsDTO GetById(int id)
        {
            WithdrawalsDTO withdrawalsDTO = new WithdrawalsDTO();
            db             DB             = new db();
            var            withdrawal     = DB.Withdrawing.FirstOrDefault(w => w.Id == id);

            withdrawalsDTO = WithdrawalsConvert.DALtoDTO(withdrawal);
            return(withdrawalsDTO);
        }
Ejemplo n.º 2
0
 public ActionResult Add([FromBody] WithdrawalsDTO withdrawal)
 {
     try
     {
         WithdrawalsBL.Add(withdrawal);
         return(Ok());
     }
     catch (Exception e)
     {
         return(BadRequest(e.ToString()));
     }
 }
Ejemplo n.º 3
0
        public static List <WithdrawalsDTO> GetByUser(int userId)
        {
            List <WithdrawalsDTO> withdrawalsDTOs = new List <WithdrawalsDTO>();
            db DB = new db();
            List <withdrawing> withdrawals = DB.Withdrawing.Where(w => w.UserId == userId).ToList();

            foreach (withdrawing withdrawal in withdrawals)
            {
                WithdrawalsDTO withdrawalDTO = WithdrawalsConvert.DALtoDTO(withdrawal);
                withdrawalDTO.Fund = DB.Funds.FirstOrDefault(f => f.FundId == withdrawal.FundId).fund_name;
                withdrawalsDTOs.Add(withdrawalDTO);
            }
            return(withdrawalsDTOs);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        public static List <WithdrawalsDTO> GetByFund(string FundId)
        {
            List <WithdrawalsDTO> withdrawalsDTOs = new List <WithdrawalsDTO>();
            db DB = new db();
            List <withdrawing> withdrawals = DB.Withdrawing.Where(w => w.FundId == FundId).ToList();

            foreach (withdrawing withdrawal in withdrawals)
            {
                WithdrawalsDTO withdrawalDTO = WithdrawalsConvert.DALtoDTO(withdrawal);

                //  User_in_fund  User= DB.User_in_fund.FirstOrDefault(u => u.userID == withdrawal.UserId);
                // withdrawalDTO.User = UserBL.Get_user_byFund(FundId, withdrawal.UserId);
                withdrawalsDTOs.Add(withdrawalDTO);
            }
            return(withdrawalsDTOs);
        }
Ejemplo n.º 8
0
        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();
        }
Ejemplo n.º 9
0
        public ActionResult GetById([FromQuery] int id)
        {
            WithdrawalsDTO Withdrawals = WithdrawalsBL.GetById(id);

            return(Ok(Withdrawals));
        }