public ActionResult <WeightLogEntriesDTO> GetUserWeightHistory(string id) { // TODO Perform authorization // TODO Handle null case var user = this.Database.Users .Where(x => x.Id == id) .Select(x => new { x.Weights }) .FirstOrDefault(); var rv = new WeightLogEntriesDTO(); rv.Entries = new List <WeightLogEntryDTO>(); foreach (var weightLogEntry in user.Weights) { rv.Entries.Add(new WeightLogEntryDTO { Timestamp = weightLogEntry.Timestamp.ToString(), Value = weightLogEntry.Weight }); } // TODO Return appropriate status code return(rv); }
public ActionResult <WeightLogEntriesDTO> GetUserWeightHistory(int id) { using (var db = new SqliteContext()) { try { var user = db.Users .Where(x => x.Id == id) .Select(x => new { x.Weights }) .ToList()[0]; var rv = new WeightLogEntriesDTO(); rv.Entries = new List <WeightLogEntryDTO>(); foreach (var weightLogEntry in user.Weights) { rv.Entries.Add(new WeightLogEntryDTO { Timestamp = weightLogEntry.Timestamp.ToString(), Value = weightLogEntry.Weight }); } return(rv); } catch (ArgumentOutOfRangeException) { return(StatusCode(404)); } } }