Esempio n. 1
0
        public IActionResult AddCar(AddCarModel model)
        {
            Car car = new Car();

            if (ModelState.IsValid)
            {
                if (model.Image != null)
                {
                    var path         = Path.GetExtension(model.Image.FileName);
                    var newImageName = Guid.NewGuid() + path;
                    var uploadPath   = Path.Combine(Directory.GetCurrentDirectory
                                                        (), "wwwroot/img/" + newImageName);

                    var stream = new FileStream(uploadPath, FileMode.Create);
                    model.Image.CopyTo(stream);

                    car.Image = newImageName;
                }

                car.Brand      = model.Brand;
                car.Plate      = model.Plate;
                car.Start_date = model.EntryDate;
                car.End_date   = model.ExpireDate;
                _carRepository.Add(car);
                return(RedirectToAction("Index", "Home"));
            }

            return(View(model));
        }
Esempio n. 2
0
 public void Add(AddCarModel model)
 {
     using (ReCapContext context = new ReCapContext())
     {
         context.Add(model);
         context.SaveChanges();
     }
 }
Esempio n. 3
0
        public IActionResult Add(AddCarModel model)
        {
            var result = _carService.Add(model);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Esempio n. 4
0
        public IActionResult Add(Car car)
        {
            var model = new AddCarModel {
                CarModel     = car.CarModel?.Code,
                Year         = car.Year,
                Registration = car.Registration,
                Color        = car.Color,
                Models       = ListModels
            };

            return(View(model));
        }
Esempio n. 5
0
        private IdbCarModel AddCar(CarsRepository repository, long?ownerProfileId, long carBrandId, long carBrandModelId, string carNumber)
        {
            var addCarModel = new AddCarModel
            {
                OwnerProfileId = ownerProfileId,
                CarBrandId     = carBrandId,
                CarModelId     = carBrandModelId,
                CarNumber      = carNumber
            };

            return(repository.AddCar(addCarModel));
        }
Esempio n. 6
0
        public AddCarModel GetAddCarInfo()
        {
            var model = new AddCarModel()
            {
                AvailableParts = this.db.Parts.Select(p => new PartSelectModel()
                {
                    Id   = p.Id,
                    Name = p.Name
                })
            };

            return(model);
        }
Esempio n. 7
0
        public IActionResult Create()
        {
            var carModel = new AddCarModel
            {
                Parts = this.partService.AllParts().Select(p => new SelectListItem
                {
                    Value = p.Id.ToString(),
                    Text  = p.Name
                }).ToList()
            };

            return(View(carModel));
        }
Esempio n. 8
0
        public IActionResult Add(AddCarModel addCarModel)
        {
            this.simpleLoggerService.LogToDb(this.User.Identity.Name, LogType.Add, "Cars");

            if (this.ModelState.IsValid)
            {
                this.carService.AddNewCar(addCarModel);

                return(RedirectToAction("All", new { make = addCarModel.Make }));
            }

            addCarModel.AvailableParts = this.carService.GetAddCarInfo().AvailableParts;

            return(this.View(addCarModel));
        }
Esempio n. 9
0
        public IActionResult Add(AddCarModel data)
        {
            if (ModelState.IsValid)
            {
                var carModel = database.Models.FirstOrDefault(m => m.Code == data.CarModel);
                var car      = new Car {
                    CarModel     = carModel,
                    Registration = data.Registration,
                    Color        = data.Color,
                    Year         = data.Year
                };
                database.AddCar(car);
                return(RedirectToAction("Index"));
            }

            data.Models = ListModels;
            return(View(data));
        }
Esempio n. 10
0
        public IActionResult Create(AddCarModel carModel)
        {
            if (!ModelState.IsValid)
            {
                carModel.Parts = this.partService.AllParts().Select(p => new SelectListItem
                {
                    Value = p.Id.ToString(),
                    Text  = p.Name
                }).ToList();
                return(View(carModel));
            }

            this.carService.Create(carModel.Make, carModel.Model, carModel.TravelledDistance, carModel.PartsIds);

            this.logService.Create(User.Identity.Name, "Create", "Car");

            return(RedirectToAction(nameof(All)));
        }
Esempio n. 11
0
        public IActionResult AddCar(AddCarModel carModel)
        {
            var carToAdd = new Car(

                carModel.balance,
                (CarType)Enum.Parse(typeof(CarType), carModel.carType)
                );

            try
            {
                ParkingClassLibrary.Parking.Instance.AddCar(carToAdd);
            }
            catch
            {
                return(BadRequest("Cannot  add Car, please check the input."));
            }

            return(Ok());
        }
Esempio n. 12
0
        public void AddNewCar(AddCarModel addCarModel)
        {
            List <PartCar> parts = this.db.Parts
                                   .Where(p => addCarModel.Parts.Any(sp => sp == p.Id))
                                   .Select(p => new PartCar()
            {
                PartId = p.Id
            })
                                   .ToList();

            var car = new Car()
            {
                Make              = addCarModel.Make,
                Model             = addCarModel.Model,
                TravelledDistance = addCarModel.TravelledDistance.Value,
                Parts             = parts
            };

            this.db.Cars.Add(car);

            this.db.SaveChanges();
        }
Esempio n. 13
0
 public IResult Add(AddCarModel model)
 {
     _carDal.Add(model);
     return(new SuccessResult(Messages.CarAdded));
 }
        /****************************************************************************/
        public IdbCarModel AddCar(AddCarModel model)
        {
            var inOwnerProfileId =
                model.OwnerProfileId == null ?
                new SqlParameter
            {
                ParameterName = "OwnerProfileId",
                Value         = DBNull.Value,
                DbType        = System.Data.DbType.Int64,
                Direction     = System.Data.ParameterDirection.Input
            }
                :
            new SqlParameter
            {
                ParameterName = "OwnerProfileId",
                Value         = model.OwnerProfileId,
                DbType        = System.Data.DbType.Int64,
                Direction     = System.Data.ParameterDirection.Input
            };
            var inCarBrandId = new SqlParameter
            {
                ParameterName = "CarBrandId",
                Value         = model.CarBrandId,
                DbType        = System.Data.DbType.Int64,
                Direction     = System.Data.ParameterDirection.Input
            };
            var inCarModelId = new SqlParameter
            {
                ParameterName = "CarModelId",
                Value         = model.CarModelId,
                DbType        = System.Data.DbType.Int64,
                Direction     = System.Data.ParameterDirection.Input
            };
            var inCarNumber =
                string.IsNullOrEmpty(model.CarNumber) ?
                new SqlParameter
            {
                ParameterName = "CarNumber",
                Value         = DBNull.Value,
                DbType        = System.Data.DbType.String,
                Direction     = System.Data.ParameterDirection.Input
            }
                :
            new SqlParameter
            {
                ParameterName = "CarNumber",
                Value         = model.CarNumber,
                DbType        = System.Data.DbType.String,
                Direction     = System.Data.ParameterDirection.Input
            };
            var outResultCarId = new SqlParameter
            {
                ParameterName = "ResultCarId",
                DbType        = System.Data.DbType.Int64,
                Direction     = System.Data.ParameterDirection.Output
            };

            var sql = "exec AddCar @OwnerProfileId, @CarBrandId, @CarModelId, @CarNumber, @ResultCarId OUT";

            using (var dbContext = new CarsContext())
            {
                _ = dbContext.Database.ExecuteSqlCommand(sql, inOwnerProfileId, inCarBrandId, inCarModelId, inCarNumber, outResultCarId);
            }
            if (long.TryParse(outResultCarId.Value.ToString(), out long resultCarId))
            {
                model.Id = resultCarId;
            }

            return(model);
        }
Esempio n. 15
0
        public IActionResult Add()
        {
            AddCarModel model = this.carService.GetAddCarInfo();

            return(View(model));
        }
Esempio n. 16
0
 public void Add(AddCarModel model)
 {
     throw new NotImplementedException();
 }