public override WeightEntry Add(WeightEntry entity) { // find existing program in DB var program = _dbContext.Programs.FirstOrDefault(p => String.Equals(p.Name, entity.Program.Name)); //if there's already a program with the same name then //update the input model's program with the existing program's info if (program != null) { entity.ProgramId = program.Id; entity.Program = program; } // get the tracked entity after adding (that has been updated thus far) var trackedEntity = _dbContext.WeightEntries.Add(entity); //save changes to get generatedId for the entry //if no changes/addtion are done then there's an issue if (_dbContext.SaveChanges() < 1) { return(null); } //update note's info once entity's id has been generated trackedEntity.Entity.Note.WeightEntryId = entity.Id; _dbContext.SaveChanges(); return(trackedEntity.Entity); }
public void Save() { _dbContext.SaveChanges(); }