Exemplo n.º 1
0
        public bool UpdateCategory(Category instance)
        {
            try
            {
                Category category = Db.Categories.Find(instance.CategoryId);
                Type type = instance.GetType();

                foreach(var info in type.GetProperties())
                {
                    if(info.CanWrite)
                    {
                        var value = info.GetValue(instance);
                        if(value != null)
                        {
                            info.SetValue(category, value, null);
                        }
                    }
                }
                Db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }