Example #1
0
        public async Task <ProductModel> InsertNewProduct(ProductModel product)
        {
            EntityProduct entityProduct = new EntityProduct
            {
                Name       = product.Name,
                Department = new Mapping.Entities.Department {
                    Id = product.DepartmentId ?? 0
                }
            };

            using (TransactionScope scope = new TransactionScope())
            {
                int id = ServiceLocator.Current.GetInstance <IRepository <EntityProduct> >().Create(entityProduct);
                scope.Complete();
                return(new ProductModel(id, entityProduct.Name, entityProduct.DepartmentId));
            }
        }
Example #2
0
        public async Task <ProductModel> GetProductById(int id)
        {
            EntityProduct entityProduct = ServiceLocator.Current.GetInstance <IRepository <EntityProduct> >().GetById(id);

            return(entityProduct.IsNull() ? null : new ProductModel(entityProduct.Id, entityProduct.Name, entityProduct.DepartmentId));
        }