public void Create(ProductDTO entity) { Product product = new Product(); product = Mapper.Map <ProductDTO, Product>(entity); using (var db = new ClothesDbContext()) { if (product != null) { var foundcategory = db.Categories.Where(c => c.Name == entity.CategoryName).FirstOrDefault(); var foundcolor = db.Colors.Where(col => col.Name == entity.ClothesColorName).FirstOrDefault(); var foundsupplier = db.Suppliers.Where(sup => sup.Name == entity.ClothesColorName).FirstOrDefault(); //var foundcategory = db.Categories.Find(entity.CategoryName); //var foundcolor = db.Colors.Find(entity.ClothesColorName); //var foundsupplier = db.Suppliers.Find(entity.SupplierName); product.Category = foundcategory; product.Color = foundcolor; product.Supplier = foundsupplier; db.Products.Add(product); db.SaveChanges(); } } }
public ProductDTO Read(int id) { ProductDTO product = new ProductDTO(); using (var db = new ClothesDbContext()) { product = Mapper.Map <Product, ProductDTO>(db.Products.Where(pr => pr.Id == id).FirstOrDefault()); return(product); } }
public CategoryDTO Read(int id) { CategoryDTO category = new CategoryDTO(); using (var db = new ClothesDbContext()) { category = Mapper.Map <Category, CategoryDTO>(db.Categories.Where(pr => pr.Id == id).FirstOrDefault()); return(category); } }
public ICollection <CategoryDTO> ReadAll() { ICollection <CategoryDTO> categories = new ObservableCollection <CategoryDTO>(); using (var db = new ClothesDbContext()) { categories = Mapper.Map <ICollection <Category>, ICollection <CategoryDTO> >(db.Categories.ToList()); return(categories); } }
public ClothesColorDTO Read(int id) { ClothesColorDTO color = new ClothesColorDTO(); using (var db = new ClothesDbContext()) { color = Mapper.Map <ClothesColor, ClothesColorDTO>(db.Colors.Where(pr => pr.Id == id).FirstOrDefault()); return(color); } }
public ICollection <SupplierDTO> ReadAll() { ICollection <SupplierDTO> suppliers = new ObservableCollection <SupplierDTO>(); using (var db = new ClothesDbContext()) { suppliers = Mapper.Map <ICollection <Supplier>, ICollection <SupplierDTO> >(db.Suppliers.ToList()); return(suppliers); } }
public ICollection <ClothesColorDTO> ReadAll() { ICollection <ClothesColorDTO> colors = new ObservableCollection <ClothesColorDTO>(); using (var db = new ClothesDbContext()) { colors = Mapper.Map <ICollection <ClothesColor>, ICollection <ClothesColorDTO> >(db.Colors.ToList()); return(colors); } }
//public void Create(Product entity, ClothesColor color, Supplier supplier, Category category) //{ // using (var db = new ClothesDbContext()) // { // if (entity != null) // { // var foundCategory = db.Categories.Find(category); // var foundColor = db.Colors.Find(color); // var foundSupplier = db.Suppliers.Find(supplier); // entity.Category = foundCategory; // entity.Color = foundColor; // entity.Supplier = foundSupplier; // db.Products.Add(entity); // db.SaveChanges(); // } // } //} public ICollection <ProductDTO> ReadAll() { ICollection <ProductDTO> products = new ObservableCollection <ProductDTO>(); using (var db = new ClothesDbContext()) { //products = Mapper.Map<ICollection<Product>, ICollection<ProductDTO>>(db.Products.ToList()); return(products); } }
public SupplierDTO Read(int id) { SupplierDTO supplier = new SupplierDTO(); using (var db = new ClothesDbContext()) { supplier = Mapper.Map <Supplier, SupplierDTO>(db.Suppliers.Where(pr => pr.Id == id).FirstOrDefault()); return(supplier); } }
public void Update(ProductDTO entity) { var product = Mapper.Map <ProductDTO, Product> (entity); using (var db = new ClothesDbContext()) { //Todo: Add custom logic to check if another object like this exist in the data base. var newProduct = db.Products.Where(pr => pr.Id == product.Id).FirstOrDefault(); newProduct.Quantity = product.Quantity; db.SaveChanges(); } }
public void Delete(ClothesColorDTO entity) { ClothesColor color = new ClothesColor(); color = Mapper.Map <ClothesColorDTO, ClothesColor>(entity); using (var db = new ClothesDbContext()) { var deletedColor = db.Colors.Where(x => x.Name == color.Name).FirstOrDefault(); db.Colors.Remove(deletedColor); db.SaveChanges(); } }
public void Delete(CategoryDTO entity) { Category category = new Category(); category = Mapper.Map <CategoryDTO, Category>(entity); using (var db = new ClothesDbContext()) { var deleteCategory = db.Categories.Where(x => x.Name == category.Name).FirstOrDefault(); db.Categories.Remove(deleteCategory); db.SaveChanges(); } }
public void Delete(ProductDTO entity) { Product product = new Product(); product = Mapper.Map <ProductDTO, Product>(entity); using (var db = new ClothesDbContext()) { var deleteProduct = db.Products.Where(pr => pr.Name == product.Name).FirstOrDefault(); db.Products.Remove(deleteProduct); db.SaveChanges(); } }
public void Delete(SupplierDTO entity) { Supplier supplier = new Supplier(); supplier = Mapper.Map <SupplierDTO, Supplier>(entity); using (var db = new ClothesDbContext()) { var deletedSupplier = db.Suppliers.Where(x => x.Name == supplier.Name).FirstOrDefault(); db.Suppliers.Remove(deletedSupplier); db.SaveChanges(); } }
public void Update(CategoryDTO entity) { Category category = new Category(); category = Mapper.Map <CategoryDTO, Category>(entity); using (var db = new ClothesDbContext()) { //Todo: Add custom logic to check if another object like this exist in the data base. var newCategory = db.Categories.Where(c => c.Id == category.Id).FirstOrDefault(); newCategory = category; db.SaveChanges(); } }
public void Update(ClothesColorDTO entity) { ClothesColor color = new ClothesColor(); color = Mapper.Map <ClothesColorDTO, ClothesColor>(entity); using (var db = new ClothesDbContext()) { //Todo: Add custom logic to check if another object like this exist in the data base. var newColors = db.Colors.Where(col => col.Id == color.Id).FirstOrDefault(); newColors = color; db.SaveChanges(); } }
public void Update(SupplierDTO entity) { Supplier supplier = new Supplier(); supplier = Mapper.Map <SupplierDTO, Supplier>(entity); using (var db = new ClothesDbContext()) { //Todo: Add custom logic to check if another object like this exist in the data base. var newSupplier = db.Suppliers.Where(sup => sup.Id == supplier.Id).FirstOrDefault(); newSupplier = supplier; db.SaveChanges(); } }
public void Create(CategoryDTO entity) { Category category = new Category(); category = Mapper.Map <CategoryDTO, Category>(entity); using (var db = new ClothesDbContext()) { if (category != null) { db.Categories.Add(category); db.SaveChanges(); } } }
public void Create(SupplierDTO entity) { Supplier supplier = new Supplier(); supplier = Mapper.Map <SupplierDTO, Supplier>(entity); using (var db = new ClothesDbContext()) { if (supplier != null) { db.Suppliers.Add(supplier); db.SaveChanges(); } } }
public void Create(ClothesColorDTO entity) { ClothesColor color = new ClothesColor(); color = Mapper.Map <ClothesColorDTO, ClothesColor>(entity); using (var db = new ClothesDbContext()) { if (entity != null) { db.Colors.Add(color); db.SaveChanges(); } } }