Exemplo n.º 1
0
        private Plane FromEntity(Entities.Plane entity)
        {
            if (entity == null)
            {
                return(null);
            }

            return(new Plane(entity.Id, entity.Model, entity.FuelConsumptionPer100Km, entity.TakeoffFuelConsumption));
        }
Exemplo n.º 2
0
        private async Task <Guid?> Create(Plane plane)
        {
            Entities.Plane entity = ToEntity(plane);
            entity.Id = Guid.NewGuid();

            _context.Add(entity);
            await _context.SaveChangesAsync();

            return(entity.Id);
        }
Exemplo n.º 3
0
        public async Task Delete(Guid?id)
        {
            Entities.Plane entity = await _context.Planes.FindAsync(id);

            if (entity != null)
            {
                _context.Planes.Remove(entity);
                await _context.SaveChangesAsync();
            }
        }
Exemplo n.º 4
0
        private async Task <Guid?> Update(Plane plane)
        {
            Entities.Plane entity = ToEntity(plane);

            _context.Attach(entity).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                return(plane.Id);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_context.Planes.Any(e => e.Id == plane.Id))
                {
                    return(null);
                }
                else
                {
                    throw;
                }
            }
        }