public void DeleteVehicle_ShouldReturnNullWhenFindVehicle()
        {
            using (var context = new VehicleContext())
            {
                //Arrange
                VehicleCRUDService vs = new VehicleCRUDService(context);

                var vehicle = vs.CreateVehicle(new Vehicle
                {
                    Make  = "BMW",
                    Model = "X7",
                    Year  = 1999
                });

                context.SaveChanges();

                //Act
                var delete = vs.DeleteVehicle(vehicle.Id);
                context.SaveChanges();
                var found = context.Vehicles.Where(v => v.Id == delete.Id).FirstOrDefault();

                //Assert
                Assert.IsNull(found);
            }
        }
        public ActionResult Create([Bind(Include = "Id,Name,Abvr")] Make make)
        {
            if (ModelState.IsValid)
            {
                db.Makes.Add(make);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(make));
        }
Exemple #3
0
        public ActionResult Create([Bind(Include = "Id,VehicleCategoryId,MemberId,Regnr,Color,NumberOfWheels,VehicleType,Checkin,Checkout,Placing")] Vehicle vehicle)
        {
            var vehicles = from v in db.Vehicles
                           select v;



            string name  = vehicle.Color as string;
            Color  color = Color.FromName(name);

            if (!color.IsKnownColor)
            {
                ViewBag.PossibleToAdd = db.Vehicles.Count() < vars.GarageCapacity;
                ModelState.AddModelError("VehicleColor", "Color is not recognized!");
                ViewBag.MemberId          = new SelectList(db.Members, "Id", "Name", vehicle.MemberId);
                ViewBag.VehicleCategoryId = new SelectList(db.VehicleCategories, "Id", "Category", vehicle.VehicleCategoryId);
                return(View(vehicle));
            }


            if (vehicles.Any(o => o.Regnr == vehicle.Regnr))
            {
                ViewBag.PossibleToAdd = db.Vehicles.Count() < vars.GarageCapacity;
                ModelState.AddModelError("RegNr", "Registration number exists");
                ViewBag.MemberId          = new SelectList(db.Members, "Id", "Name", vehicle.MemberId);
                ViewBag.VehicleCategoryId = new SelectList(db.VehicleCategories, "Id", "Category", vehicle.VehicleCategoryId);
                return(View(vehicle));
            }
            if (ModelState.IsValid)
            {
                //var vehicles = db.Vehicles.ToList();

                vehicle.Checkin  = DateTime.Now;
                vehicle.Checkout = (DateTime)SqlDateTime.MinValue;
                var category = db.VehicleCategories.Where(c => c.Id == vehicle.VehicleCategoryId).First();
                int position = this.FindParkingSpace(vehicle);
                if (position == -1)
                {
                    ViewBag.PossibleToAdd = db.Vehicles.Count() < vars.GarageCapacity;
                    ModelState.AddModelError("Create", "Garage is full");
                    return(View(vehicle));
                }
                else
                {
                    vehicle.Placing = position;
                    db.Vehicles.Add(vehicle);
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.MemberId          = new SelectList(db.Members, "Id", "Name", vehicle.MemberId);
            ViewBag.VehicleCategoryId = new SelectList(db.VehicleCategories, "Id", "Category", vehicle.VehicleCategoryId);
            return(View(vehicle));
        }
        public ActionResult Create([Bind(Include = "Id,Name")] Member member)
        {
            if (ModelState.IsValid)
            {
                db.Members.Add(member);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(member));
        }
        public ActionResult Create([Bind(Include = "Id,KategoriAdi")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Exemple #6
0
        public ActionResult Create([Bind(Include = "Customer_ID,First_Name,Last_Name,Email,Phone,Postcode,Licence")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customer.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
        public ActionResult Create([Bind(Include = "Vehicle_ID,Vehicle_Manuf,Vehicle_Model,Vehicle_Colour,Vehicle_Licence,Vehicle_Rate")] Vehicle vehicle)
        {
            if (ModelState.IsValid)
            {
                db.Vehicle.Add(vehicle);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(vehicle));
        }
Exemple #8
0
        public ActionResult Create([Bind(Include = "Id,Category,Size")] VehicleCategory vehicleCategory)
        {
            if (ModelState.IsValid)
            {
                db.VehicleCategories.Add(vehicleCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(vehicleCategory));
        }
        public ActionResult Create([Bind(Include = "VehicleID,VehicleType,Make,Model,Engine,Doors,Wheels,SelectedBodyType")] Vehicle vehicle)
        {
            if (ModelState.IsValid)
            {
                db.Vehicles.Add(vehicle);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(vehicle));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Abrv")] VehicleMake vehicleMake)
        {
            if (ModelState.IsValid)
            {
                vehicleMake.Id = Guid.NewGuid();
                db.VehicleMakes.Add(vehicleMake);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(vehicleMake));
        }
        public IActionResult Create([FromBody] Vehicle item)
        {
            if (item == null || !ModelState.IsValid)
            {
                return(BadRequest());
            }

            _context.Vehicles.Add(item);
            _context.SaveChanges();

            return(CreatedAtRoute("GetVehicle", new { id = item.Id }, item));
        }
 public void CreateVehicle(VehicleDb vehicle)
 {
     _context.Add(vehicle);
     try
     {
         _context.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new DBOperationException(ex);
     }
 }
        public ActionResult Create([Bind(Include = "Id,Name,MakeId,Abvr")] Modeli modeli)
        {
            if (ModelState.IsValid)
            {
                db.Modelis.Add(modeli);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MakeId = new SelectList(db.Makes, "Id", "Name", modeli.MakeId);
            return(View(modeli));
        }
        public ActionResult Create([Bind(Include = "Id,AracAdi,ModelAdi,ModelYili,Resim,Fiyat,Uyggunluk,Anasayfa,CategoryId")] Vehicle vehicle)
        {
            if (ModelState.IsValid)
            {
                db.Vehicles.Add(vehicle);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "KategoriAdi", vehicle.CategoryId);
            return(View(vehicle));
        }
        public ActionResult Create([Bind(Include = "Id,RegistrationNumber,Color,Brand,Model,NumberOfWheels,CheckIn,CheckOut")] ParkedVehicle parkedVehicle)
        {
            if (ModelState.IsValid)
            {
                db.Vehicles.Add(parkedVehicle);
                parkedVehicle.CheckIn = DateTime.Now;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(parkedVehicle));
        }
Exemple #16
0
        public IActionResult Create(Car car)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Vehicles.Add(car);
            _context.SaveChanges();

            return(CreatedAtRoute("GetCar", new { id = car.Id }, car));
        }
        public ActionResult Create([Bind(Include = "Rental_ID,Customer_ID,Vehicle_ID,Rental_Start,Rental_End")] Rental rental)
        {
            if (ModelState.IsValid)
            {
                db.Rental.Add(rental);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Customer_ID = new SelectList(db.Customer, "Customer_ID", "CustomerDetails", rental.Customer_ID);
            ViewBag.Vehicle_ID  = new SelectList(db.Vehicle, "Vehicle_ID", "VehicleDetails", rental.Vehicle_ID);
            return(View(rental));
        }
Exemple #18
0
        public ActionResult Create([Bind(Include = "Id,VehicleCategoryId,MemberId,Regnr,Color,NumberOfWheels,VehicleType,Checkin,Checkout,Placing")] Vehicle vehicle)
        {
            if (ModelState.IsValid)
            {
                db.Vehicles.Add(vehicle);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MemberId          = new SelectList(db.Members, "Id", "Name", vehicle.MemberId);
            ViewBag.VehicleCategoryId = new SelectList(db.VehicleCategories, "Id", "Category", vehicle.VehicleCategoryId);
            return(View(vehicle));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Abrv,VehicleMakeId")] VehicleModel vehicleModel)
        {
            if (ModelState.IsValid)
            {
                vehicleModel.Id = Guid.NewGuid();
                db.VehicleModels.Add(vehicleModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.VehicleMakeId = new SelectList(db.VehicleMakes, "Id", "Name", vehicleModel.VehicleMakeId);
            return(View(vehicleModel));
        }
Exemple #20
0
        public ActionResult Create([Bind(Include = "Id,VType,RegNr,Color,Brand,VName,WheelTally,CheckInTime,CheckOutTime")] Vehicle vehicle)
        {
            if (ModelState.IsValid)
            {
                vehicle.CheckInTime  = DateTime.Now;
                vehicle.CheckOutTime = DateTime.Now;
                db.Vehicles.Add(vehicle);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(vehicle));
        }
Exemple #21
0
 public ActionResult Create([Bind(Include = "Id,MemberId,VehicleTypeId,RegistrationNumber,Color,Brand,Model,NumberOfWheels")] ParkedVehicle parkedVehicle)
 {
     if (ModelState.IsValid)
     {
         db.Vehicles.Add(parkedVehicle);
         parkedVehicle.CheckIn = DateTime.Now;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MemberIdList      = new SelectList(db.Members, "Id", "MemberNr", parkedVehicle.MemberId);
     ViewBag.VehicleTypeIdList = new SelectList(db.Types, "Id", "VehTypeName", parkedVehicle.VehicleType);
     return(View(parkedVehicle));
 }
        public ActionResult Create([Bind(Include = "Id,FName,LName,MemberShip,TelNumber,Address,City,Pcode")] Member member)
        {
            if (ModelState.IsValid)
            {
                db.Members.Add(member);
                member.StartDate = DateTime.Now;
                db.SaveChanges();
                member.MemberShip = member.Id;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(member));
        }
Exemple #23
0
        public bool Save(Vehicle entity)
        {
            try
            {
                _context.Vehicles.Add(entity);

                _context.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public IHttpActionResult PostUserVehicle(UserVehicles Vehicle)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            string userId = User.Identity.GetUserId();

            Vehicle.UserId = userId;

            db.Vehicle.Add(Vehicle);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { }, Vehicle));
        }
Exemple #25
0
        public IActionResult Create(Enquery enquery)
        {
            _context.Add(enquery);
            _context.SaveChanges();

            return(CreatedAtRoute("GetEnquery", new { id = enquery.Id }, enquery));
        }
Exemple #26
0
        private void DeleteVehicle(object s, RoutedEventArgs e)
        {
            var vehicleToDelete = (s as FrameworkElement).DataContext as Model.Vehicle;

            _context.Vehicles.Remove(vehicleToDelete);
            _context.SaveChanges();
        }
Exemple #27
0
        public void GetAll()
        {
            using (var context = new VehicleContext(options))
            {
                var id = 0;
                if (context.Vehicles.Count() > 0)
                {
                    id = context.Vehicles.Max(x => x.Id);
                }

                context.Vehicles.Add(new Vehicle {
                    Id = (id + 1), Mark = "Fiat", Model = "teste1", Color = "color1", Description = "desc1"
                });
                context.Vehicles.Add(new Vehicle {
                    Id = (id + 2), Mark = "Honda", Model = "teste1", Color = "color1", Description = "desc1"
                });
                context.Vehicles.Add(new Vehicle {
                    Id = (id + 3), Mark = "Ferrari", Model = "teste1", Color = "color1", Description = "desc1"
                });
                context.SaveChanges();
            }

            using (var context = new VehicleContext(options))
            {
                var service = new Services(context);
                var result  = service.GetAll(null);
                Assert.AreEqual(3, result.Count());
            }
        }
        public static void PopulateTestData(VehicleContext db)
        {
            db.AddRange(
                new Vehicle
            {
                Year  = 2015,
                Make  = "Nissan",
                Model = "Versa"
            },
                new Vehicle
            {
                Year  = 1965,
                Make  = "Ford",
                Model = "Mustang"
            },
                new Vehicle
            {
                Year  = 1967,
                Make  = "Chevy",
                Model = "Impala"
            }
                );

            db.SaveChanges();
        }
Exemple #29
0
        public void Setup()
        {
            //create in memory database
            var options = new DbContextOptionsBuilder <VehicleContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            // insert temp records
            _context = new VehicleContext(options);

            _context.Vehicles.Add(new Vehicle()
            {
                Price   = 101m,
                Color   = "purple",
                Mileage = 1,
                Model   = "yugo",
                Status  = Vehicle.VehicleStatus.Active
            });

            _context.SaveChanges();

            var mapperConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMapperProfile());
            });

            _mapper = mapperConfig.CreateMapper();
        }
        public async Task DeleteAsync(int id)
        {
            var entity = await SaleEntities.FindAsync(id);

            Context.Entry(entity).State = EntityState.Deleted;
            Context.SaveChanges();
        }
        public void AddNewTransmissionTypeTest()
        {
            Entity entity;
            using (var context = new VehicleContext())
            {
                entity = context.Entities.OfType<Style>().FirstOrDefault();
                entity.Created = entity.Created.AddMinutes(-45);
                context.DbTypes.AddOrUpdate(x => new {x.Name, x.TypeName}, new TransmissionType("Automatic", "5sp"));
                context.SaveChanges();
            }
            var t1 = entity.Version;

            var task = new Task(() => { entity.Modified = DateTime.UtcNow; });
            
            var newEntity = DbContextExtensions.ReAttachAndSave<VehicleContext>(entity, task);

            var t2 = entity.Version;
            Assert.AreNotEqual(t1, t2);
            int i = 0;
        }