Ejemplo n.º 1
0
        public async Task <IActionResult> AddNewCar(NewCarModel newCarModel)
        {
            using (var transaction = _dbContext.Database.BeginTransaction())
            {
                Office carOffice = _dbContext.Offices.Include(x => x.Cars).Where(x => x.Id == newCarModel.OfficeId).SingleOrDefault();
                if (carOffice == null)
                {
                    return(Ok(new { message = "Office does not exist!" }));
                }
                Car newCar = new Car();
                newCar.CarReservations = new Collection <CarReservation>();
                newCar.Model           = newCarModel.Model;
                newCar.Brand           = newCarModel.Brand;
                newCar.Year            = newCarModel.Year;
                newCar.TypeOfCar       = newCarModel.TypeOfCar;
                newCar.NumberOfSeats   = newCarModel.NumberOfSeats;
                newCar.PricePerDay     = newCarModel.PricePerDay;

                carOffice.Cars.Add(newCar);

                await _dbContext.SaveChangesAsync();

                transaction.Commit();
                return(Ok(new { message = "Car is successfully added!" }));
            }
        }
Ejemplo n.º 2
0
        public IActionResult AddCarModel([FromForm] NewCarModel newCarModel)
        {
            var user   = User.Claims.Where(u => u.Type == ClaimTypes.UserData).FirstOrDefault().Value;
            var userId = new Guid(user);
            var result = _carService.AddCarModel(newCarModel.Name, newCarModel.BrandId, userId);

            return(Ok(result));
        }
Ejemplo n.º 3
0
        public HttpResponseMessage AddNewCar(NewCarModel carModel)
        {
            Car car = new Car()
            {
                BrandId   = carModel.Brand,
                Condition = CarCondition.New,
                IsDeleted = false,
                Model     = carModel.Model,
                Name      = carModel.CarName,
                TypeId    = carModel.CarFamily
            };
            List <CarCategory> carCategories = new List <CarCategory>();
            CarCategory        carCategory;
            CarColor           CarColor;

            foreach (var item in carModel.Options)
            {
                carCategory            = new CarCategory();
                carCategory.CategoryId = item.Category;
                carCategory.IsDeleted  = false;
                carCategory.CarColors  = new List <CarColor>();
                foreach (var colorData in item.moreDetails)
                {
                    CarColor           = new CarColor();
                    CarColor.CarImages = new List <CarImage>()
                    {
                        new CarImage {
                            ImageURL = colorData.file, IsDeleted = false
                        }
                    };
                    CarColor.ColorId   = colorData.Color;
                    CarColor.IsDeleted = false;
                    CarColor.Price     = colorData.Price;
                    CarColor.Quantity  = colorData.Quantity;

                    carCategory.CarColors.Add(CarColor);
                }
                carCategories.Add(carCategory);
            }
            car.Carcategories = carCategories;
            db.Cars.Add(car);
            db.SaveChanges();

            //Send OK Response to Client.
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Ejemplo n.º 4
0
        public static bool CreateCarModel(CarDbContext context, NewCarModel updateCarModel)
        {
            var carBrand = context.CarBrands.SingleOrDefault(cb => cb.Id == updateCarModel.CarBrandId);

            if (carBrand == null)
            {
                return(false);
            }

            var carModel = new CarModel()
            {
                Id         = Guid.NewGuid(),
                Name       = updateCarModel.Name,
                Photo      = updateCarModel.Photo,
                CarBrand   = carBrand,
                CarBrandId = carBrand.Id
            };

            context.CarModels.Add(carModel);
            context.SaveChanges();
            return(true);
        }
Ejemplo n.º 5
0
 public JsonResult Post([FromBody] NewCarModel updateCarModel)
 {
     CarDbCommand.CreateCarModel(_context, updateCarModel);
     return(new JsonResult(null));
 }