Esempio n. 1
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);
        }
Esempio n. 2
0
 public async Task <Guid?> CreateOrUpdate(Plane plane)
 {
     if (plane.Id == null || plane.Id == Guid.Empty)
     {
         return(await Create(plane));
     }
     else
     {
         return(await Update(plane));
     }
 }
Esempio n. 3
0
        private Entities.Plane ToEntity(Plane plane)
        {
            if (plane == null)
            {
                return(null);
            }

            return(new Entities.Plane()
            {
                Id = plane.Id,
                Model = plane.Model,
                FuelConsumptionPer100Km = plane.FuelConsumptionPer100Km,
                TakeoffFuelConsumption = plane.TakeoffFuelConsumption
            });
        }
Esempio 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;
                }
            }
        }