Ejemplo n.º 1
0
        public async Task <IActionResult> PutAthletes(long id, Athlete Athlete)
        {
            if (id != Athlete.Id)
            {
                return(BadRequest());
            }

            _context.Entry(Athlete).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AthleteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutBookingInfos(int id, BookingInfo BookingInfo)
        {
            if (id != BookingInfo.Id)
            {
                return(BadRequest());
            }

            _context.Entry(BookingInfo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookingInfoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 3
0
        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)
                {
                }
            }
        }
Ejemplo n.º 4
0
        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
            }));
        }