/// <summary> /// Create data in database /// </summary> /// <param name="bodyExercise">Data</param> /// <returns>insert data</returns> public BodyExercise Create(BodyExercise bodyExercise) { if (bodyExercise == null) return null; if (bodyExercise.Id == 0) { var key = new BodyExerciseKey(); var sequencerManager = new SequencerManager(); do { key.Id = sequencerManager.GetNextValue(_dbContext, 2, "bodyExercise"); } while (Get(key) != null); // Test Record exist bodyExercise.Id = key.Id; } if (bodyExercise.Id == 0) return null; var bodyExerciseRow = new BodyExerciseRow(); BodyExerciseTransformer.ToRow(bodyExercise, bodyExerciseRow); _dbContext.BodyExercise.Add(bodyExerciseRow); _dbContext.SaveChanges(); return BodyExerciseTransformer.ToBean(bodyExerciseRow); }
public static void ToRow(BodyExercise bean, BodyExerciseRow row) { if (bean == null) return; row.Id = bean.Id; row.MuscleId = bean.MuscleId; }
internal static BodyExercise ToBean(BodyExerciseRow row) { if (row == null) return null; var bean = new BodyExercise(); bean.Id = row.Id; //Image name is "{id}.png" bean.ImageName = string.Format("{0}.png", row.Id); bean.MuscleId = row.MuscleId; return bean; }