Пример #1
0
        public CreateProductModel Execute(CreateProductCommandModel Product)
        {
            using (_Entities = new TestMultiplicaEntities())
            {
                var product = Mapper.Map <Data.Product>(Product);
                _Entities.Product.Add(product);
                _Entities.SaveChanges();

                var productResult = Mapper.Map <CreateProductModel>(product);

                return(productResult);
            }
        }
        public DeleteProductModel Execute(int ID)
        {
            using (_Entities = new TestMultiplicaEntities())
            {
                var product = _Entities.Product.Find(ID);
                _Entities.Product.Remove(product);
                _Entities.Entry(product).State = EntityState.Deleted;
                _Entities.SaveChanges();

                var productResult = Mapper.Map <DeleteProductModel>(product);

                return(productResult);
            }
        }
Пример #3
0
        public UpdateProductModel Execute(int ID, UpdateProductCommandModel Model)
        {
            using (_Entities = new TestMultiplicaEntities())
            {
                var product = _Entities.Product.Find(ID);
                Mapper.Map <UpdateProductCommandModel, Data.Product>(Model, product);
                _Entities.Product.Attach(product);
                _Entities.Entry(product).State = EntityState.Modified;
                _Entities.SaveChanges();

                var productResult = Mapper.Map <UpdateProductModel>(product);

                return(productResult);
            }
        }