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)); }
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)); }
public void TestFullNameByFirstName() { TestDrive td = new TestDrive(Database); td.FirstName = "1"; Assert.AreEqual(td.FullName, "1"); }
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)); }
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)); }
public ActionResult DeleteConfirmed(Guid id) { TestDrive testDrive = db.TestDrive.Find(id); db.TestDrive.Remove(testDrive); db.SaveChanges(); return(RedirectToAction("Index")); }
public void TestFullNameBySecondNameAndThirdName() { TestDrive td = new TestDrive(Database); td.SecondName = "2"; td.ThirdName = "3"; Assert.AreEqual(td.FullName, "2 3"); }
private void ValidateTestDriveUser(TestDrive dbTestDrive, ClaimsPrincipal user) { var dbUserId = this.userManager.GetUserId(user); if (dbTestDrive.UserId != dbUserId) { throw new ArgumentException(ErrorConstants.IncorrectId); } }
private TestDrive CreateTestDrive() { var testDrive = new TestDrive(); testDrive.UserId = Guid.NewGuid().ToString(); dbContext.Add(testDrive); dbContext.SaveChanges(); return(testDrive); }
public ActionResult Edit(TestDrive testDrive) { if (ModelState.IsValid) { db.Entry(testDrive).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(testDrive)); }
public static TestDrive SeedTestDrive(ApplicationDbContext dbContext, BaseCar baseCar) { var dbTestDrive = new TestDrive() { Car = baseCar }; SeedTestDrive(dbContext, dbTestDrive); return(dbTestDrive); }
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)); }
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 })); }
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); } }
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); }
// 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)); }
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; } }
public static TestDrive SeedTestDrive( ApplicationDbContext dbContext, string userId, Status status) { var dbTestDrive = new TestDrive() { UserId = userId, Status = status }; SeedTestDrive(dbContext, dbTestDrive); return(dbTestDrive); }
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); }
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)); }
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); }
public void TestTimeDefaultValue() { TestDrive td = new TestDrive(Database); Assert.AreEqual(td.Time, new TimeSpan(12, 0, 0)); }
private static void SeedTestDrive(ApplicationDbContext dbContext, TestDrive testDrive) { dbContext.TestDrives.Add(testDrive); dbContext.SaveChanges(); }