public IActionResult SignUp(TourSlot tourslot) { savedID = tourslot.TourSlotID; savedTime = tourslot.TimeInfo; ViewBag.Time = savedTime; Context.TourSlots.First(x => x.TourSlotID == savedID).Available = false; Context.SaveChanges(); // Update the slot to be available = false // Set ViewData = slot //ViewData["tourslot"] = slot; return(View("ReservationInfo")); }
public AuthenticateResponse AuthenticateGoogle(AuthenticateRequestGoogle request) { if (request == null) { return(null); } if (request.Token == null) { return(null); } var httpClient = new HttpClient(); var requestUri = new Uri(string.Format(Constants.GoogleApiTokenInfoUrl, request.Token)); GoogleTokenInfo tokenInfo; try { HttpResponseMessage httpResponseMessage = httpClient.GetAsync(requestUri).Result; if (httpResponseMessage.StatusCode != HttpStatusCode.OK) { return(null); } tokenInfo = JsonConvert.DeserializeObject <GoogleTokenInfo>(httpResponseMessage.Content.ReadAsStringAsync().Result); } catch (Exception ex) { return(null); } if (tokenInfo.aud != Constants.GoogleClientId) { return(null); } User user = _context.Users.FirstOrDefault(u => u.Login == tokenInfo.email && u.UserType == UserType.Google); if (user == null) //login not found! Create user { user = new User() { Login = tokenInfo.email, UserType = UserType.Google, Email = tokenInfo.email }; _context.Users.Add(user); _context.SaveChanges(); } string token = generateJwtToken(user); return(new AuthenticateResponse() { Token = token }); }
public async Task <IActionResult> AddStop(int StationId, int TrainId, string Time) { DateTime date = DateTime.ParseExact(Time, "yyyy-MM-dd-HH-mm", CultureInfo.InvariantCulture); Stop stop = new Stop() { StationId = StationId, TrainId = TrainId, StopDateTime = date }; _context.Stops.Add(stop); _context.SaveChanges(); return(Ok()); }
public IActionResult SaveCar(Car car) { Car carFromDb = _context.Cars.FirstOrDefault(c => c.Name == car.Name); if (carFromDb != null) { return(Conflict()); } _context.Add(car); _context.SaveChanges(); return(Ok()); }
public async Task <IActionResult> Resign(int id) { User user = HttpContext.Items[Constants.UserKey] as User; if (user == null) { return(Unauthorized()); } var userId = user.Id; var reservation = _context.Reservations.Include(r => r.From).FirstOrDefault(r => r.UserId == userId && r.ReservationId == id); if (reservation == null) { return(Unauthorized()); } if (reservation.From.StopDateTime <= DateTime.Now) { return(BadRequest("This reservation cannot be canceled!")); } var places = _context.PlaceReservations.Where(pr => pr.ReservationId == id).ToList(); foreach (PlaceReservation place in places) { _context.PlaceReservations.Remove(place); _context.SaveChanges(); } _context.Reservations.Remove(reservation); _context.SaveChanges(); return(Ok()); }
// [Authorize(Policy = "OnlySiteAdmin")] public async Task <ActionResult <int> > NukeDb(string command) { if (command != "drop") { return(BadRequest("You don't want to nuke db, don't you?")); } // _context.Database.EnsureDeleted(); /*var sql = @"DECLARE @tableName VARCHAR(200) * SET @tableName='' * WHILE EXISTS * ( * --Find all child tables AND those which have no relations * SELECT T.table_name FROM INFORMATION_SCHEMA.TABLES T * LEFT OUTER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC * ON T.table_name=TC.table_name * WHERE (TC.constraint_Type ='Foreign Key'or TC.constraint_Type IS NULL) AND * T.table_name NOT IN ('dtproperties','sysconstraints','syssegments')AND * Table_type='BASE TABLE' AND T.table_name > @TableName * ) * BEGIN * SELECT @tableName=min(T.table_name) FROM INFORMATION_SCHEMA.TABLES T * LEFT OUTER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC * ON T.table_name=TC.table_name * WHERE (TC.constraint_Type ='Foreign Key'or TC.constraint_Type IS NULL) AND * T.table_name NOT IN ('dtproperties','sysconstraints','syssegments') AND * Table_type='BASE TABLE' AND T.table_name > @TableName * --Truncate the table * EXEC('DELETE FROM '+@tablename) * PRINT 'DELETE FROM '+@tablename * END * * SET @TableName='' * WHILE EXISTS * ( * --Find all Parent tables * SELECT T.table_name FROM INFORMATION_SCHEMA.TABLES T * LEFT OUTER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC * ON T.table_name=TC.table_name * WHERE TC.constraint_Type ='Primary Key'AND T.table_name <>'dtproperties' AND * Table_type='BASE TABLE' AND T.table_name > @TableName * ) * BEGIN * SELECT @tableName=min(T.table_name) FROM INFORMATION_SCHEMA.TABLES T * LEFT OUTER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC ON T.table_name=TC.table_name * WHERE TC.constraint_Type ='Primary Key' AND T.table_name <>'dtproperties' AND * Table_type='BASE TABLE' AND T.table_name > @TableName * * --DELETE the table * EXEC('DELETE FROM '+ @tableName) * PRINT 'DELETE FROM '+ @tableName * --Reset identity column * If EXISTS * ( * SELECT * FROM information_schema.columns * WHERE COLUMNPROPERTY(OBJECT_ID(QUOTENAME(table_schema)+'.'+ * QUOTENAME(@tableName)), column_name,'IsIdentity')=1 * ) * BEGIN * DBCC CHECKIDENT (@tableName, RESEED, 1) * PRINT @tableName * END * END * ";*/ /*using (var trans = _context.Database.BeginTransaction()) * {*/ // _context.Users.RemoveRange(_context.Users); _context.Fields.RemoveRange(_context.Fields); _context.Sites.RemoveRange(_context.Sites); _context.Floor.RemoveRange(_context.Floor); _context.Building.RemoveRange(_context.Building); _context.Image.RemoveRange(_context.Image); _context.Locations.RemoveRange(_context.Locations); _context.Regions.RemoveRange(_context.Regions); _context.Rooms.RemoveRange(_context.Rooms); _context.ReservationModels.RemoveRange(_context.ReservationModels); _context.SaveChanges(); /*var res = _context.Database.ExecuteSqlRaw(sql);*/ // _context.Database.CommitTransaction(); // trans.Commit(); /*}*/ // _context.Database.Migrate(); return(Ok()); }
public static void SeedData(ReservationsDbContext dBContext) { if (!dBContext.Reservations.Any()) { dBContext.Reservations.Add(new DB.Reservation() { CPF = "00000000000", VehicleID = 2, RentalPricePerHour = 25, StartDate = new DateTime(2021, 1, 1), EndDate = new DateTime(2021, 1, 10), IsCarReturned = true, IsCarClean = true, IsCarDamaged = false, IsFuelTankFull = true, RentalPricePerHourAfterReturn = 25 }); dBContext.Reservations.Add(new DB.Reservation() { CPF = "00000000000", VehicleID = 1, RentalPricePerHour = 10, StartDate = new DateTime(2021, 4, 12), EndDate = new DateTime(2021, 4, 20), IsCarReturned = false, IsCarClean = true, IsCarDamaged = false, IsFuelTankFull = true, RentalPricePerHourAfterReturn = 10 }); dBContext.Reservations.Add(new DB.Reservation() { CPF = "00000000000", VehicleID = 5, RentalPricePerHour = 7, StartDate = new DateTime(2021, 5, 12), EndDate = new DateTime(2021, 5, 20), IsCarReturned = false, IsCarClean = true, IsCarDamaged = false, IsFuelTankFull = true, RentalPricePerHourAfterReturn = 7 }); dBContext.Reservations.Add(new DB.Reservation() { CPF = "00000000000", VehicleID = 8, RentalPricePerHour = 4, StartDate = new DateTime(2021, 5, 12), EndDate = DateTime.Now, IsCarReturned = false, IsCarClean = true, IsCarDamaged = false, IsFuelTankFull = true, RentalPricePerHourAfterReturn = 4 }); dBContext.Reservations.Add(new DB.Reservation() { CPF = "00000000001", VehicleID = 10, RentalPricePerHour = 9, StartDate = new DateTime(2021, 4, 12), EndDate = new DateTime(2021, 4, 18), IsCarReturned = false, IsCarClean = true, IsCarDamaged = false, IsFuelTankFull = true, RentalPricePerHourAfterReturn = 9 }); dBContext.Reservations.Add(new DB.Reservation() { CPF = "00000000002", VehicleID = 4, RentalPricePerHour = 50, StartDate = new DateTime(2021, 4, 15), EndDate = new DateTime(2021, 4, 25), IsCarReturned = false, IsCarClean = true, IsCarDamaged = false, IsFuelTankFull = true, RentalPricePerHourAfterReturn = 50 }); dBContext.SaveChanges(); } }