/// <summary> /// Adds entity of the <see cref="DalAccount"/> class to context /// </summary> /// <param name="entity"> Entity for saving </param> /// <exception cref="ArgumentNullException"> /// <paramref name="entity"/> is null. /// </exception> public void Create(DalAccount entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } context.Set <Account>().Add(entity.ToAccount()); }
/// <summary> /// Updates account by values from entity of the <see cref="DalAccount"/> class /// </summary> /// <param name="entity"> Entity of the <see cref="DalAccount"/> class </param> /// <exception cref="ArgumentNullException"> /// <paramref name="entity"/> is null. /// </exception> public bool Update(DalAccount entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } Account entityToUpdate = context.Set <Account>().First(e => e.Id == entity.Id); if (entityToUpdate == null) { return(false); } try { context.Entry(entityToUpdate).CurrentValues.SetValues(entity.ToAccount()); return(true); } catch (Exception) { return(false); } }