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;
            }
        }
Esempio n. 2
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();
            }
        }
Esempio n. 4
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();
            }
        }