Example #1
0
        public async Task <IHttpActionResult> PutJoggingRecord(int id, JoggingRecord joggingRecord)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != joggingRecord.Id)
            {
                return(BadRequest());
            }

            db.Entry(joggingRecord).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!JoggingRecordExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> GetJoggingRecord(int id)
        {
            JoggingRecord joggingRecord = await db.JoggingRecords.FindAsync(id);

            if (joggingRecord == null)
            {
                return(NotFound());
            }

            return(Ok(joggingRecord));
        }
Example #3
0
        public async Task <IHttpActionResult> PostJoggingRecord(JoggingRecord joggingRecord)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.JoggingRecords.Add(joggingRecord);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = joggingRecord.Id }, joggingRecord));
        }
Example #4
0
        public async Task <IHttpActionResult> DeleteJoggingRecord(int id)
        {
            JoggingRecord joggingRecord = await db.JoggingRecords.FindAsync(id);

            if (joggingRecord == null)
            {
                return(NotFound());
            }

            db.JoggingRecords.Remove(joggingRecord);
            await db.SaveChangesAsync();

            return(Ok(joggingRecord));
        }
        public JoggingRecord GetJoggingRecord(int id)
        {
            JoggingRecord joggingRecord = JoggingRecords.Where(r => r.Id == id).FirstOrDefault();

            return(joggingRecord);
        }