protected void SetOrChangeContext(IMobContext context) { if (context == null) { throw new ArgumentNullException("context", "The context can't be null"); } try { if (context.Database.Connection.State == System.Data.ConnectionState.Broken || context.Database.Connection.State == System.Data.ConnectionState.Closed) { context.Database.Connection.Open(); } } catch (Exception ex) { throw new InvalidOperationException("It's not possible to connect to the server", ex); } entitySet = context.Set <T>(); if (entitySet == null) { throw new ArgumentNullException("Entities", "Set for Entity T not located in the DbContext"); } this.db = context; }
public void SeedData(IMobContext context) { context.Set <Country>().AddOrUpdate (x => x.Id, new Country { Id = 1, Code = "BR", Name = "Brasil", Active = true, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now } ); context.Set <Currency>().AddOrUpdate (x => x.Id, new Currency { Id = 1, Code = "BRL", Name = "Real", Active = true, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now } ); context.Set <CreditCardType>().AddOrUpdate (x => x.Id, new CreditCardType { Id = 1, CreditCardTypeCode = CreditCardTypeCode.Visa, Code = "VISA", Name = "Visa", Active = true, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now }, new CreditCardType { Id = 2, CreditCardTypeCode = CreditCardTypeCode.Amex, Code = "AMEX", Name = "Amex", Active = true, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now }, new CreditCardType { Id = 3, CreditCardTypeCode = CreditCardTypeCode.MasterCard, Code = "MASTERCARD", Name = "Master Card", Active = true, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now }, new CreditCardType { Id = 4, CreditCardTypeCode = CreditCardTypeCode.Elo, Code = "ELO", Name = "Elo", Active = true, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now }, new CreditCardType { Id = 5, CreditCardTypeCode = CreditCardTypeCode.HiperCard, Code = "HIPERCARD", Name = "Hipercard", Active = true, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now }, new CreditCardType { Id = 6, CreditCardTypeCode = CreditCardTypeCode.DinersClub, Code = "DINERS", Name = "Diners", Active = true, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now } ); context.Set <PlanInterval>().AddOrUpdate (x => x.Id, new PlanInterval { Id = 1, Code = "MONTH", Name = "Mensal", Active = true, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now } ); }