Exemplo n.º 1
0
        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();
                }
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
        //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);
            }
        }
Exemplo n.º 10
0
        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();
            }
        }
Exemplo n.º 11
0
        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();
            }
        }
Exemplo n.º 12
0
        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();
            }
        }
Exemplo n.º 13
0
        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();
            }
        }
Exemplo n.º 14
0
        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();
            }
        }
Exemplo n.º 15
0
        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();
            }
        }
Exemplo n.º 16
0
        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();
            }
        }
Exemplo n.º 17
0
        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();
            }
        }
Exemplo n.º 18
0
        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();
                }
            }
        }
Exemplo n.º 19
0
        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();
                }
            }
        }
Exemplo n.º 20
0
        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();
                }
            }
        }