public static ArticleDTO SaveArticle(ArticleDTO a) { GSMEF.Article EA = Article.ConvertFromDTO(a); using (var ctx = new GSMDBEntities()) { if (EA.Id > 0) { ctx.Entry(EA).State = System.Data.Entity.EntityState.Modified; foreach (var child in EA.Ventes) { ctx.Entry(child).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); } } else { EA = Article.ConvertFromDTO(a); ctx.Articles.Add(EA); a.Id = EA.Id; //because of DTOs we need to firm upthe FKs foreach (var child in a.VentesDto) { child.ArticleId = a.Id; } } } return a; }
public static ArticleDTO GetArticle(int id, bool deepLoad) { ArticleDTO a = new ArticleDTO(); using (GSMDBEntities ctx = new GSMDBEntities()) { var result = ctx.Articles.Where(x => x.Id.Equals(id)).SingleOrDefault(); a = Article.ConvertToDTO(result, deepLoad); } return a; }
private void GetArticle(int id) { try { ArticleParentObject = Article.GetArticle(id, false); ArticleParentObject.VentesDto.Add(CurrentVente); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void bSave_Click(object sender, EventArgs e) { try { ArticleParentObject = Article.SaveArticle(ArticleParentObject); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static GSMEF.Article ConvertFromDTO(ArticleDTO data) { GSMEF.Article A = new GSMEF.Article() { Id = data.Id, Désignation = data.Désignation, Type = data.Type, Observations = data.Observations }; foreach(VenteDTO a in data.VentesDto) { A.Ventes.Add(Vente.ConvertFromDTO(a)); } return A; }
public static ArticleDTO ConvertToDTO(GSMEF.Article data,bool deepLoad) { ArticleDTO A = new ArticleDTO() { Id = data.Id, Désignation = data.Désignation, Observations = data.Observations, Type = data.Type, }; if (deepLoad) { foreach (GSMEF.Vente v in data.Ventes) { A.VentesDto.Add(Vente.ConvertToDTO(v)); } } return A; }