Exemple #1
0
        public Log GetFitnessLog(int id)
        {
            Log log = null;

            using (var fitnessLog = new FitnessLog())
            {
                log = fitnessLog.Logs.Include("Entries").FirstOrDefault(l => l.LogID == id);
            }

            // Web API JSON Serializer does not support the EF Code First dynamic proxies
            // so we have to use projection to create a POCO version of the return types
            if (log != null)
            {
                return new Models.Log
                       {
                           LogID    = log.LogID,
                           Title    = log.Title,
                           Username = log.Username,
                           Entries  = new List <LogEntry>
                                          (log.Entries.Select(e => new LogEntry()
                    {
                        DateAndTime = e.DateAndTime, ExerciseName = e.ExerciseName, Lbs = e.Lbs, LogEntryID = e.LogEntryID, Reps = e.Reps, Set = e.Set
                    })),
                       }
            }
            ;

            return(null);
        }
        public Log AddLog(LogEntry entry)
        {
            using (var fitnessLog = new FitnessLog())
            {
                var log = fitnessLog.Logs.Find(entry.Log.LogID);

                if (log == null)
                    throw new HttpResponseException(System.Net.HttpStatusCode.NotFound);

                entry.Log = log;
                log.Entries.Add(entry);

                fitnessLog.SaveChanges();
                return log;
            }
        }
Exemple #3
0
        public Log AddLog(LogEntry entry)
        {
            using (var fitnessLog = new FitnessLog())
            {
                var log = fitnessLog.Logs.Find(entry.Log.LogID);

                if (log == null)
                {
                    throw new HttpResponseException(System.Net.HttpStatusCode.NotFound);
                }

                entry.Log = log;
                log.Entries.Add(entry);

                fitnessLog.SaveChanges();
                return(log);
            }
        }
        public void DeleteLog(LogEntry entry)
        {
            using (var fitnessLog = new FitnessLog())
            {
                var log =
                     fitnessLog.Logs.Include("Entries")
                    .FirstOrDefault(l => l.Entries.Any(e => e.LogEntryID == entry.LogEntryID));
                if (log == null)
                    throw new HttpResponseException(System.Net.HttpStatusCode.NotFound);

                var logEntry =
                    log.Entries.FirstOrDefault(e => e.LogEntryID == entry.LogEntryID);
                if (logEntry == null)
                    throw new HttpResponseException(System.Net.HttpStatusCode.NotFound);

                log.Entries.Remove(logEntry);

                fitnessLog.SaveChanges();
            }
        }
        public Log GetFitnessLog(int id)
        {
            Log log = null;
            using (var fitnessLog = new FitnessLog())
            {
                log = fitnessLog.Logs.Include("Entries").FirstOrDefault(l => l.LogID == id);
            }

            // Web API JSON Serializer does not support the EF Code First dynamic proxies
            // so we have to use projection to create a POCO version of the return types
            if (log != null)
                return new Models.Log
                {
                    LogID = log.LogID,
                    Title = log.Title,
                    Username = log.Username,
                    Entries = new List<LogEntry>
                       (log.Entries.Select(e => new LogEntry() { DateAndTime = e.DateAndTime, ExerciseName = e.ExerciseName, Lbs = e.Lbs, LogEntryID = e.LogEntryID, Reps = e.Reps, Set = e.Set })),
                };

            return null;
        }
Exemple #6
0
        public void DeleteLog(LogEntry entry)
        {
            using (var fitnessLog = new FitnessLog())
            {
                var log =
                    fitnessLog.Logs.Include("Entries")
                    .FirstOrDefault(l => l.Entries.Any(e => e.LogEntryID == entry.LogEntryID));
                if (log == null)
                {
                    throw new HttpResponseException(System.Net.HttpStatusCode.NotFound);
                }

                var logEntry =
                    log.Entries.FirstOrDefault(e => e.LogEntryID == entry.LogEntryID);
                if (logEntry == null)
                {
                    throw new HttpResponseException(System.Net.HttpStatusCode.NotFound);
                }

                log.Entries.Remove(logEntry);

                fitnessLog.SaveChanges();
            }
        }