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;
            }
        }
Exemplo n.º 2
0
 public bool CreateCategory(Category instance)
 {
     try
     {
         if (instance.CategoryId == 0)
         {
             Db.Categories.Add(instance);
             Db.SaveChanges();
             return true;
         }
         return false;
     }
     catch
     {
         return false;
     }
 }