private void AddComponents(IPCConfigurationDatabaseService dbService, IPCConfiguration pcConfiguration) { foreach (IPCComponent component in ChosenPCComponents) { pcConfiguration.PCComponents.Add(component); } }
public bool Save() { if (!ApplyChanges()) { return(false); } if (Validate().Count > 0) { return(false); } IPCConfigurationDatabaseService dbService = container.Resolve <IPCConfigurationDatabaseService>(); IPCConfiguration pcConfiguration = container.Resolve <IPCConfiguration>(); AddComponents(dbService, pcConfiguration); pcConfiguration.TotalPrice = TotalPrice; pcConfiguration.ConfigurationType = ConfigurationType; pcConfiguration.Status = Status; container.Resolve <IPCConfigurationDatabaseService>().Add(pcConfiguration); return(true); }
public void Delete(IPCConfiguration configuration) { using (PCConfigurationContext context = new PCConfigurationContext()) { PCConfiguration pCConfigurationToDelete = context.PCConfigurations.FirstOrDefault(c => c.ID == (configuration as PCConfiguration).ID); pCConfigurationToDelete.Status = Core.Common.EntityStatus.Deleted; context.SaveChanges(); } }
public void Add(IPCConfiguration configuration) { using (PCConfigurationContext context = new PCConfigurationContext()) { context.PCConfigurations.Add(configuration as PCConfiguration); foreach (PCComponent component in configuration.PCComponents) { IPCComponent tmpComponent = container.Resolve <IPCComponentDatabaseService>() .GetCurrentPCComponents() .FirstOrDefault(c => c.Code.Equals(component.Code, System.StringComparison.OrdinalIgnoreCase)); if (tmpComponent != null && context.Entry(component).State == EntityState.Added) { context.Entry(component).State = EntityState.Unchanged; } } context.SaveChanges(); } }