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