예제 #1
0
        /// <summary>
        /// Updates the entity, based on its unique identifier.
        /// </summary>
        /// <param name="entity">Entity to be updated.</param>
        /// <exception cref="AirplaneException">Throws when something goes worng. The InnerException can be used to have more details.</exception>
        /// <returns></returns>
        public async Task <Airplane> UpdateAsync(Airplane entity)
        {
            try
            {
                var airplane = default(Airplane);
                using (_context = new GolContext(_configuration))
                {
                    var entry        = _context.Airplanes.Update(entity);
                    var rowsAffected = await _context.SaveChangesAsync();

                    if (rowsAffected > 0)
                    {
                        airplane = entry.Entity;
                    }
                }

                if (airplane == null)
                {
                    throw new AirplaneException("O avião não foi atualizado na base de dados.");
                }

                return(airplane);
            }
            catch (Exception e)
            {
                throw new AirplaneException("Não foi possível atualizar o avião informado.", e);
            }
        }
예제 #2
0
 /// <summary>
 /// Removes the specified entity from database.
 /// </summary>
 /// <param name="entity">Entity to be deleted.</param>
 /// <exception cref="AirplaneException">Throws when something goes worng. The InnerException can be used to have more details.</exception>
 /// <returns></returns>
 public async Task DeleteAsync(Airplane entity)
 {
     try
     {
         using (_context = new GolContext(_configuration))
         {
             _context.Airplanes.Remove(entity);
             var rowsAffected = await _context.SaveChangesAsync();
         }
     }
     catch (Exception e)
     {
         throw new AirplaneException("Não foi possível remover o avião informado.", e);
     }
 }
예제 #3
0
 public async Task <int> SaveChanges()
 {
     return(await Db.SaveChangesAsync());
 }