Beispiel #1
0
        private void AddDealership(string dealershipName)
        {
            var dealership = new Dealership
            {
                IsActive       = true,
                CreationDate   = DateTime.UtcNow,
                DealerShipName = dealershipName,
                Address        = "Rua da Autorepairshop",
                ZipCodeId      = 1,
            };

            _context.Dealerships.Add(dealership);
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Email,PhoneNumber")] Dealership dealership)
        {
            if (id != dealership.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid && DealershipMgr.UpdateDealership(dealership))
            {
                return(RedirectToAction(nameof(Index)));
            }
            return(View(dealership));
        }
Beispiel #3
0
        public void AddDealership(DealershipInputModel model)
        {
            Dealership dealership = new Dealership
            {
                Name    = model.Name,
                Country = model.Country,
                Town    = model.Town,
                Cars    = model.Cars,
            };

            context.Dealerships.Add(dealership);
            context.SaveChanges();
        }
Beispiel #4
0
        public void TestPut()
        {
            var        dealership    = DealershipMgr.getDealership(2);
            string     oldName       = dealership.Name;
            Dealership newDealership = new Dealership {
                Id = 2, Name = "KIA Hamilton", Email = "*****@*****.**", PhoneNumber = "800-121-1525"
            };

            DealershipMgr.putDealership(2, newDealership);
            var dealerships = DealershipMgr.getDealerships();

            Assert.AreNotEqual(oldName, dealerships[1].Name);
        }
Beispiel #5
0
        public static bool DeleteDealership(Dealership dealership)
        {
            Dealership ds = dealerships.FirstOrDefault(p => p.ID == dealership.ID);

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

            dealerships.Remove(ds);

            return(true);
        }
Beispiel #6
0
        public void CTestSuccessPost()
        {
            Dealership dealership = new Dealership();

            dealership.Email = "*****@*****.**";
            dealership.Name  = "Michael";
            dealership.Phone = "9012421";

            DealershipMgr.Post(dealership);
            var result1 = DealershipMgr.Get(1);

            Assert.AreEqual(result1, dealership);
        }
Beispiel #7
0
        public void DealershipApiPostPass()
        {
            DealershipsController dealerships = new DealershipsController(_context);

            Dealership newDealership = new Dealership {
                Name = "My Dealership", Email = "*****@*****.**", PhoneNumber = "905-531-0912"
            };

            Dealership testDealership = dealerships.PostDealership(newDealership);

            Assert.AreEqual(4, DealershipList.Count);
            Assert.AreEqual("Devons Cars", DealershipList[4].Name);
        }
Beispiel #8
0
        public void DealershipMgrGetById()
        {
            //Test to pass
            Dealership d = DealershipMgr.GetDealership(2);

            Assert.IsInstanceOfType(d, typeof(Dealership));
            Assert.AreEqual("dealership2", d.Name);
            Assert.AreEqual("*****@*****.**", d.Email);

            //Test to fail
            Assert.AreNotEqual("123-123-1234", d.PhoneNumber);
            Assert.IsNull(DealershipMgr.GetDealership(20));
        }
Beispiel #9
0
        public void ValidGet()
        {
            // Arrange

            // Act
            Dealership dealership = _dealershipMgr.Get(1);

            // Assert
            Assert.AreEqual("*****@*****.**", dealership.Email);
            Assert.AreEqual(1, dealership.Id);
            Assert.AreEqual("Dealer One", dealership.Name);
            Assert.AreEqual("(111) 111-1111", dealership.PhoneNumber);
        }
        public ActionResult Create(Dealership dealership)
        {
            if (ModelState.IsValid)
            {
                dealership.DealershipID = Guid.NewGuid();
                db.Dealerships.Add(dealership);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.DealershipAddressID = new SelectList(db.Addresses, "AddressID", "FullAddress", dealership.DealershipAddressID);
            ViewBag.DealershipContactID = new SelectList(db.Contacts, "ContactID", "FirstName", dealership.DealershipContactID);
            return View(dealership);
        }
        // GET: Dealerships/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Dealership dealership = db.Dealerships.Find(id);

            if (dealership == null)
            {
                return(HttpNotFound());
            }
            return(View(dealership));
        }
Beispiel #12
0
        // GET: Dealerships/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Dealership dealership = await db.Dealerships.FindAsync(id);

            if (dealership == null)
            {
                return(HttpNotFound());
            }
            return(View(dealership));
        }
Beispiel #13
0
        public void CreateSingleDealer_Fail()
        {
            var testObject = new Dealership()
            {
                Name        = "Honda Dealer",
                Email       = null, //no email should fail.
                PhoneNumber = "905 888 7777"
            };

            _dealershipManager.CreateDealership(testObject);
            var result = _dealershipManager.GetDealerships().Find(x => x.Name == testObject.Name);

            Assert.AreEqual(null, result);
        }
Beispiel #14
0
        public async Task ApiTestPassGetDealership()
        {
            Dealership dealership1 = DealershipMgr.GetDealership(0);

            Assert.AreEqual("Kia", dealership1.Name);
            Assert.AreEqual("*****@*****.**", dealership1.Email);
            Assert.AreEqual("1234567890", dealership1.PhoneNumber);

            Dealership dealership2 = DealershipMgr.GetDealership(1);

            Assert.AreEqual("Honda", dealership2.Name);
            Assert.AreEqual("*****@*****.**", dealership2.Email);
            Assert.AreEqual("0987654321", dealership2.PhoneNumber);
        }
Beispiel #15
0
        public IActionResult Put(int id, [FromBody] Dealership value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.SelectMany(v => v.Errors).Select(x => x.ErrorMessage)));
            }
            var success = _dealershipManager.UpdateDealership(id, value);

            if (success)
            {
                return(Ok("Success"));
            }
            return(BadRequest("Something went wrong"));
        }
Beispiel #16
0
        public IActionResult Delete(int id)
        {
            Dealership dealership            = service.GetOneDealership(id);
            DealershipDetailsViewModel model = new DealershipDetailsViewModel
            {
                DealershipId = dealership.DealershipId,
                Name         = dealership.Name,
                Country      = dealership.Country,
                Town         = dealership.Town,
                Cars         = dealership.Cars
            };

            return(View(model));
        }
        public async Task <IActionResult> AddDealershipToServices(Dealership dealership)
        {
            var dShip = await _dealershipRepository.GetByNameAsync(dealership.DealerShipName);

            var services = await _serviceRepository.GetAllServicesAsync();

            foreach (var item in services)
            {
                await _servicesSuppliedRepository.AddServicesToDealershipAsync(item, dShip);
            }



            return(RedirectToAction("AddDepartmentsToDealership", dShip));
        }
        public async Task <IActionResult> AddDepartmentsToDealership(Dealership dealership)
        {
            var dShip = await _dealershipRepository.GetByNameAsync(dealership.DealerShipName);

            var departments = await _departmentRepository.GetDepartments();

            foreach (var item in departments)
            {
                await _dealershipDepartmentRepository.AddDepartmentToDealershipAsync(item, dShip);
            }



            return(RedirectToAction(nameof(Index)));
        }
Beispiel #19
0
        public static string Put(Dealership ids)
        {
            foreach (var x in Dealerships)
            {
                if (x.ID == ids.ID && x.Name != null && x.Email != null)
                {
                    x.Email = ids.Email;
                    x.Name  = ids.Name;
                    x.Phone = ids.Phone;

                    return("Success");
                }
            }
            return("Failure");
        }
        public IActionResult Edit(int id, [Bind("DealershipID,Name,Email,PhoneNumber")] Dealership dealership)
        {
            if (id != dealership.DealershipId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _dealershipsManager.UpdateDealership(id, dealership);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(dealership));
        }
Beispiel #21
0
        public void GetVehicles_AllVehicles_with_MinAndMaxYear()
        {
            Dealership dealership    = new Dealership();
            int        vehiclesCount = 10;

            Vehicle[] allVehicles = new Vehicle[vehiclesCount];

            for (int i = 0; i < vehiclesCount; i++)
            {
                Vehicle vehicle = randomVehicles.next();
                Assert.IsTrue(dealership.CreateVechicle(vehicle));
                allVehicles[i] = vehicle;
            }

            //Get vehicles with 5 year window between min and max year
            for (int i = DealershipConfig.MIN_YEAR; i <= DealershipConfig.MAX_YEAR; i += 5)
            {
                int minYear = i;
                int maxYear = i + 5;
                LinkedList <Vehicle> vehicles = dealership.GetVehicles(minYear, maxYear);
                if (vehicles == null)
                {
                    continue;
                }
                foreach (Vehicle vehicle in vehicles)
                {
                    //Check if the get vehicles exists in allVehicles
                    bool containsVehicle = false;
                    for (int j = 0; j < vehiclesCount; j++)
                    {
                        if (vehicle.Equals(allVehicles[j]))
                        {
                            containsVehicle = true;
                            break;
                        }
                    }
                    Assert.IsTrue(containsVehicle);

                    //Check if the current vehicle is truely inbetween
                    //the get range
                    if (vehicle.Year < i && vehicle.Year > i + 5)
                    {
                        Assert.Fail();
                    }
                }
            }
            Assert.Pass();
        }
Beispiel #22
0
 public ActionResult SeedDB()
 {
     // var dealerships = new DealershipMgr().Get();
     if (_context.Dealership.Count() == 0)
     {
         Dealership deal1 = new Dealership {
             Id = 1, Name = "Joshs Cars", Email = "*****@*****.**", PhoneNumber = "905-123-4567"
         };
         Dealership deal2 = new Dealership {
             Id = 2, Name = "Used Cars", Email = "*****@*****.**", PhoneNumber = "905-122-3461"
         };
         _context.Dealership.AddRange(deal1, deal2);
         _context.SaveChanges();
     }
     return(RedirectToAction(nameof(Index)));
 }
Beispiel #23
0
        public void UpdateDealer_Fail()
        {
            var testObject = new Dealership()
            {
                Name        = "Chevy Dealer",
                Email       = "*****@*****.**",
                PhoneNumber = "905 888 7777"
            };

            var result = _dealershipManager.GetDealerships().Find(x => x.Name == testObject.Name);

            result.Email = null;
            var success = _dealershipManager.UpdateDealership(result.DealershipId, result);

            Assert.AreEqual(false, success);
        }
Beispiel #24
0
        public static void Initialize(TestContext tc)
        {
            var options = new DbContextOptionsBuilder <Lab1Context>().UseInMemoryDatabase(databaseName: "Lab1TestDb").Options;

            _context = new Lab1Context(options);

            Dealership dealership1 = new Dealership {
                Name = "dealership1", Email = "*****@*****.**"
            };
            Dealership dealership2 = new Dealership {
                Name = "dealership2", Email = "*****@*****.**"
            };

            _context.Dealership.AddRange(dealership1, dealership2);
            _context.SaveChanges();
        }
Beispiel #25
0
        public void dealershipSelected(string name, string value)
        {
            Console.WriteLine("selected dealer=" + value);
            Dealership dealer = listOfDealers.FirstOrDefault(d => d.DealershipName == value);

            if (dealer == null)
            {
                Controls.OkDialog("Invalid Dealer", "Selected dealer does not exist, please select a different dealer.");
                return;
            }

            NSUserDefaults.StandardUserDefaults.SetInt(dealer.DealershipID, "SelectedDealershipID");
            NSUserDefaults.StandardUserDefaults.SetString(dealer.DealershipName, "SelectedDealershipName");

            SetDealershipLabel();
        }
Beispiel #26
0
        public void UpdateDealership(DealershipEditViewModel entity)
        {
            Dealership dealership = context.Dealerships.Find(entity.DealershipId);

            if (dealership is null)
            {
                return;
            }
            dealership.Name    = entity.Name;
            dealership.Country = entity.Country;
            dealership.Town    = entity.Town;
            dealership.Cars    = entity.Cars;

            context.Dealerships.Update(dealership);
            context.SaveChanges();
        }
Beispiel #27
0
        public static bool UpdateDealership(Dealership dealership)
        {
            Dealership ds = dealerships.FirstOrDefault(p => p.ID == dealership.ID);

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

            int dsId = dealerships.FindIndex(p => p.ID == ds.ID);

            dealerships.RemoveAt(dsId);
            dealerships.Insert(dsId, dealership);

            return(true);
        }
Beispiel #28
0
        public static void Initialize(TestContext tc)
        {
            var options = new DbContextOptionsBuilder <Lab_1AContext>().UseInMemoryDatabase(databaseName: "Lab1A Test").Options;

            _context = new Lab_1AContext(options);

            Dealership dealership1 = new Dealership {
                ID = 1, Email = "*****@*****.**", Name = "Rose", PhoneNumber = "905-453-1123"
            };
            Dealership dealership2 = new Dealership {
                ID = 2, Email = "*****@*****.**", Name = "Yang", PhoneNumber = "905-764-2215"
            };

            _context.Dealership.AddRange(dealership1, dealership2);
            _context.SaveChanges();
        }
Beispiel #29
0
        public async Task <bool> CreateDealershipAsync(CreateDealershipInputModel input, ApplicationUser user, string picturePath)
        {
            var dealership = new Dealership
            {
                Name        = input.DealershipName,
                DealerSince = DateTime.UtcNow,
                Location    = input.Location + " " + input.FullAddress,
                PhoneNumber = input.PhoneNumber,
                Description = input.Description,
                Stars       = 0,
                User        = user,
                UserId      = user.Id,
            };

            // /wwwroot/images/dealerships/jhdsi-343g3h453-=g34g.jpg
            Directory.CreateDirectory($"{picturePath}/dealerships/");
            var extension = Path.GetExtension(input.LogoPicture.FileName).TrimStart('.');

            if (!this.allowedExtensions.Any(x => extension.EndsWith(x)))
            {
                throw new Exception($"Invalid picture extension {extension}");
            }

            var dbPicture = new Picture
            {
                Extension = extension,
            };

            dealership.LogoPicture = dbPicture;

            var physicalPath = $"{picturePath}/dealerships/{dbPicture.Id}.{extension}";

            using Stream fileStream = new FileStream(physicalPath, FileMode.Create);
            await input.LogoPicture.CopyToAsync(fileStream);

            if (dealership != null)
            {
                await this.dealershipRepository.AddAsync(dealership);

                await this.dealershipRepository.SaveChangesAsync();

                return(true);
            }

            throw new InvalidOperationException(GlobalConstants.InvalidOperationExceptionWhileCreatingDealership);
        }
Beispiel #30
0
        public void dealershipSelected(string name, string value)
        {
            Console.WriteLine("selected dealer create vehicle=" + value);
            Dealership dealer = listOfDealers.FirstOrDefault(d => d.DealershipName == value);

            if (dealer == null)
            {
                Controls.OkDialog("Invalid Dealer", "Selected dealer does not exist, please select a different dealer.");
                return;
            }

            Vehicle v = LoadVehicleFromDatabase();

            v.DealershipID = dealer.DealershipID;
            using (Connection sqlConn = new Connection(SQLiteBoostDB.GetDBPath()))
                new VehicleDB(sqlConn).SaveVehicle(v);
        }
        public IActionResult Delete(int id)
        {
            Dealership dealership = DealershipMgr.GetDealership(id);

            if (dealership == null)
            {
                return(NotFound());
            }

            if (!DealershipMgr.DeleteDealership(dealership))
            {
                ModelState.AddModelError("Error", "Error deleting Dealership.");
                return(BadRequest(ModelState));
            }

            return(NoContent());
        }
 public ActionResult Edit(Dealership dealership)
 {
     if (ModelState.IsValid)
     {
         db.Entry(dealership).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.DealershipAddressID = new SelectList(db.Addresses, "AddressID", "FullAddress", dealership.DealershipAddressID);
     ViewBag.DealershipContactID = new SelectList(db.Contacts, "ContactID", "FirstName", dealership.DealershipContactID);
     return View(dealership);
 }