public void CreateAsync_ReturnsCorrectReservationId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            using (var dbContext = new ApplicationDbContext(options))
            {
                var user = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**"
                };
                dbContext.Users.Add(user);
                dbContext.SaveChanges();

                CreateReservationServiceModel reservation = new CreateReservationServiceModel
                {
                    VehicleMake         = "BMW",
                    VehicleModel        = "M5",
                    LicenseNumber       = "СА 1234 КР",
                    PhoneNumber         = "0897482124",
                    ReservationDateTime = new DateTime(2020, 3, 21, 10, 30, 10),
                    Username            = user.UserName,
                };

                var reservationsService = new ReservationsService(dbContext);
                var result         = reservationsService.CreateAsync(reservation);
                var reservationObj = dbContext.Reservations.FirstOrDefaultAsync();

                Assert.Equal(reservationObj.Result.Id, result.Result);
            }
        }
Exemple #2
0
        public async Task <IActionResult> ByName(ReservationInputModel model)
        {
            string username = this.User.Identity.Name;

            if (!this.ModelState.IsValid)
            {
                return(this.PartialView("~/Views/ServiceTypes/_ReservationModalForm.cshtml", model));
            }

            var reservation = new CreateReservationServiceModel
            {
                VehicleMake         = model.VehicleMake,
                VehicleModel        = model.VehicleModel,
                LicenseNumber       = model.LicenseNumber,
                ReservationDateTime = DateTime.ParseExact(model.ReservationDateTime, "dd-MM-yyyy HH:mm", CultureInfo.InvariantCulture),
                PhoneNumber         = model.PhoneNumber,
                ServiceId           = model.ServiceId,
                OperatingLocationId = model.OperatingLocationId,
                Username            = username,
            };

            await this.reservationsService.CreateAsync(reservation);

            if (this.User.IsInRole("User"))
            {
                return(this.RedirectToAction("MyReservations", "Reservations"));
            }

            return(this.RedirectToAction("ByName"));
        }
Exemple #3
0
        //TODO: Add docs
        public async Task <string> CreateAsync(CreateReservationServiceModel model)
        {
            string userId = this.dbContext.Users.Where(x => x.UserName == model.Username)
                            .Select(x => x.Id)
                            .FirstOrDefault();

            //If no such user, assign userId to GUEST USER (people that want to do reservations without having an account)
            if (userId == null)
            {
                var test = this.dbContext.Users.FirstOrDefault(x => x.UserName == "GuestUser").Id;
                userId = test;
            }

            Reservation reservation = new Reservation
            {
                IsActive            = true,
                VehicleMake         = model.VehicleMake,
                VehicleModel        = model.VehicleModel,
                LicenseNumber       = model.LicenseNumber,
                PhoneNumber         = model.PhoneNumber,
                ReservationDateTime = model.ReservationDateTime,

                ServiceId           = model.ServiceId,
                OperatingLocationId = model.OperatingLocationId,

                UserId = userId,
            };

            //reservation.Service.OperatingLocations.Add

            await this.dbContext.Reservations.AddAsync(reservation);

            await this.dbContext.SaveChangesAsync();

            return(reservation.Id);
        }