示例#1
0
        public async Task <IActionResult> makeAdmin(int id)
        {
            User userRepo = await _repo.getUser(id);

            if (userRepo == null)
            {
                return(BadRequest("User not found"));
            }

            userRepo.Role = "admin";
            _repo.Update <User>(userRepo);
            return(Ok(await _repo.SaveAll()));
        }
 public async Task <IActionResult> updateVehicle([FromBody] Vehicle vehicle)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _repo.Update <Vehicle>(vehicle);
     return(Ok(await _repo.SaveAll()));
 }
 public async Task <IActionResult> updatePlaza([FromBody] Plaza plaza)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _repo.Update <Plaza>(plaza);
     if (await _repo.SaveAll())
     {
         return(Ok());
     }
     return(BadRequest("Failed to Add plaza"));
 }
        private async Task <bool> chargeUserAccount(int userId, double amount)
        {
            User userToCharge = await _repo.getUser(userId);

            userToCharge.AccountBalance -= amount;

            _repo.Update <User>(userToCharge);
            if (await _repo.SaveAll())
            {
                if (userToCharge.AccountBalance < 0)
                {
                    _sms.sendMessage($" Insufficient fund, your account balance is below zero, please Recharge as soon as possible  {amount}", $"{userToCharge.PhoneNumber}");
                    return(false);
                }
                else
                {
                    _sms.sendMessage($" THANK YOU. your toll account was successfully charged {amount}", $"{userToCharge.PhoneNumber}");
                    return(true);
                }
            }
            _sms.sendMessage($" An error occured charging your account please pay {amount}, manually", $"{userToCharge.PhoneNumber}");
            return(false);
        }