public Guardarropa ObtenerGuardarropaPorId(int id) { try { GuardarropaEntity guardarropa = _dbContext.Guardarropas.Find(id); PrendasRepositorio repo = new PrendasRepositorio(); ICollection <Prenda> prendas = repo.GetPrendasGuardarropa(id); Guardarropa model = GuardarropaMapper.MapModel(guardarropa); model.Prendas = prendas; return(model); } catch (Exception e) { throw e; } }
public Sugerencia ObtenerSugerencia(int SugerenciaId) { try { using (var context = new DbContext2()) { SugerenciaEntity entidad = context.Sugerencias.Find(SugerenciaId); ICollection <PrendasSugerenciaEntity> prendas = context.PrendasSugerencia.Where(s => s.SugerenciaId == SugerenciaId).ToList(); Sugerencia sugerencia = SugerenciaMapper.MapModel(entidad); PrendasRepositorio repo = new PrendasRepositorio(); foreach (var x in prendas) { sugerencia.Atuendo.Prendas.Add(repo.GetPrenda(x.PrendaId)); } return(sugerencia); } } catch (Exception e) { throw e; } }
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; } }