public AthletesController() //(BookingsDBContext context) { DbContextOptions <ApplicationDbContext> optionsBuilder = new DbContextOptions <ApplicationDbContext>(); //optionsBuilder.UseSqlite("Data Source=data.db"); _context = new BookingsDBContext(); System.Diagnostics.Debug.WriteLine("==AthletesController=="); }
public IEnumerable <UserInfo0> getusers() { List <UserInfo0> users; using (var db = new BookingsDBContext()) { var vusers = from b in db.AspNetUsers select b; users = vusers.ToList <UserInfo0>(); } return(users); }
public IEnumerable <BookingInfo> getbookings() { List <BookingInfo> bookings; using (var db = new BookingsDBContext()) { var vbookings = from b in db.BookingInfo select b; bookings = vbookings.ToList <BookingInfo>(); } return(bookings); }
public UserInfo0 getUser(string name) { UserInfo0 user; using (var db = new BookingsDBContext()) { var vUser = from u in db.AspNetUsers where (u.UserName == name) select u; user = vUser.FirstOrDefault <UserInfo0>(); } return(user); }
public bool Count(string name) { UserInfo0 usr; using (var db = new BookingsDBContext()) { var user = from u in db.AspNetUsers where (u.UserName == name) select u; usr = user.FirstOrDefault <UserInfo0>(); } return(usr.IsAdmin); }
public Athlete getAthlete(string name) { Athlete Athlete; using (var db = new BookingsDBContext()) { var vAthlete = from u in db.Athletes where (u.UserName == name) select u; Athlete = vAthlete.FirstOrDefault <Athlete>(); } return(Athlete); }
public async Task AddBooking(BookingInfo booking) { using (var db = new BookingsDBContext()) { try { await db.BookingInfo.AddAsync(booking); await db.SaveChangesAsync(); var bookings = db.BookingInfo.ToList(); } catch (Exception ex) { } } }
public async Task <IActionResult> Register(RegisterParameters parameters) { var user = new ApplicationUser(); user.UserName = parameters.UserName; var result = await _userManager.CreateAsync(user, parameters.Password); if (!result.Succeeded) { return(BadRequest(result.Errors.FirstOrDefault()?.Description)); } var usr = await _userManager.FindByNameAsync(user.UserName); usr.Email = parameters.Email; usr.PhoneNumber = parameters.Phone; await _userManager.UpdateAsync(usr); Athlete athlete; using (BookingsDBContext db = new BookingsDBContext()) { athlete = new Athlete { Id = 0, UserName = user.UserName, Email = user.Email, HasAccessCard = user.HasAccessCard, IsAdmin = user.IsAdmin, IsCoach = user.IsCoach, PhoneNumber = user.PhoneNumber }; try { await db.Athletes.AddAsync(athlete); await db.SaveChangesAsync(); var athletes = db.Athletes.ToList(); athlete = athletes[0]; System.Diagnostics.Debug.WriteLine(athlete.Id); } catch (Microsoft.Data.Sqlite.SqliteException sqlEx) { System.Diagnostics.Debug.WriteLine(sqlEx.Message); System.Diagnostics.Debug.WriteLine(sqlEx.InnerException); } } System.Diagnostics.Debug.WriteLine(athlete.Id); //using (BookingsDBContext db2 = new BookingsDBContext()) //{ // athlete.Id = 1; // System.Diagnostics.Debug.WriteLine("====Doing Athlete mirror of user===="); // var booking = new BookingInfo // { // Id = 0, // Date = new DateTime(2020, 2, 15), // _Time = 12, // _Duration = 2, // Slot = 1, // AthleteId = athlete.Id // }; // System.Diagnostics.Debug.WriteLine("====Done Athlete mirror of user===="); // try // { // // db2.Attach<BookingInfo>(booking); // System.Diagnostics.Debug.WriteLine("====Doing Booking mirror db - 2===="); // await db2.BookingInfo.AddAsync(booking); // System.Diagnostics.Debug.WriteLine("====Doing Booking mirror db - 3===="); // await db2.SaveChangesAsync(); // System.Diagnostics.Debug.WriteLine("====Doing Booking mirror db - 4r===="); // } // catch (Microsoft.Data.Sqlite.SqliteException sqlEx) // { // System.Diagnostics.Debug.WriteLine("====Doing Athlete mirror db Error"); // System.Diagnostics.Debug.WriteLine(sqlEx.Message); // System.Diagnostics.Debug.WriteLine(sqlEx.InnerException); // } // catch (Exception Ex) // { // System.Diagnostics.Debug.WriteLine("====Doing Athlete mirror db Error"); // System.Diagnostics.Debug.WriteLine(Ex.Message); // System.Diagnostics.Debug.WriteLine(Ex.InnerException); // } //} return(await Login(new LoginParameters { UserName = parameters.UserName, Password = parameters.Password })); }
public BookingsController(BookingsDBContext context) { _context = context; }