public async Task <IHttpActionResult> PutLTBloodGlucoseReport(long id, LTBloodGlucoseReport lTBloodGlucoseReport)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != lTBloodGlucoseReport.LTBloodGlucoseReportId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> GetLTBloodGlucoseReport(string Id)
        {
            LTBloodGlucoseReport lTBloodGlucoseReport = await db.LTBloodGlucoseReports.Include(p => p.SelfHelpCourses).FirstOrDefaultAsync(p => p.ReportingClinicName == Id); // Where(p => p.ReportingClinicName == id);

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

            return(Ok(lTBloodGlucoseReport));
        }
        public async Task <IHttpActionResult> GetLTBloodGlucoseReport(long id)
        {
            LTBloodGlucoseReport lTBloodGlucoseReport = await db.LTBloodGlucoseReports.FindAsync(id);

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

            return(Ok(lTBloodGlucoseReport));
        }
示例#4
0
        public async Task <IHttpActionResult> PostLTBloodGlucoseReport(LTBloodGlucoseReport lTBloodGlucoseReport)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.LTBloodGlucoseReports.Add(lTBloodGlucoseReport);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = lTBloodGlucoseReport.LTBloodGlucoseReportId }, lTBloodGlucoseReport));
        }
        public async Task <IHttpActionResult> DeleteLTBloodGlucoseReport(long id)
        {
            LTBloodGlucoseReport lTBloodGlucoseReport = await db.LTBloodGlucoseReports.FindAsync(id);

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

            db.LTBloodGlucoseReports.Remove(lTBloodGlucoseReport);
            await db.SaveChangesAsync();

            return(Ok(lTBloodGlucoseReport));
        }
        public async Task <IHttpActionResult> DeleteLTBloodGlucoseReport(long Id)
        {
            LTBloodGlucoseReport lTBloodGlucoseReport = await db.LTBloodGlucoseReports.Include(r => r.SelfHelpCourses).FirstOrDefaultAsync(p => p.LTBloodGlucoseReportId == Id);

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

            foreach (var shc in lTBloodGlucoseReport.SelfHelpCourses.ToList())
            {
                db.SelfHelpCourses.Remove(shc);
            }
            db.LTBloodGlucoseReports.Remove(lTBloodGlucoseReport);
            await db.SaveChangesAsync();

            return(Ok(lTBloodGlucoseReport));
        }
示例#7
0
        public async Task <IHttpActionResult> PutLTBloodGlucoseReport(long Id, LTBloodGlucoseReport lTBloodGlucoseReport)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (Id != lTBloodGlucoseReport.LTBloodGlucoseReportId)
            {
                return(BadRequest());
            }

            /*
             * http://stackoverflow.com/questions/25078798/new-subentity-will-not-save-when-parent-entity-is-saved
             * */
            foreach (var e in lTBloodGlucoseReport.SelfHelpCourses)
            {
                db.Entry(e).State = e.SelfHelpCourseID == 0 ? EntityState.Added : EntityState.Modified;
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }