Exemplo n.º 1
0
        /// <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());
        }
Exemplo n.º 2
0
        /// <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);
            }
        }