Example #1
0
        } // CreateGlucoseEntry

        public async Task <IActionResult> GlucoseEntryUpdate(string userName, Guid loginToken, Guid glucoseId)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = await _users.ReadAsync(userName); // Read user from the repository

                user.RemoteLoginToken = Guid.NewGuid();                  // Create a login token, similar to a "session id"
                GlucoseEntry glucose = await _glucose.ReadAsync(glucoseId);

                var glucoseModel = new GlucoseEntryViewModel
                {
                    PatientUsername = glucose.UserName,
                    Patient         = glucose.Patient,
                    Measurement     = glucose.Measurement,
                    BeforeAfter     = glucose.BeforeAfter,
                    WhichMeal       = glucose.WhichMeal,
                    Date            = glucose.CreatedAt,
                    Timestamp       = glucose.Timestamp,
                };


                await _glucose.UpdateAsync(glucose.Id, glucoseModel.GetNewGlucoseEntries());

                return(new JsonResult(                                  // This implements IActionResult. If you were
                           new                                          //      to inspect the output, you would see a
                {                                                       //      Json-formatted string.
                    success = true,
                    errorCode = ErrorCode.NO_ERROR,
                    remoteGlucoseToken = _glucose.ToString(),
                    glucose.UserName,
                    glucose.Patient,
                    glucose.Measurement,
                    glucose.BeforeAfter,
                    glucose.WhichMeal,
                    glucose.CreatedAt,
                    glucose.Timestamp
                }
                           ));
            }//end if(ModelState.IsValid)

            return(new JsonResult(
                       new
            {
                success = false,
                errorCode = ErrorCode.UNKNOWN
            }
                       ));
        }//end GlucoseEntryUpdate
Example #2
0
        } // Create


        public async Task UpdateAsync( Guid id, GlucoseEntryViewModel glucoseentryVM )
        {
            var oldGlucoseEntry = await ReadAsync( id );
            if( oldGlucoseEntry != null )
            {
    			oldGlucoseEntry.PatientUsername = glucoseentryVM.PatientUsername;
    			oldGlucoseEntry.Patient = glucoseentryVM.Patient;
    			oldGlucoseEntry.Measurement = glucoseentryVM.Measurement;
    			oldGlucoseEntry.BeforeAfter = glucoseentryVM.BeforeAfter;
    			oldGlucoseEntry.WhichMeal = glucoseentryVM.WhichMeal;
    			oldGlucoseEntry.Date = glucoseentryVM.Date;
    			oldGlucoseEntry.Timestamp = glucoseentryVM.Timestamp;
                _db.Entry( oldGlucoseEntry ).State = EntityState.Modified;
                await _db.SaveChangesAsync();
                return;
            }

        } // UpdateAsync