protected void BuildCollection() { MvvmDbContext db = null; try { db = new MvvmDbContext(); // Get the collection DataCollection = db.Products.ToList(); // Filter the collection if (DataCollection != null && DataCollection.Count > 0) { if (!string.IsNullOrEmpty(SearchEntity.ProductName)) { DataCollection = DataCollection.FindAll( p => p.ProductName .StartsWith(SearchEntity.ProductName, StringComparison.InvariantCultureIgnoreCase)); } } if (DataCollection.Count == 0) { Message = "No Product Data Found."; } } catch (Exception ex) { Publish(ex, "Error while loading products."); } }
protected virtual void GetEntity() { MvvmDbContext db = null; try { db = new MvvmDbContext(); // Get the entity if (!string.IsNullOrEmpty(EventArgument)) { Entity = db.Products.Find(Convert.ToInt32(EventArgument)); } } catch (Exception ex) { Publish(ex, "Error Retrieving Product With ID=" + EventArgument); } }
public virtual void Delete() { MvvmDbContext db = null; try { db = new MvvmDbContext(); if (!string.IsNullOrEmpty(EventArgument)) { Entity = db.Products.Find(Convert.ToInt32(EventArgument)); db.Products.Remove(Entity); db.SaveChanges(); PageMode = PDSAPageModeEnum.List; } } catch (Exception ex) { Publish(ex, "Error Deleting Product With ID=" + Entity.ProductName); } }
protected void Update() { MvvmDbContext db = null; try { db = new MvvmDbContext(); // Do editing here db.Entry(Entity).State = EntityState.Modified; db.SaveChanges(); PageMode = PDSAPageModeEnum.List; } catch (DbEntityValidationException ex) { IsValid = false; ValidationErrorsToMessages(ex); } catch (Exception ex) { Publish(ex, "Error Updating Product With ID=" + Entity.ProductId.ToString()); } }
protected void Insert() { MvvmDbContext db = null; try { db = new MvvmDbContext(); // Do editing here db.Products.Add(Entity); db.SaveChanges(); PageMode = PDSAPageModeEnum.List; } catch (DbEntityValidationException ex) { IsValid = false; ValidationErrorsToMessages(ex); } catch (Exception ex) { Publish(ex, "Error Inserting New Product: '" + Entity.ProductName + "'"); } }