bool ChangeLevel(int userId, int curLevel) { var isReaload = false; var results = db.PatientsResults .Where(r => r.UserId == userId && r.Level == curLevel) .OrderByDescending(r => r.Date) .ThenByDescending(r => r.Id) .Take(3) .ToArray(); if (results.Count() == 3) { var minResult = results.Min(r => r.Result); var level = db.UserLevels.FirstOrDefault(l => l.UserId == userId); if (minResult > 90 && level.Level < 7) { level.Level++; db.Entry(level).State = EntityState.Modified; isReaload = true; } else if (minResult < 30 && level.Level > 3) { level.Level--; db.Entry(level).State = EntityState.Modified; isReaload = true; } } db.SaveChanges(); return(isReaload); }
public async Task <IActionResult> PutTodoItem(string id, Product product) { if (id != product.Id) { return(BadRequest()); } _ctx.Entry(product).State = EntityState.Modified; try { await _ctx.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit([Bind(Include = "WorkoutId,AthleteId,WorkoutType,WorkoutDate,WorkoutDistance,WorkoutHours,WorkoutMinutes,WorkoutSeconds,AverageHeartRate,PreviousNightSleepHours,PreviousNightSleepMinutes")] Workout workout) { if (ModelState.IsValid) { db.Entry(workout).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(workout)); }
public async Task <IActionResult> PutUserTiles(Guid id, UserTiles payload) { if (id != payload.Guid) { return(BadRequest()); } var userTile = await _context.UserTiles.FindAsync(id); if (userTile == null) { return(NotFound()); } if (!IsUserAllowed(userTile)) { return(Forbid()); } //Reset the username so the username can't be edited payload.Username = GetUsername(); //Deatach _context.Entry(userTile).State = EntityState.Detached; //Modify _context.Entry(payload).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserTilesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit([Bind(Include = "Id,Title,Excerpts,Content")] MTB_Articles mTB_Articles) { if (ModelState.IsValid) { db.Entry(mTB_Articles).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(mTB_Articles)); }
public ActionResult Edit([Bind(Include = "AthleteId,FirstName,LastName,Email")] Athlete athlete) { if (ModelState.IsValid) { db.Entry(athlete).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(athlete)); }