Пример #1
0
        public string AddVehicle(IList <string> arguments)
        {
            string  vehicleType = arguments[0];
            string  model       = arguments[1];
            double  weight      = double.Parse(arguments[2]);
            decimal price       = decimal.Parse(arguments[3]);
            int     attack      = int.Parse(arguments[4]);
            int     defense     = int.Parse(arguments[5]);
            int     hitPoints   = int.Parse(arguments[6]);

            IVehicle vehicle = null;

            switch (vehicleType)
            {
            case "Vanguard":
                //vehicle = new Vanguard(model, weight, price, attack, defense, hitPoints, new VehicleAssembler());
                vehicle = vehicleFactory.CreateVehicle(vehicleType, model, weight, price, attack, defense, hitPoints);
                break;

            case "Revenger":
                //    vehicle = new Revenger(model, weight, price, attack, defense, hitPoints, new VehicleAssembler());
                vehicle = vehicleFactory.CreateVehicle(vehicleType, model, weight, price, attack, defense, hitPoints);
                break;
            }

            if (vehicle != null)
            {
                this.vehicles.Add(vehicle.Model, vehicle);
            }

            return(string.Format(
                       GlobalConstants.VehicleSuccessMessage,
                       vehicleType,
                       vehicle.Model));
        }
Пример #2
0
        static void Main(string[] args)
        {
            IVehicleFactory factory = GetFactory("FactoryMethodPattern.ConcreteFactories.LincolnAviatorFactory");

            var lincolnAviator = factory.CreateVehicle();

            lincolnAviator.ShowInfo();

            factory = GetFactory("FactoryMethodPattern.ConcreteFactories.FordExplorerFactory");

            var fordExplorer = factory.CreateVehicle();

            fordExplorer.ShowInfo();
        }
Пример #3
0
        static void Main(string[] args)
        {
            IVehicleFactory factory = GetFactory("Factory_method_real.LincolnAviatorFactory");

            var lincolnAviator = factory.CreateVehicle();

            lincolnAviator.ShowInfo();

            factory = GetFactory("Factory_method_real.FordExplorerFactory");

            var fordExplorer = factory.CreateVehicle();

            fordExplorer.ShowInfo();
        }
Пример #4
0
        public async Task <int> SaveVehicle(VehicleViewModel vehicle, int garageId)
        {
            var vehicleModel = vehicle.Adapt <VehicleModel>();

            vehicleModel.VehicleProgram = await GetProgramVehicleList(vehicle);

            if (vehicle.Id == 0)
            {
                return(await _vehicleFactory.CreateVehicle(vehicleModel, garageId));
            }
            else
            {
                return(await _vehicleFactory.UpdateVehicle(vehicleModel, garageId));
            }
        }
Пример #5
0
        public string AddVehicle(IList <string> arguments)
        {//Vehicle Vanguard SA-203 100 300 1000 450 2000
            string  vehicleType = arguments[0];
            string  model       = arguments[1];
            double  weight      = double.Parse(arguments[2]);
            decimal price       = decimal.Parse(arguments[3]);
            int     attack      = int.Parse(arguments[4]);
            int     defense     = int.Parse(arguments[5]);
            int     hitPoints   = int.Parse(arguments[6]);

            IVehicle vehicle = vehicleFactory.CreateVehicle(vehicleType, model, weight, price, attack, defense, hitPoints);

            //throws exception if unsuccessfull!
            if (vehicles.ContainsKey(model))
            {
                throw new ArgumentException("Vehicle already added!NSH");
            }

            this.vehicles.Add(vehicle.Model, vehicle);
            return(string.Format(GlobalConstants.VehicleSuccessMessage, vehicleType, vehicle.Model));
        }
Пример #6
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                    await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation("User logged in.");

                    // Register the users Vehicle
                    IVehicle userVehicle = _vehicleFactory.CreateVehicle(
                        model.VIN,
                        model.YearId,
                        Int32.Parse(model.ColorId),
                        Int32.Parse(model.TransmissionId),
                        user.Id);

                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #7
0
        public string AddVehicle(IList <string> arguments)
        {
            string  vehicleType = arguments[0];
            string  model       = arguments[1];
            double  weight      = double.Parse(arguments[2]);
            decimal price       = decimal.Parse(arguments[3]);
            int     attack      = int.Parse(arguments[4]);
            int     defense     = int.Parse(arguments[5]);
            int     hitPoints   = int.Parse(arguments[6]);

            IVehicle vehicle = vehicleFactory.CreateVehicle(vehicleType, model, weight, price, attack, defense, hitPoints);

            if (vehicle != null)
            {
                this.vehicles.Add(vehicle.Model, vehicle);
            }

            return(string.Format(
                       GlobalConstants.VehicleSuccessMessage,
                       vehicleType,
                       vehicle.Model));
        }
 public static Vehicle GetVehicle(IVehicleFactory vehicleFactory)
 {
     return(vehicleFactory.CreateVehicle());
 }
Пример #9
0
 public IVehicle Create()
 {
     return(_vehicleFactory.CreateVehicle());
 }