public async Task SaveAsync(Teacher entity) { try { if (entity == null) { return; } using (var timeLineContext = _contextFactory.GetTimeLineContext()) { var entityModel = await timeLineContext .Teachers .FirstOrDefaultAsync(item => item.Id.Equals(entity.Id)); if (entityModel == null) { entityModel = new DA.Teacher(); MapForUpdateentity(entity, entityModel); await timeLineContext.Teachers.AddAsync(entityModel); } else { MapForUpdateentity(entity, entityModel); } timeLineContext.SaveChanges(); } } catch (Exception ex) { throw ex; } }
private void MapForUpdateentity(Teacher entity, DA.Teacher daEntity) { daEntity.Id = entity.Id; }