protected override void Init()
 {
     base.Init();
     Products     = new List <TrainingProduct>();
     SearchEntity = new TrainingProduct();
     Entity       = new TrainingProduct();
     mg           = new TrainingProductManager();
 }
        public bool Update(TrainingProduct entity)
        {
            bool ret = Validate(entity);

            if (ret)
            {
                db.Entry(entity).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(ret);
        }
        public List <TrainingProduct> Get(TrainingProduct entity)
        {
            List <TrainingProduct> ret = db.Products.ToList();

            if (!string.IsNullOrEmpty(entity.ProductName))
            {
                ret = ret.FindAll(p => p.ProductName.ToLower().StartsWith(entity.ProductName, StringComparison.CurrentCultureIgnoreCase));
            }

            return(ret);
        }
 protected override void Add()
 {
     IsValid = true;
     Entity  = new TrainingProduct()
     {
         IntroductionDate = DateTime.Now,
         Url   = "http://",
         Price = 0
     };
     base.Add();
 }
        public bool Insert(TrainingProduct entity)
        {
            bool ret = Validate(entity);

            if (ret)
            {
                db.Products.Add(entity);
                db.SaveChanges();
                //insert database
            }
            return(ret);
        }
        public bool Validate(TrainingProduct entity)
        {
            ValidationErrors.Clear();
            if (!string.IsNullOrEmpty(entity.ProductName))
            {
                if (entity.ProductName.ToLower() == entity.ProductName)
                {
                    ValidationErrors.Add(new KeyValuePair <string, string>("ProductName", "Product Name must not be all lower case"));
                }
            }

            return(ValidationErrors.Count == 0);
        }
 public bool Delete(TrainingProduct entity)
 {
     db.Products.Remove(entity);
     db.SaveChanges();
     return(true);
 }
        public TrainingProduct Get(int productId)
        {
            TrainingProduct ret = db.Products.Find(productId);

            return(ret);
        }
 protected override void ResetSearch()
 {
     SearchEntity = new TrainingProduct();
 }