Ejemplo n.º 1
0
        public ActionResult Create(TestDrive testDrive, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file.ContentLength > 0 && file != null)
                {
                    string ext = Path.GetExtension(file.FileName);
                    if (ext != ".pdf")
                    {
                        ViewBag.Error = $"Error, Accepted file format is .pdf";
                        return(View());
                    }
                    try
                    {
                        string path = Path.Combine(Server.MapPath("~/LicenceCopies"), Path.GetFileName(file.FileName));
                        file.SaveAs(path);

                        testDrive.Attathment = path;
                    }
                    catch (Exception e)
                    {
                        ViewBag.Error = e.Message;
                        return(View(testDrive));
                    }
                }

                db.TestDrive.Add(testDrive);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(testDrive));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,Email,PhoneNumber,Date,StartTime,EndTime,Message")] TestDrive testDrive)
        {
            if (id != testDrive.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(testDrive);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TestDriveExists(testDrive.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(testDrive));
        }
Ejemplo n.º 3
0
        public void TestFullNameByFirstName()
        {
            TestDrive td = new TestDrive(Database);

            td.FirstName = "1";

            Assert.AreEqual(td.FullName, "1");
        }
Ejemplo n.º 4
0
        public void TestDateTimeByDate()
        {
            TestDrive td = new TestDrive(Database);

            td.Date = new DateTime(2019, 12, 10);

            Assert.AreEqual(td.DateTime, new DateTime(2019, 12, 10, 12, 0, 0));
        }
Ejemplo n.º 5
0
        public void TestDateTimeByTime()
        {
            TestDrive td = new TestDrive(Database);

            td.Time = new TimeSpan(10, 10, 10);

            Assert.AreEqual(td.DateTime, DateTime.Today.AddHours(10).AddMinutes(10));
        }
Ejemplo n.º 6
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            TestDrive testDrive = db.TestDrive.Find(id);

            db.TestDrive.Remove(testDrive);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 7
0
        public void TestFullNameBySecondNameAndThirdName()
        {
            TestDrive td = new TestDrive(Database);

            td.SecondName = "2";
            td.ThirdName  = "3";

            Assert.AreEqual(td.FullName, "2 3");
        }
Ejemplo n.º 8
0
        private void ValidateTestDriveUser(TestDrive dbTestDrive, ClaimsPrincipal user)
        {
            var dbUserId = this.userManager.GetUserId(user);

            if (dbTestDrive.UserId != dbUserId)
            {
                throw new ArgumentException(ErrorConstants.IncorrectId);
            }
        }
Ejemplo n.º 9
0
        private TestDrive CreateTestDrive()
        {
            var testDrive = new TestDrive();

            testDrive.UserId = Guid.NewGuid().ToString();
            dbContext.Add(testDrive);
            dbContext.SaveChanges();
            return(testDrive);
        }
Ejemplo n.º 10
0
 public ActionResult Edit(TestDrive testDrive)
 {
     if (ModelState.IsValid)
     {
         db.Entry(testDrive).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(testDrive));
 }
Ejemplo n.º 11
0
        public static TestDrive SeedTestDrive(ApplicationDbContext dbContext, BaseCar baseCar)
        {
            var dbTestDrive = new TestDrive()
            {
                Car = baseCar
            };

            SeedTestDrive(dbContext, dbTestDrive);

            return(dbTestDrive);
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Email,PhoneNumber,Date,StartTime,EndTime,Message")] TestDrive testDrive)
        {
            if (ModelState.IsValid)
            {
                _context.Add(testDrive);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(testDrive));
        }
Ejemplo n.º 13
0
 public IActionResult Teste(TestDrive testDrive)
 {
     //Cadastrar
     _context.TestDrives.Add(testDrive);
     //Commit
     _context.SaveChanges();
     //Mensagem
     TempData["msg"] = "Test Drive agendado";
     //Redirect para o Teste informando o id do cliente
     return(RedirectToAction("Teste", new { id = testDrive.ClienteId }));
 }
Ejemplo n.º 14
0
        private async Task ValidateTestDriveStatus(TestDrive dbTestDrive)
        {
            var dbUpcomingStatusId = await this.statusRepository
                                     .Find(s => s.Name == TestDriveStatus.Upcoming.ToString())
                                     .Select(s => s.Id)
                                     .FirstAsync();

            if (dbTestDrive.StatusId != dbUpcomingStatusId)
            {
                throw new InvalidOperationException(ErrorConstants.StatusIsNotUpcoming);
            }
        }
Ejemplo n.º 15
0
        public static TestDrive SeedTestDriveWithStatus(
            ApplicationDbContext dbContext,
            TestDriveStatus status = TestDriveStatus.Upcoming)
        {
            var dbStatus    = SeedStatusesMethods.SeedStatus(dbContext, status);
            var dbTestDrive = new TestDrive()
            {
                Status = dbStatus
            };

            SeedTestDrive(dbContext, dbTestDrive);

            return(dbTestDrive);
        }
Ejemplo n.º 16
0
        // GET: TestDrives/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TestDrive testDrive = db.TestDrive.Find(id);

            if (testDrive == null)
            {
                return(HttpNotFound());
            }
            return(View(testDrive));
        }
Ejemplo n.º 17
0
        public async Task <TestDriveDTO> BuscarPorSolicitudAsync(string clienteId, string solicitudId)
        {
            try
            {
                TestDrive _testdrive = await testdriveRepository.BuscarPorSolicitudAsync(clienteId, solicitudId);

                TestDriveDTO testdriveDTO = _mapper.Map <TestDrive, TestDriveDTO>(_testdrive);
                return(testdriveDTO);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 18
0
        public static TestDrive SeedTestDrive(
            ApplicationDbContext dbContext,
            string userId,
            Status status)
        {
            var dbTestDrive = new TestDrive()
            {
                UserId = userId,
                Status = status
            };

            SeedTestDrive(dbContext, dbTestDrive);

            return(dbTestDrive);
        }
Ejemplo n.º 19
0
        public static TestDrive SeedTestDriveWithEverything(
            ApplicationDbContext dbContext,
            TestDriveStatus status = TestDriveStatus.Upcoming)
        {
            var dbStatus    = SeedStatusesMethods.SeedStatus(dbContext, status);
            var dbCar       = SeedCarsMethods.SeedCarWithEverything <NewCar>(dbContext);
            var dbTestDrive = new TestDrive()
            {
                Status = dbStatus,
                User   = new User(),
                Car    = dbCar
            };

            SeedTestDrive(dbContext, dbTestDrive);

            return(dbTestDrive);
        }
Ejemplo n.º 20
0
        public static TestDrive SeedTestDriveWithCar <TCar>(
            ApplicationDbContext dbContext,
            DateTime dateTime,
            TestDriveStatus status = TestDriveStatus.Upcoming)
            where TCar : BaseCar, new()
        {
            var dbStatus    = SeedStatusesMethods.SeedStatus(dbContext, status);
            var dbTestDrive = new TestDrive()
            {
                ScheduleDate = dateTime,
                Status       = dbStatus
            };
            var dbCar = SeedCarsMethods.SeedCar <TCar>(dbContext);

            dbCar.TestDrives.Add(dbTestDrive);

            SeedTestDrive(dbContext, dbTestDrive);

            return(dbTestDrive);
        }
        public async Task <IActionResult> Create([Bind("Id,DateTime,ClientId,CarId")] TestDrive testDrive)
        {
            if (ModelState.IsValid)
            {
                _context.Add(testDrive);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            var cars = await _context.Cars
                       .Where(x => x.TestDrive)
                       .Include(x => x.CarModel).ThenInclude(x => x.Vendor)
                       .Include(x => x.Color).AsNoTracking().ToListAsync();

            var clients = await _context.Clients.AsNoTracking().ToListAsync();

            ViewData["Cars"]    = cars;
            ViewData["Clients"] = clients;

            return(View(testDrive));
        }
Ejemplo n.º 22
0
        public void TestDateDefaultValue()
        {
            TestDrive td = new TestDrive(Database);

            Assert.AreEqual(td.Date, DateTime.Today);
        }
 private bool IsScheduledInLast24Hours(TestDrive testDrive)
 {
     return(DateTime.UtcNow.AddDays(-1) <= testDrive.ScheduleDate);
 }
Ejemplo n.º 24
0
        public void TestTimeDefaultValue()
        {
            TestDrive td = new TestDrive(Database);

            Assert.AreEqual(td.Time, new TimeSpan(12, 0, 0));
        }
Ejemplo n.º 25
0
 private static void SeedTestDrive(ApplicationDbContext dbContext, TestDrive testDrive)
 {
     dbContext.TestDrives.Add(testDrive);
     dbContext.SaveChanges();
 }