public IActionResult SaveCompetition(PersonCardioCompetiotion competition) { if (!ModelState.IsValid) { return(View("Create")); } context.Competitions.Add(competition); context.SaveChanges(); return(View("CompetitionAdded", competition)); }
public ActionResult SaveCardio(Cardio cardio) { if (!ModelState.IsValid) { return(View("Create")); } context.Cardio.Add(cardio); context.SaveChanges(); return(View("CardioAdded", cardio)); }
public IActionResult SaveCompetition(CardioContest competition) { if (!ModelState.IsValid) { return View("Create"); } context.CardioContests.Add(competition); context.SaveChanges(); return View("CompetitionAdded", competition); }
public IActionResult ValidatePerson(Person person) { if (!ModelState.IsValid) { return(View("Create")); } context.Add(person); context.SaveChanges(); return(View("PersonAdded", person)); }
public IActionResult SaveWeights(Weights weights) { if (!ModelState.IsValid) { return(View("Create")); } context.Weights.Add(weights); context.SaveChanges(); return(View("WorkoutAdded", weights)); }
public async Task <ActionResult> RegisterAsync(AuthAccount request) { var result = await _userManager.CreateAsync(new IdentityUser { UserName = request.Email, Email = request.Email, }, request.Password); if (!result.Succeeded) { return(BadRequest(new { result.Errors, })); } else { _context.UserData.Add(new UserData { User = request.Email, UserSchedule = new UserSchedule() }); _context.SaveChanges(); } return(Ok()); }
public ActionResult <Models.WorkoutModel> DeleteWorkoutFromDay(int day) { var userName = User.Claims.Single(a => a.Type == ClaimTypes.NameIdentifier).Value; var value = _context.UserData.Include(i => i.UserSchedule).Include(i => i.Workouts).Where(i => i.User == userName).First().UserSchedule; if (value == null) { return(NotFound("Schedule not found")); } var result = new Entities.Workout(); switch (day) { case 1: result = _context.Schedules.Where(i => i.Id == value.Id).First().Monday = null; break; case 2: result = _context.Schedules.Where(i => i.Id == value.Id).First().Tuesday = null; break; case 3: result = _context.Schedules.Where(i => i.Id == value.Id).First().Wednesday = null; break; case 4: result = _context.Schedules.Where(i => i.Id == value.Id).First().Thursday = null; break; case 5: result = _context.Schedules.Where(i => i.Id == value.Id).First().Friday = null; break; case 6: result = _context.Schedules.Where(i => i.Id == value.Id).First().Saturday = null; break; case 7: result = _context.Schedules.Where(i => i.Id == value.Id).First().Sunday = null; break; } _context.SaveChanges(); return(Ok()); }
public async Task SeedAsync() { _ctx.Database.EnsureCreated(); UserStore user = await _userManager.FindByEmailAsync("*****@*****.**"); if (user == null) { user = new UserStore() { FirstName = "Francesco", SecondName = "Brugnera", Email = "*****@*****.**", UserName = "******" }; var result = await _userManager.CreateAsync(user, "Password@1!"); if (result != IdentityResult.Success) { throw new InvalidOperationException("could not create user"); } } if (!_ctx.Lessons.Any()) { //sample data creation process var filepath = Path.Combine(_hosting.ContentRootPath, "Data/art.json"); var json = File.ReadAllText(filepath); var lessons = JsonConvert.DeserializeObject <IEnumerable <Lesson> >(json); _ctx.Lessons.AddRange(lessons); var order = _ctx.Orders.Where(o => o.Id == 1).FirstOrDefault(); if (order != null) { order.User = user; order.Items = new List <OrderItem>() { new OrderItem() { Lesson = lessons.First(), Quantity = 5, UnitPrice = lessons.First().Price } }; //_ctx.Orders.Add(order); } _ctx.SaveChanges(); } }
public ActionResult <Workout> PutAllWorkouts(UpdateWorkout updateWorkout) { var userName = User.Claims.Single(a => a.Type == ClaimTypes.NameIdentifier).Value; var currentUsser = _context.UserData.First(i => i.User == userName); var value = _context.Workouts .Where(i => i.UserData.User == userName && i.Id == updateWorkout.id) .Include(i => i.Exercises) .ThenInclude(i => i.Sets).First(); if (value == null) { return(NotFound("Not found")); } value.WorkoutName = updateWorkout.name; _context.SaveChanges(); return(Ok()); }
public bool SaveAll() { return(_ctx.SaveChanges() > 0); }