public ChampionshipController() { this.motorcycleRepository = new MotorcycleRepository(); this.riderRepository = new RiderRepository(); this.raceRepository = new RaceRepository(); this.riders = new List <IRider>(); }
public static void Main() { var raceRepo = new RaceRepository(); var riderRepo = new RiderRepository(); var motorcycleRepo = new MotorcycleRepository(); var raceFactory = new RaceFactory(); var riderFactory = new RiderFactory(); var motorcycleFactory = new MotorcycleFactory(); var championshipController = new ChampionshipController( raceRepo, riderRepo, motorcycleRepo, raceFactory, riderFactory, motorcycleFactory); var consoleReader = new ConsoleReader(); var consoleWriter = new ConsoleWriter(); var engine = new Engine( championshipController, consoleReader, consoleWriter); engine.Run(); }
public static void Main(string[] args) { IReader reader = new ConsoleReader(); IWriter writer = new ConsoleWriter(); IRepository <IMotorcycle> motorcycleRepository = new MotorcycleRepository(); IRepository <IRace> raceRepository = new RaceRepository(); IRepository <IRider> riderRepository = new RiderRepository(); MotorcycleFactory motorcycleFactory = new MotorcycleFactory(); // Judge system does not require dependency inversion principle to be observed! // Also Factories and CommandInterpreter are not required! IChampionshipController championshipController = new ChampionshipController( motorcycleRepository, raceRepository, riderRepository, motorcycleFactory); ICommandInterpreter commandInterpreter = new CommandInterpreter(championshipController); IEngine engine = new Engine(commandInterpreter, reader, writer); engine.Run(); }
public static void Main(string[] args) { //TODO Add IEngine //Motorcycle varche = new PowerMotorcycle("12214235", 75); //Console.WriteLine(varche.HorsePower); IMotorcycleFactory motorcycleFactory = new MotorcycleFactory(); IRaceFactory raceFactory = new RaceFactory(); IRiderFactory riderFactory = new RiderFactory(); MotorcycleRepository motorcycleRepository = new MotorcycleRepository(); RaceRepository raceRepository = new RaceRepository(); RiderRepository riderRepository = new RiderRepository(); IChampionshipController controller = new ChampionshipController( motorcycleFactory, raceFactory, riderFactory, motorcycleRepository, raceRepository, riderRepository); IReader reader = new ConsoleReader(); IWriter writer = new ConsoleWriter(); IEngine engine = new Engine(reader, writer, controller); engine.Run(); }
private static Rider InitRider(string email, string lastName, string firstName) { var repository = new RiderRepository(); var rider = new Rider { Email = email, LastName = lastName, FirstName = firstName }; repository.Add(rider); return(rider); }
public ChampionshipController() { this.raceFactory = new RaceFactory(); this.riderFactory = new RiderFactory(); this.motorcycleFactory = new MotorcycleFactory(); this.motorcycleRepository = new MotorcycleRepository(); this.raceRepository = new RaceRepository(); this.riderRepository = new RiderRepository(); }
public ChampionshipController() { motorcycleRepo = new MotorcycleRepository(); raceRepo = new RaceRepository(); riderRepo = new RiderRepository(); motorcycleFactory = new MotorcycleFactory(); raceFactory = new RaceFactory(); riderFactory = new RiderFactory(); }
public async Task <AppUserDto> RegisterAsync(UserCreateDto input, RiderCreateDto riderCreateDto) { var userDto = await base.RegisterAsync(input); var userE = await UserManager.FindByNameAsync(userDto.UserName); await UserManager.AddToRoleAsync(userE, RolesConsts.Rider); var cityDto = await CityRepository.FindAsync(riderCreateDto.CityID) ?? throw new BusinessException("Invalid city"); await RiderRepository.InsertAsync(new RiderEntity(userDto.Id, riderCreateDto.Geolocation, cityDto.Id), autoSave : true); return(userDto); }
public static async Task <IActionResult> RiderCreate([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req) { // req.IsValidToken(); //Rider user = await req.Content.ReadAsAsync<Rider>(); string requestBody = new StreamReader(req.Body).ReadToEnd(); Rider user = JsonConvert.DeserializeObject <Rider>(requestBody); await RiderRepository <Rider> .Initialize(); if (user == null) { return((ActionResult) new OkObjectResult("User cannot be null or empty")); } if (string.IsNullOrEmpty(user.Email)) { return((ActionResult) new OkObjectResult("An email address is needed for this request")); } var udb = RiderRepository <Rider> .GetItems($"Select * from RiderData u where u.Email = '{user.Email}'"); if (udb != null && udb.Count() > 0) { return((ActionResult) new OkObjectResult("Rider already exist, please login or activate account to continue")); } if (string.IsNullOrEmpty(user.Password)) { return((ActionResult) new OkObjectResult("A Password is needed for this request")); } user.Password = user.Password.EncodeString(); user.LastModified = DateTime.Now; user.IsActivated = true; try { dynamic u = await RiderRepository <Rider> .CreateItemAsync(user); return((ActionResult) new OkObjectResult("Your account has been created. Admin will contact via the number provided to complete the activation process.")); } catch (Exception ex) { return((ActionResult) new OkObjectResult("An error has occured")); } }
public ChampionshipController( IMotorcycleFactory motorcycleFactory, IRaceFactory raceFactory, IRiderFactory riderFactory, MotorcycleRepository motorcycleRepository, RaceRepository raceRepository, RiderRepository riderRepository) { this.motorcycleFactory = motorcycleFactory; this.raceFactory = raceFactory; this.riderFactory = riderFactory; this.motorcycleRepository = motorcycleRepository; this.raceRepository = raceRepository; this.riderRepository = riderRepository; }
public static async Task <IActionResult> GetConnectedRiders([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req) { req.IsValidToken(); try { // User user = await req.Content.ReadAsAsync<Driver>(); await RiderRepository <Rider> .Initialize(); var drivers = RiderRepository <Rider> .GetItems("Select * from RiderData d where d.Status <> 'busy' or d.Status <> 'offline' "); if (drivers == null || drivers.Count() <= 0) { return((ActionResult) new OkObjectResult("No Avilable Riders In The System.")); } return((ActionResult) new OkObjectResult(drivers)); } catch (Exception ex) { return((ActionResult) new OkObjectResult(ex)); } }
public static async Task <IActionResult> GetAllRiders([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req) { req.IsValidToken(); try { //User user = await req.Content.ReadAsAsync<User>(); await RiderRepository <Rider> .Initialize(); var riders = await RiderRepository <Rider> .GetItemsAsync(); if (riders == null || riders.Count() <= 0) { return((ActionResult) new OkObjectResult("No Avilable Riders In The System.")); } return((ActionResult) new OkObjectResult(riders)); } catch (Exception ex) { return((ActionResult) new OkObjectResult(ex)); } }
public virtual async Task <DeliveryChargeEntity> CalculateAsync(int addressId, int deliveryScheduleId, float subtotal, bool hasPromotion = false) { var addrE = await AddressRepository.FindAsync(addressId) ?? throw new EntityNotFoundException(); var dScheduleE = await DeliveryScheduleRepository.FindAsync(deliveryScheduleId) ?? throw new EntityNotFoundException(); var riderEs = await RiderRepository.GetRidersForTheCity(addrE.CityID); var meanDistance = GetMeanDistance(addrE, riderEs); var distanceChargeE = await AsyncExecutor.LastOrDefaultAsync(DistanceChargeRepository .Where(e => e.From < meanDistance) .OrderBy(e => e.From)); var subtotalPercentageE = await AsyncExecutor.LastOrDefaultAsync(SubtotalPercentageRepository.Where(e => e.From < subtotal) .OrderBy(e => e.From)); var charge = subtotal * subtotalPercentageE.Percentage; charge += (hasPromotion)? 0 : distanceChargeE.Charge; charge += charge * dScheduleE.CostIncreasePercentage; return(new DeliveryChargeEntity(charge, distanceChargeE.Id, subtotalPercentageE.Id, dScheduleE.Id)); }
public static async Task <IActionResult> RunAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req) { try { await DriverRepository <Driver> .Initialize(); await RiderRepository <Rider> .Initialize(); await UserRepository <User> .Initialize(); string token = req.Query["token"]; if (string.IsNullOrEmpty(token)) { return((ActionResult) new OkObjectResult("Please set the token feild as a query parameter '?token='")); } string decode = string.Empty; try { decode = token.DecodeString(); } catch (Exception) { return((ActionResult) new OkObjectResult("Invalid base64 Token")); } var parts = decode.Split(':'); //return req.CreateResponse(HttpStatusCode.OK, parts); if (parts == null || parts.Count() <= 0) { return((ActionResult) new OkObjectResult("Token Is invalid")); } var email = parts[0]; var password = parts[1]; var type = parts[2]; DisplayUser ds = null; if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(type)) { return((ActionResult) new OkObjectResult("Token failed")); } password = password.EncodeString(); if (type.ToLower().Equals("user")) { var u = UserRepository <User> .GetItems($"Select * from UserData u where u.Email = '{email}' and u.Password = '******' and u.IsActivated = true"); if (u == null || u.Count() <= 0) { return((ActionResult) new OkObjectResult("Failed To locate a user with the provide credentials or user is nnot yet activated")); } var fs = u.FirstOrDefault(); ds = new DisplayUser() { Firstname = fs.Firstname, Lastname = fs.Lastname, id = fs.id, DateCreated = fs.DateCreated, Email = fs.Email, //IsLoggedIn = fs.IsLoggedIn, IsActivated = fs.IsActivated, LastModified = fs.LastModified ?? null, Phone = fs.Phone //Status = fs.Status }; var updateUser = await UserRepository <User> .GetItemAsync(ds.id); if (updateUser != null) { updateUser.IsLoggedIn = true; await UserRepository <User> .UpdateItemAsync(updateUser.id, updateUser); } //return req.CreateResponse(HttpStatusCode.OK, ds); } else if (type.ToLower().Equals("rider")) { var u = RiderRepository <Rider> .GetItems($"Select * from RiderData u where u.Email = '{email}' and u.Password = '******' and u.IsActivated = true "); if (u == null || u.Count() <= 0) { return((ActionResult) new OkObjectResult("Failed To locate a user with the provide credentials or user is nnot yet activated")); } var fs = u.FirstOrDefault(); ds = new DisplayUser() { Firstname = fs.Firstname, Lastname = fs.Lastname, id = fs.id, DateCreated = fs.DateCreated, Email = fs.Email, IsLoggedIn = fs.IsLoggedIn, IsActivated = fs.IsActivated, LastModified = fs.LastModified ?? null, Phone = fs.Phone, Status = fs.Status }; } else if (type.ToLower().Equals("driver")) { var u = DriverRepository <Driver> .GetItems($"Select * from DriverData u where u.Email = '{email}' and u.Password = '******' and u.IsActivated = true"); if (u == null || u.Count() <= 0) { return((ActionResult) new OkObjectResult("Failed To locate a user with the provide credentials or user is nnot yet activated")); } var fs = u.FirstOrDefault(); ds = new DisplayUser() { Firstname = fs.Firstname, Lastname = fs.Lastname, id = fs.id, DateCreated = fs.DateCreated, Email = fs.Email, IsLoggedIn = fs.IsLoggedIn, IsActivated = fs.IsActivated, LastModified = fs.LastModified ?? null, Phone = fs.Phone, Status = fs.Status }; } else { return((ActionResult) new OkObjectResult("invalid login type")); } if (ds == null) { return((ActionResult) new OkObjectResult("Login failed no user located, sorry.")); } try { string key = Environment.GetEnvironmentVariable("Secret"); var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key)); var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature); var header = new JwtHeader(credentials); var claim = new[] { new Claim(ClaimTypes.NameIdentifier, ds.id), new Claim(ClaimTypes.Name, email) }; var tokens = new JwtSecurityToken( issuer: "Phynix", audience: "Phynix Inc", claims: claim, notBefore: DateTime.Now.AddMinutes(1), expires: DateTime.Now.AddDays(2), signingCredentials: credentials); var handler = new JwtSecurityTokenHandler(); var tokenString = handler.WriteToken(tokens); return((ActionResult) new OkObjectResult(new { Result = new { data = ds, token = tokenString } })); } catch (Exception ex) { return((ActionResult) new OkObjectResult(ex)); } } catch (Exception ex) { return((ActionResult) new OkObjectResult(ex)); } }
public ChampionshipController() { races = new RaceRepository(); motorcycles = new MotorcycleRepository(); riders = new RiderRepository(); }
private void CreateContext() { switch (_currentRepository.ToLower()) { case "riders": Context = new RiderRepository(); break; default: ErrorMessage = "Invalid repository."; break; } }
public dynamic CreateAndGetContext() { dynamic context = null; switch (_currentRepository.ToLower()) { case "riders": context = new RiderRepository(); break; default: ErrorMessage = "Invalid context."; break; } return context; }
public Race(string name, int laps) { this.Name = name; this.Laps = laps; riderRepository = new RiderRepository(); }