public Usuario CrearUsuario(Usuario Usuario) { UsuarioEntity entidad = UsuarioMapper.MapEntity(Usuario); SensibilidadLocalEntity sensibilidadEntidad = SensibilidadLocalMapper.MapEntity(Usuario.Sensibilidad); sensibilidadEntidad.UsuarioId = Usuario.UsuarioId; _dbContext.Usuarios.Add(entidad); _dbContext.SensibilidadLocal.Add(sensibilidadEntidad); _dbContext.SaveChanges(); return(Usuario); }
//public PrendasRepositorio(QueMePongoDbContext dbContext) //{ // this.dbContext = dbContext; //} public void AddPrenda(Prenda prenda) { try { var entidad = PrendaMapper.MapEntity(prenda); dbContext.Prendas.Add(entidad); dbContext.SaveChanges(); }catch (Exception e) { throw e; } }
public void TestEnsureDeletedThenCreateDatabase2Ok() { //SETUP var showLog = false; #pragma warning disable 618 var options = this.CreateUniqueClassOptionsWithLogging <DbContext2>(log => #pragma warning restore 618 { if (showLog) { _output.WriteLine(log.Message); } }); using (var context = new DbContext2(options)) { context.Database.EnsureDeleted(); //ATTEMPT showLog = true; context.Database.EnsureClean(); showLog = false; //VERIFY context.Add(new TopClass2()); context.SaveChanges(); } }
public void TestDatabase1SchemaChangeToDatabase2Ok() { //SETUP var connectionString = this.GetUniqueDatabaseConnectionString(); var builder1 = new DbContextOptionsBuilder <DbContext1>(); using (var context = new DbContext1(builder1.UseSqlServer(connectionString).Options)) using (new TimeThings(_output, "EnsureDeleted/EnsureCreated")) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); } var builder2 = new DbContextOptionsBuilder <DbContext2>(); using (var context = new DbContext2(builder2.UseSqlServer(connectionString).Options)) { //ATTEMPT using (new TimeThings(_output, "EnsureClean")) { context.Database.EnsureClean(); } //VERIFY context.Add(new TopClass2()); context.SaveChanges(); } }
public void TestWipeDataDatabase2Ok() { //SETUP var options = this.CreateUniqueMethodOptions <DbContext2>(); using (var context = new DbContext2(options)) { context.Database.EnsureCreated(); context.Add(new TopClass2 { Dependents = new List <Dependent2> { new Dependent2() } }); context.SaveChanges(); context.TopClasses.Count().ShouldEqual(1); context.Dependents.Count().ShouldEqual(1); //ATTEMPT context.Database.EnsureClean(); //VERIFY context.TopClasses.Count().ShouldEqual(0); context.Dependents.Count().ShouldEqual(0); } }
public Evento CrearEvento(Evento evento) { try { EventoEntity entidad = EventoMapper.MapEntity(evento); _dbContext.Eventos.Add(entidad); _dbContext.SaveChanges(); return(evento); } catch (Exception e) { throw e; } }
public static void Delete(int id) { using (var db = new DbContext2()) { db.Items.Remove(db.Items.Find(id)); db.SaveChanges(); } }
public static void CreateCat(string name, int?parentId) { using (var db = new DbContext2()) { db.Categories.Add(new Categories() { Name = name, ParentId = parentId, }); db.SaveChanges(); } }
public static void Create(string name, string email, string password) { using (var db = new DbContext2()) { db.Users.Add(new Users() { Email = email, Name = name, Password = password, }); db.SaveChanges(); } }
public Guardarropa CrearGuardarropa(Guardarropa guardarropa) { try { GuardarropaEntity entidad = GuardarropaMapper.MapEntity(guardarropa); _dbContext.Guardarropas.Add(entidad); _dbContext.SaveChanges(); PrendasRepositorio repo = new PrendasRepositorio(); foreach (var x in guardarropa.Prendas) { repo.AddPrenda(x); } foreach (var x in guardarropa.Usuarios) { AgregarGuardarropa(x, guardarropa.GuardarropaId); } return(guardarropa); } catch (Exception e) { throw e; } }
public static void Create(string name, string description, string image, int categoryId, decimal price) { using (var db = new DbContext2()) { db.Items.Add(new Items() { Name = name, Description = description, CategoryId = categoryId, Image = image, Price = price, }); db.SaveChanges(); } }
public void CrearSugerencia(Sugerencia sugerencia) { try { using (var context = new DbContext2()) { SugerenciaEntity entidad = SugerenciaMapper.MapEntity(sugerencia); context.Sugerencias.Add(entidad); foreach (var x in sugerencia.Atuendo.Prendas) { context.PrendasSugerencia.Add(new PrendasSugerenciaEntity() { SugerenciaId = sugerencia.SugerenciaId, PrendaId = x.PrendaId }); } context.SaveChanges(); } } catch (Exception e) { throw e; } }