public async Task<Appliance> UpdateApplianceAsync(Appliance appliance) { Appliance applianceToUpdate = (await GetAppliancesAsync(new List<int> { appliance.Id })).SingleOrDefault(); if (applianceToUpdate == null) return null; if (appliance.Model != null) { ApplianceModel usedModel = (await GetApplianceModelsAsync(new[] { appliance.Model.Id })).SingleOrDefault(); if (usedModel == null) return null; applianceToUpdate.Model = usedModel; } if (appliance.CurrentSetting != null) applianceToUpdate.CurrentSetting = appliance.CurrentSetting; if (appliance.Name != null) applianceToUpdate.Name = appliance.Name; if (appliance.Zone != null) applianceToUpdate.Zone = appliance.Zone; await SaveAsync(); return applianceToUpdate; }
public async Task<Appliance> CreateApplianceAsync(Appliance appliance) { ApplianceModel usedModel = (await GetApplianceModelsAsync(new[] {appliance.Model.Id})).SingleOrDefault(); if (usedModel == null) return null; appliance.Model = usedModel; Appliance applianceToCreate = Context.Appliances.Add(appliance); await SaveAsync(); return applianceToCreate; }