public async Task <int> SaveAsync(BL.Role entity) { try { if (entity == null) { return(0); } using (var context = _contextFactory.GetProductContext()) { var entityModel = await context .Roles .FirstOrDefaultAsync(item => item.Id.Equals(entity.Id)); if (entityModel == null) { entityModel = new DA.Role(); MapForUpdateEntity(entity, entityModel); await context.Roles.AddAsync(entityModel); } else { MapForUpdateEntity(entity, entityModel); } context.SaveChanges(); return(entityModel.Id); } } catch (Exception ex) { throw ex; } }
public async Task SaveAsync(Role entity) { try { if (entity == null) { return; } using (var timeLineContext = _contextFactory.GetTimeLineContext()) { var entityModel = await timeLineContext .Roles .FirstOrDefaultAsync(item => item.Id.Equals(entity.Id)); if (entityModel == null) { entityModel = new DA.Role(); MapForUpdateentity(entity, entityModel); await timeLineContext.Roles.AddAsync(entityModel); } else { MapForUpdateentity(entity, entityModel); } timeLineContext.SaveChanges(); } } catch (Exception ex) { throw ex; } }
private void MapForUpdateEntity(BL.Role entity, DA.Role daEntity) { daEntity.Id = entity.Id; daEntity.Name = entity.Name; }
private void MapForUpdateentity(Role entity, DA.Role daEntity) { daEntity.Id = entity.Id; }