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