public static void RegisterVouchẻMethodPlugin(Assembly executingAssembly)
        {
            var allTypes = executingAssembly.GetTypes();
            var list     = allTypes.Where(t => typeof(IVoucherCodeMethod).IsAssignableFrom(t) &&
                                          t.IsClass && !t.IsAbstract).ToList();

            foreach (var pmType in list)
            {
                var tempPm = Activator.CreateInstance(pmType) as IVoucherCodeMethod;
                if (tempPm == null)
                {
                    continue;
                }

                using (var db = new CoreEcommerce.Ef.CoreEcommerceDbContext())
                {
                    var existed = db.VoucherMethods.SingleOrDefault(i => i.Id == tempPm.Id);
                    if (existed != null)
                    {
                        continue;
                    }

                    var type = tempPm.GetType();
                    db.VoucherMethods.Add(new VoucherMethod()
                    {
                        AssemblyType = type.FullName,
                        Id           = tempPm.Id,
                        Name         = type.Name
                    });
                    db.SaveChanges();
                }
            }
        }
Exemple #2
0
 public void Handle(ProductCreated e)
 {
     using (var db = new CoreEcommerce.Ef.CoreEcommerceDbContext())
     {
         db.Products.Add(new Product()
         {
             Id           = e.Id,
             ParentId     = e.ParentId,
             CreatedDate  = e.CreatedDate,
             Price        = e.Price,
             Quantity     = e.Quantity,
             ProductCode  = e.ProductCode,
             AllowComment = e.AllowComment,
             Gram         = e.Gram,
             Calorie      = e.Calorie
         });
         db.SaveChanges();
     }
 }