public async Task <IActionResult> Edit(Guid id, [Bind("Id,PatientUsername,Measurement,BeforeAfter,WhichMeal,Date,Timestamp")] GlucoseEntry GlucoseEntries) { if (id != GlucoseEntries.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(GlucoseEntries); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GlucoseEntriesExists(GlucoseEntries.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(GlucoseEntries)); }
} // Create public async Task UpdateAsync( Guid id, GlucoseEntry glucoseEntry ) { var dbGlucoseEntry = await ReadAsync( id ); if( dbGlucoseEntry != null ) { if( Config.AuditingOn ) { var auditChange = new AuditChange(); auditChange.CreateAuditTrail( AuditActionType.UPDATE, dbGlucoseEntry.Id.ToString(), dbGlucoseEntry, glucoseEntry ); await _auditRepo.CreateAsync( auditChange ); } // if dbGlucoseEntry.UserName = glucoseEntry.UserName; dbGlucoseEntry.Patient = glucoseEntry.Patient; dbGlucoseEntry.Measurement = glucoseEntry.Measurement; dbGlucoseEntry.BeforeAfter = glucoseEntry.BeforeAfter; dbGlucoseEntry.WhichMeal = glucoseEntry.WhichMeal; dbGlucoseEntry.CreatedAt = glucoseEntry.CreatedAt; dbGlucoseEntry.UpdatedAt = glucoseEntry.UpdatedAt; dbGlucoseEntry.Timestamp = glucoseEntry.Timestamp; _db.Entry( dbGlucoseEntry ).State = EntityState.Modified; await _db.SaveChangesAsync(); return; } } // UpdateAsync
} // ReadAll public async Task<GlucoseEntry> CreateAsync( GlucoseEntry GlucoseEntries ) { _db.GlucoseEntries.Add( GlucoseEntries ); await _db.SaveChangesAsync(); return GlucoseEntries; } // Create
} // ReadAll public async Task<GlucoseEntry> CreateAsync( GlucoseEntry glucoseentry ) { _db.GlucoseEntries.Add( glucoseentry ); await _db.SaveChangesAsync(); return glucoseentry; } // Create
public async Task <IActionResult> Create([Bind("Id,UserName,Measurement,BeforeAfter,WhichMeal,Date,Timestamp")] GlucoseEntry GlucoseEntries) { if (ModelState.IsValid) { GlucoseEntries.Id = Guid.NewGuid(); _context.Add(GlucoseEntries); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(GlucoseEntries)); }
public async Task <IActionResult> NewGlucose(GlucoseEntry glucoseEntry) { if (ModelState.IsValid) { _context.GlucoseEntry.Add(glucoseEntry); await _context.SaveChangesAsync(); return(Ok()); } else { return(BadRequest()); } }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } GlucoseEntry = await _context.GlucoseEntry.FirstOrDefaultAsync(m => m.Id == id); if (GlucoseEntry == null) { return(NotFound()); } return(Page()); }
} // 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 GlucoseEntriesViewModel { 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
public GlucoseDetailPage() { InitializeComponent(); var item = new GlucoseEntry { BloodSugar = 40, Date = DateTime.Now, Meal = GlucoseEntry.MealType.Breakfast, Reading = GlucoseEntry.ReadingType.PreMeal, Username = App.User.UserName }; viewModel = new GlucoseDetailViewModel(item); BindingContext = viewModel; }
} // ReadAll public async Task<GlucoseEntry> CreateAsync( GlucoseEntry glucoseEntry ) { _db.GlucoseEntries.Add( glucoseEntry ); await _db.SaveChangesAsync(); if( Config.AuditingOn ) { var auditChange = new AuditChange(); auditChange.CreateAuditTrail( AuditActionType.CREATE, glucoseEntry.Id.ToString(), new GlucoseEntry(), glucoseEntry ); await _auditRepo.CreateAsync( auditChange ); } // if return glucoseEntry; } // Create
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } GlucoseEntry = await _context.GlucoseEntry.FindAsync(id); if (GlucoseEntry != null) { _context.GlucoseEntry.Remove(GlucoseEntry); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
} // DeleteAsync public async Task CreateOrUpdateEntries( ICollection<GlucoseEntry> glucoseEntries ) { foreach( GlucoseEntry glucoseEntry in glucoseEntries ) { GlucoseEntry dbGlucoseEntry = await ReadAsync( glucoseEntry.Id ); if( !Exists( glucoseEntry.Id ) ) // If GlucoseEntry doesn't exist { await CreateAsync( glucoseEntry ); // Create in the database } else if( dbGlucoseEntry.UpdatedAt < glucoseEntry.UpdatedAt ) { await UpdateAsync( glucoseEntry.Id, glucoseEntry ); // Update in the database } } return; } // CreateOrUpdateEntries
} // Create public async Task UpdateAsync( Guid id, GlucoseEntry GlucoseEntry ) { var oldGlucoseEntries = await ReadAsync( id ); if( oldGlucoseEntries != null ) { oldGlucoseEntries.UserName = GlucoseEntry.UserName; oldGlucoseEntries.Patient = GlucoseEntry.Patient; oldGlucoseEntries.Measurement = GlucoseEntry.Measurement; oldGlucoseEntries.BeforeAfter = GlucoseEntry.BeforeAfter; oldGlucoseEntries.WhichMeal = GlucoseEntry.WhichMeal; oldGlucoseEntries.CreatedAt = GlucoseEntry.CreatedAt; oldGlucoseEntries.UpdatedAt = GlucoseEntry.UpdatedAt; oldGlucoseEntries.Timestamp = GlucoseEntry.Timestamp; _db.Entry( oldGlucoseEntries ).State = EntityState.Modified; await _db.SaveChangesAsync(); return; } } // UpdateAsync
} // DeleteAsync public async Task CreateOrUpdateEntries( ICollection<GlucoseEntry> glucoseEntries ) { foreach ( GlucoseEntry glucoseEntry in glucoseEntries ) { GlucoseEntry dbGlucoseEntry = await ReadAsync( glucoseEntry.Id ); if ( dbGlucoseEntry == null ) // If meal entry doesn't exist { // Create in the database await CreateAsync( glucoseEntry ); } else if ( dbGlucoseEntry.UpdatedAt < glucoseEntry.UpdatedAt ) { // Update in the database await UpdateAsync( glucoseEntry.Id, glucoseEntry ); } } // foreach MealEntry return; } // CreateOrUpdateEntries
public async Task <IActionResult> CreateGlucoseEntry(string userName, Guid loginToken, GlucoseEntry glucoseEntry) { // Get user from username, verify login token var user = await _users.ReadAsync(userName); if (user.RemoteLoginToken != loginToken) // Check login token { return(new JsonResult( // Return error new { success = false, errorCode = ErrorCode.INVALID_LOGIN_TOKEN } )); } // if if (!_glucose.ReadAll().Any(o => o.Id == glucoseEntry.Id))// Ensure glucose doesn't exist first { return(new JsonResult( // If it does, return error new { success = false, errorCode = ErrorCode.ITEM_ALREADY_EXISTS } )); } if (ModelState.IsValid) { var newGlucoseEntry = await _glucose.CreateAsync(glucoseEntry); return(new JsonResult( // Return success new { success = true, errorCode = ErrorCode.NO_ERROR, newGlucoseEntry.Id } )); } // if return(new JsonResult( // Return unknown error new { success = false, errorCode = ErrorCode.UNKNOWN } )); } // CreateGlucoseEntry
public GlucoseEntryPage() { InitializeComponent(); Entry = new GlucoseEntry(); }
public GlucoseDetailViewModel(GlucoseEntry entry = null) { Title = entry?.Date.ToShortDateString() + entry?.Reading + entry?.Meal; Glucose = entry; }