public Recommendation Update(Recommendation rec) { Recommendation result = null; try { using (var dbCtx = new WeatherAppDbEntities()) { result = dbCtx.Recommendations.SingleOrDefault(info => info.GroupItemId == rec.GroupItemId); if (result != null) { result.Condition = rec.Condition; result.Forecast = rec.Forecast; result.Language = rec.Language; result.MelanomaRiskId = rec.MelanomaRiskId; result.VitaminDId = rec.VitaminDId; dbCtx.SaveChanges(); return result; } else throw new DaoException("No recommendation groupId" + rec.GroupItemId + " found in database"); } } catch (Exception e) { throw new DaoException("Error updating recommendation " + rec.GroupItemId + " in database. " + e.Message, e); } }
public Recommendation Insert(Recommendation rec) { try { using (var dbCtx = new WeatherAppDbEntities()) { dbCtx.Recommendations.Add(rec); dbCtx.SaveChanges(); } return rec; } catch (Exception e) { throw new DaoException("Error inserting recommendation " + rec.Forecast + " in database", e); } }