Esempio n. 1
0
        public bool Update(TrainingProduct entity)
        {
            bool ret = false;

            ret = Validate(entity);
            if (ret)
            {
                var DbItem = Db.TrainingProduct.Find(entity.Id);

                DbItem.Id               = entity.Id;
                DbItem.ProductName      = entity.ProductName;
                DbItem.IntroductionDate = entity.IntroductionDate;
                DbItem.Url              = entity.Url;
                DbItem.Price            = entity.Price;

                try
                {
                    Db.SaveChanges();
                }
                catch (Exception)
                {
                    return(ret);
                }
            }

            return(ret);
        }
        protected override void Init()
        {
            Products     = new List <TrainingProduct>();
            SearchEntity = new TrainingProduct();
            Entity       = new TrainingProduct();

            base.Init();
        }
Esempio n. 3
0
        public bool Delete(TrainingProduct entity)
        {
            var DbItem = Db.TrainingProduct;

            DbItem.Remove(DbItem.Find(entity.Id));

            Db.SaveChanges();

            return(true);
        }
        protected override void Add()
        {
            IsValid = true;

            Entity = new TrainingProduct();
            Entity.IntroductionDate = DateTime.Now;
            Entity.Url   = "https://";
            Entity.Price = 0;

            base.Add();
        }
        protected override void Delete()
        {
            TrainingProductManager mgr = new TrainingProductManager();

            Entity    = new TrainingProduct();
            Entity.Id = Convert.ToInt32(EventArgument);

            mgr.Delete(Entity);

            Get();

            base.Delete();
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        public bool Insert(TrainingProduct entity)
        {
            bool ret = false;

            ret = Validate(entity);

            if (ret)
            {
                Db.TrainingProduct.Add(entity);
                try
                {
                    Db.SaveChanges();
                }
                catch (Exception)
                {
                    return(ret);
                }
            }

            return(ret);
        }
Esempio n. 8
0
        public List <TrainingProduct> Get(TrainingProduct entity)
        {
            List <TrainingProduct> products = new List <TrainingProduct>();
            var DbItems = Db.TrainingProduct;

            // TODO: Refactor Searching...
            if (!string.IsNullOrEmpty(entity.ProductName))
            {
                var search = DbItems.Where(p => p.ProductName.Contains(entity.ProductName));

                foreach (var product in search)
                {
                    products.Add(new TrainingProduct()
                    {
                        Id               = product.Id,
                        ProductName      = product.ProductName,
                        IntroductionDate = product.IntroductionDate,
                        Url              = product.Url,
                        Price            = product.Price
                    });
                }

                return(products);
            }

            foreach (var product in DbItems)
            {
                products.Add(new TrainingProduct()
                {
                    Id               = product.Id,
                    ProductName      = product.ProductName,
                    IntroductionDate = product.IntroductionDate,
                    Url              = product.Url,
                    Price            = product.Price
                });
            }

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

            base.ResetSearch();
        }