public Guid CreateHealthMeasure(HealthMeasureViewData healthMeasureViewData) { using (var entities = this.EntityContext) { var healthMeasureEntity = new HealthMeasure { Id = Guid.NewGuid() }; entities.AddToHealthMeasure(healthMeasureEntity); this.SaveOrUpdateHealthMeasure(healthMeasureViewData, healthMeasureEntity, entities); entities.SaveChanges(); return healthMeasureEntity.Id; } }
private void SaveOrUpdateHealthMeasure(HealthMeasureViewData healthMeasureViewData, HealthMeasure healthMeasureEntity, ZoosManagementSystemEntities entities) { healthMeasureEntity.MeasurementDate = DateTime.Parse(healthMeasureViewData.MeasurementDate); healthMeasureEntity.Height = healthMeasureViewData.Height; healthMeasureEntity.Weight = healthMeasureViewData.Weight; healthMeasureEntity.Temperature = healthMeasureViewData.Temperature; healthMeasureEntity.Notes = healthMeasureViewData.Notes; healthMeasureEntity.Vaccine = healthMeasureViewData.Vaccine; var animalId = new Guid(healthMeasureViewData.AnimalId); healthMeasureEntity.Animal = entities.Animal.FirstOrDefault(a => a.Id == animalId); }