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 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(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(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(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(); } } }