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); }
public async Task <Guid?> CreateOrUpdate(Plane plane) { if (plane.Id == null || plane.Id == Guid.Empty) { return(await Create(plane)); } else { return(await Update(plane)); } }
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 }); }
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; } } }