Exemplo n.º 1
0
        public IHttpActionResult Put(int id,
                                     Product product)
        {
            IHttpActionResult ret = null;
            PTCViewModel      vm  = new PTCViewModel();

            vm.Entity   = product;
            vm.PageMode = PageConstants.EDIT;
            vm.Save();

            if (vm.IsValid)
            {
                ret = Ok(product);
            }
            else if (vm.Messages.Count > 0)
            {
                ret = BadRequest(ConvertToModelState(vm.Messages));
            }
            else
            {
                ret = NotFound();
            }

            return(ret);
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            PTCViewModel vm = new PTCViewModel();

            vm.HandleRequest();
            return(View(vm));
        }
        public IHttpActionResult Put(int id, Product product)
        {
            IHttpActionResult ret = null;
            PTCViewModel      vm  = new PTCViewModel();

            if (product != null)
            {
                vm.Entity   = product;
                vm.PageMode = PDSAPageModeEnum.Edit;
                vm.Save();
                if (vm.IsValid)
                {
                    ret = Ok(vm.Entity);
                }
                else
                {
                    if (vm.Messages.Count > 0)
                    {
                        ret = BadRequest(ConvertToModelState(vm.Messages));
                    }
                    else if (vm.LastException != null)
                    {
                        ret = BadRequest(vm.Message);
                    }
                }
            }
            else
            {
                ret = NotFound();
            }

            return(ret);
        }
Exemplo n.º 4
0
        public IHttpActionResult Post(Product product)
        {
            IHttpActionResult ret = null;
            PTCViewModel      vm  = new PTCViewModel();

            vm.Entity   = product;
            vm.PageMode = PageConstants.ADD;
            vm.Save();

            if (vm.IsValid)
            {
                ret = Created <Product>(
                    Request.RequestUri +
                    product.ProductId.ToString(),
                    product);
            }
            else if (vm.Messages.Count > 0)
            {
                ret = BadRequest(ConvertToModelState(vm.Messages));
            }
            else
            {
                ret = NotFound();
            }

            return(ret);
        }
Exemplo n.º 5
0
        public IHttpActionResult Put(int id, Product product)
        {
            var vm = new PTCViewModel();

            if (product == null)
            {
                return(NotFound());
            }

            vm.Entity   = product;
            vm.PageMode = PDSAPageModeEnum.Edit;
            vm.Save();

            if (!vm.IsValid)
            {
                if (vm.Messages.Count > 0)
                {
                    return(BadRequest(ConvertToModelState(vm.Messages)));
                }
                else if (vm.LastException != null)
                {
                    return(BadRequest(vm.Message));
                }
            }

            return(Ok(vm.Entity));
        }
Exemplo n.º 6
0
        public IHttpActionResult Post(Product product)
        {
            IHttpActionResult ret = null;
            var vm = new PTCViewModel();

            if (product != null)
            {
                vm.Entity   = product;
                vm.PageMode = PDSAPageModeEnum.Add;
                vm.Save();
                if (vm.IsValid)
                {
                    return(Created(Request.RequestUri + vm.Entity.ProductId.ToString(), vm.Entity));
                }
                else
                {
                    if (vm.Messages.Count > 0)
                    {
                        return(BadRequest(ConvertToModelState(vm.Messages)));
                    }
                    else
                    {
                        return(BadRequest(vm.Message));
                    }
                }
            }

            return(NotFound());
        }
Exemplo n.º 7
0
        public IHttpActionResult SearchPriceAndMake(ProductSearch searchEntity)
        {
            IHttpActionResult ret = null;
            PTCViewModel      vm  = new PTCViewModel();

            //Search for Products
            vm.SearchEntity = searchEntity;
            vm.SearchPriceAndMake();

            var priceRange        = vm.ProductsMaxPrice.Intersect(vm.ProductsMinPrice);
            var makeAndPriceRange = priceRange.Intersect(vm.Products);

            vm.Products = makeAndPriceRange.ToList();

            if (vm.Products.Count > 0)
            {
                ret = Ok(vm.Products);
            }
            else
            {
                ret = NotFound();
            }

            return(ret);
        }
Exemplo n.º 8
0
        public IHttpActionResult Delete(int id)
        {
            var vm = new PTCViewModel();

            vm.Delete(id);

            if (vm.LastException != null)
            {
                return(BadRequest(vm.Message));
            }

            return(Ok(vm.Entity));
        }
Exemplo n.º 9
0
        public ActionResult Index(PTCViewModel vm)
        {
            vm.HandleRequest();

            if (vm.IsValid)
            {
                ModelState.Clear();
            }
            else
            {
                ModelState.Merge(vm.Messages);
            }
            return(View(vm));
        }
        public IHttpActionResult Get()
        {
            var vm = new PTCViewModel();

            vm.LoadSearchCategories();
            if (vm.SearchCategories.Count > 0)
            {
                return(Ok(vm.SearchCategories));
            }
            else
            {
                return(NotFound());
            }
        }
Exemplo n.º 11
0
        public IHttpActionResult Search([FromBody] ProductSearch search)
        {
            var vm = new PTCViewModel();

            vm.SearchEntity = search;
            vm.Search();
            if (vm.LastException != null)
            {
                return(BadRequest(vm.Message));
            }
            else
            {
                return(Ok(vm.Products));
            }
        }
Exemplo n.º 12
0
        public ActionResult Product(PTCViewModel vm)
        {
            vm.HandleRequest();

            // If everything is OK, update the model state on the page
            if (vm.IsValid)
            {
                ModelState.Clear();
            }
            else
            {
                ModelState.Merge(vm.Messages);
            }

            return(View(vm));
        }
Exemplo n.º 13
0
        public IHttpActionResult GetSearchCategories()
        {
            IHttpActionResult ret = null;
            PTCViewModel      vm  = new PTCViewModel();

            vm.LoadSearchCategories();
            if (vm.SearchCategories.Count > 0)
            {
                ret = Ok(vm.SearchCategories);
            }
            else
            {
                ret = NotFound();
            }
            return(ret);
        }
        public IHttpActionResult Delete(int id)
        {
            IHttpActionResult ret;
            PTCViewModel      vm = new PTCViewModel();

            vm.Delete(id);
            if (vm.LastException != null)
            {
                ret = BadRequest(vm.Message);
            }
            else
            {
                ret = Ok(vm.Entity);
            }

            return(ret);
        }
Exemplo n.º 15
0
        public IHttpActionResult Get()
        {
            var vm = new PTCViewModel();

            vm.LoadCategories();

            if (vm.Categories.Count > 0)
            {
                return(Ok(vm.Categories));
            }
            else if (vm.LastException != null)
            {
                return(BadRequest(vm.Message));
            }

            return(NotFound());
        }
        // GET api/<controller>
        public IHttpActionResult Get()
        {
            IHttpActionResult ret = null;
            PTCViewModel      vm  = new PTCViewModel();

            vm.Get();
            if (vm.Products.Count > 0)
            {
                ret = Ok(vm.Products);
            }
            else
            {
                ret = NotFound();
            }

            return(ret);
        }
Exemplo n.º 17
0
        public IHttpActionResult Get(int id)
        {
            IHttpActionResult ret;
            Product           prod = new Product();
            PTCViewModel      vm   = new PTCViewModel();

            prod = vm.Get(id);
            if (prod != null)
            {
                ret = Ok(prod);
            }
            else
            {
                ret = NotFound();
            }
            return(ret);
        }
Exemplo n.º 18
0
        public IHttpActionResult Get(int id)
        {
            var vm = new PTCViewModel();

            vm.Get(id);

            if (vm.Entity != null)
            {
                return(Ok(vm.Entity));
            }
            else if (vm.LastException != null)
            {
                return(BadRequest(vm.Message));
            }

            return(NotFound());
        }
Exemplo n.º 19
0
        public IHttpActionResult Search(ProductSearch searchEntity)
        {
            IHttpActionResult ret = null;
            var vm = new PTCViewModel();

            vm.SearchEntity = searchEntity;
            vm.Search();
            if (vm.Products.Count > 0)
            {
                ret = Ok(vm.Products);
            }
            else
            {
                ret = NotFound();
            }

            return(ret);
        }
        public IHttpActionResult Get(int id)
        {
            IHttpActionResult ret = null;
            var vm = new PTCViewModel();

            var product = vm.Get(id);

            if (product != null)
            {
                ret = Ok(product);
            }
            else
            {
                ret = NotFound();
            }

            return(ret);
        }
Exemplo n.º 21
0
        public IHttpActionResult Delete(int id)
        {
            IHttpActionResult ret = null;
            PTCViewModel      vm  = new PTCViewModel();

            vm.Entity = vm.Get(id);
            if (vm.Entity.ProductId > 0)
            {
                vm.Delete(id);

                ret = Ok(true);
            }
            else
            {
                ret = NotFound();
            }
            return(ret);
        }
Exemplo n.º 22
0
        public IHttpActionResult Get()
        {
            IHttpActionResult ret = null;
            var vm = new PTCViewModel();

            //throw new ApplicationException("Error in the Get() method");
            vm.Get();
            if (vm.Products.Count > 0)
            {
                ret = Ok(vm.Products);
            }
            else
            {
                ret = NotFound();
            }

            return(ret);
        }
Exemplo n.º 23
0
        public IHttpActionResult Put(int id, Product product)
        {
            IHttpActionResult ret = null;
            var vm = new PTCViewModel();

            vm.Entity   = product;
            vm.PageMode = PageConstants.EDIT;
            vm.Save();

            if (vm.IsValid)
            {
                ret = Ok(product);
            }
            else
            {
                ret = NotFound();
            }

            return(ret);
        }
Exemplo n.º 24
0
        public IHttpActionResult Post(Product product)
        {
            IHttpActionResult ret = null;
            var vm = new PTCViewModel();

            vm.Entity   = product;
            vm.PageMode = PageConstants.ADD;
            vm.Save();

            if (vm.IsValid)
            {
                ret = Created(Request.RequestUri + product.ProductId.ToString(), product);
            }
            else
            {
                ret = NotFound();
            }

            return(ret);
        }
        // GET api/<controller>
        public IHttpActionResult Get()
        {
            IHttpActionResult ret;
            PTCViewModel      vm = new PTCViewModel();

            vm.Get();
            if (vm.Products.Count() > 0)
            {
                ret = Ok(vm.Products);
            }
            else if (vm.LastException != null)
            {
                ret = BadRequest(vm.Message);
            }
            else
            {
                ret = NotFound();
            }

            return(ret);
        }
        public IHttpActionResult GetSearchCategories()
        {
            IHttpActionResult ret;
            PTCViewModel      vm = new PTCViewModel();

            vm.LoadSearchCategories();
            if (vm.SearchCategories.Count() > 0)
            {
                ret = Ok(vm.SearchCategories);
            }
            else if (vm.LastException != null)
            {
                ret = BadRequest(vm.Message);
            }
            else
            {
                ret = NotFound();
            }

            return(ret);
        }
        public IHttpActionResult Delete(int id)
        {
            IHttpActionResult ret = null;
            PTCViewModel      vm  = new PTCViewModel();

            // Get the product
            vm.Entity = vm.Get(id);
            // Did we find the product?
            if (vm.Entity.ProductId > 0)
            {
                // Delete the product
                vm.Delete(id);

                ret = Ok(true);
            }
            else
            {
                ret = NotFound();
            }

            return(ret);
        }