public ActionResult Delete(ViewModelProduct product)
        {
            ResponseMessage response = _productService.Delete(product.Id);

            if (response.IsError == true)
            {
                foreach (var item in response.ErrorCodes)
                {
                    ModelState.AddModelError(item, item);
                }

                return View();
            }
            return RedirectToAction("Index");
        }
        public ActionResult Create(ViewModelProduct product)
        {
            var entity = Mapper.Map<ViewModelProduct, Product>(product);
            ResponseMessage response = _productService.Add(entity);

            if (response.IsError == true)
            {
                foreach (var item in response.ErrorCodes)
                {
                    ModelState.AddModelError(item, item);
                }
                PrepareSelectList();
                return View(product);
            }
            return RedirectToAction("Index");
        }
        private static void GenerateQueryString(StringBuilder query, ViewModelProduct product)
        {
            if (!string.IsNullOrEmpty(product.Name))
            {
                AppendCriteria(query);

                query.Append("it.Name like '%" + product.Name + "%'");
            }

            if (!string.IsNullOrEmpty(product.Number))
            {
                AppendCriteria(query);

                query.Append("it.Number like '%" + product.Number + "%'");
            }

            if (product.Size_SizeId != null)
            {
                AppendCriteria(query);
                query.Append("it.Size_SizeId = " + product.Size_SizeId.Value.ToString());
            }

            if (product.Model_ModelId != null)
            {
                AppendCriteria(query);
                query.Append("it.Model_ModelId = " + product.Model_ModelId.Value.ToString());
            }

            if (product.Type_TypeId != null)
            {
                AppendCriteria(query);
                query.Append("it.Type_TypeId = " + product.Type_TypeId.Value.ToString());
            }

            if (product.Origin_OriginId != null)
            {
                AppendCriteria(query);
                query.Append("it.Origin_OriginId = " + product.Origin_OriginId.Value.ToString());
            }
        }
        public ActionResult Search(ViewModelProduct product, int? skip)
        {
            StringBuilder query = new StringBuilder();

            GenerateQueryString(query, product);
            var products = Mapper.Map<List<Product>, List<ViewModelProduct>>(_productService.Search(query.ToString(),skip.HasValue ? skip.Value : 0));
            return Json(products);
        }