Beispiel #1
0
        public void Edit(int id, string model, decimal price, BodyType bodyType, TypeOfTransmission typeOfTransmission, double travelledDistance, int productionYear, int horsePower, string color, string imageUrl)
        {
            if (!this.db.Cars.Any(p => p.Id == id))
            {
                return;
            }

            var car = this.db.Cars.Find(id);

            if (car == null)
            {
                return;
            }

            // Editing the car

            car.Model              = model;
            car.Price              = price;
            car.BodyType           = bodyType;
            car.TypeOfTransmission = typeOfTransmission;
            car.TravelledDistance  = travelledDistance;
            car.ProductionYear     = productionYear;
            car.HorsePower         = horsePower;
            car.Color              = color;
            car.ImageUrl           = imageUrl;

            this.db.SaveChanges();
        }
Beispiel #2
0
        public bool Add(string model, decimal price, BodyType bodyType, TypeOfTransmission typeOfTransmission, double travelledDistance, int productionYear, int horsePower, string color, string imageUrl, string userId)
        {
            if (!this.db.Users.Any(u => u.Id == userId))
            {
                return(false);
            }

            var car = new Car
            {
                Model              = model,
                Price              = price,
                BodyType           = bodyType,
                TypeOfTransmission = typeOfTransmission,
                TravelledDistance  = travelledDistance,
                ProductionYear     = productionYear,
                HorsePower         = horsePower,
                Color              = color,
                ImageUrl           = imageUrl,
                UserId             = userId
            };

            this.db.Cars.Add(car);
            this.db.SaveChanges();

            return(true);
        }