protected override GuidKey InnerUpdateOrInsert(DTOProdotto Dato) { using (var ctx = new EntityModel.SqlServerEntities()) { var tab = new tabProdotti(); if (!ctx.tabProdotti.Any(x => x.ID.Equals(Dato.ID))) { Dato.ID = new Guid(); ctx.Entry(tab).State = EntityState.Added; } else { ctx.Entry(tab).State = EntityState.Modified; } tab.Descrizione = Dato.Descrizione; tab.DescrizioneBreve = Dato.DescrizioneBreve; tab.isDeleted = false; tab.ID = Dato.ID; if (Dato.ProdottiDiListino != null) { } ctx.SaveChanges(); return(Dato.Identifier); } }
public DTOProdotto MapTable(tabProdotti product) { if (product == null) { return(null); } return(new DTOProdotto { ID = product.ID, Descrizione = product.Descrizione, DescrizioneBreve = product.DescrizioneBreve //todo: ,Categoria = product.Categoria //todo:,AttributiDisponibili = product.tabGruppoAttributi }); }
protected List <DTOProdotto> GetByContition(Func <tabProdotti, bool> expression) { using (var ctx = new SqlServerEntities()) { if (!ctx.tabProdotti.Any()) { var tab = new tabProdotti(); tab.ID = Guid.NewGuid(); tab.Descrizione = "Generico"; tab.DescrizioneBreve = "Generico"; ctx.Entry(tab).State = EntityState.Added; ctx.SaveChanges(); } //TODO: linq Kit è più efficente return(ctx.tabProdotti.Where(x => !x.isDeleted).Where(expression).Select(MapTable).ToList()); } }