public IHttpActionResult Get(int id)
 {
     try
     {
         // throw new ArgumentNullException("ja: this is a test");
         ProductModel product;
         ProductRepo  productRepo = new ProductRepo();
         if (id > 0)
         {
             // not an efficient query
             var products = productRepo.Retrieve();
             product = products.FirstOrDefault <ProductModel>(p => p.ProductId == id);
             if (product == null)
             {
                 return(NotFound());
             }
         }
         else
         {
             product = productRepo.Create();
         }
         return(Ok(product));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Ejemplo n.º 2
0
        public ActionResult AddProduct(ProductViewModel model)
        {
            if (ModelState.IsValid)
            {
                var product = MapFromModel(model);
                var repo    = new ProductRepo();
                repo.Create(product);

                LogHelper.log(this);

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Ejemplo n.º 3
0
        private void saveProductsToDb(List <ProductImportModel> products)
        {
            ProductRepo repo = new ProductRepo();

            foreach (ProductImportModel product in products)
            {
                Product p = new Product()
                {
                    Name      = product.Name,
                    Price     = product.Price,
                    Category  = product.Category,
                    Available = product.Available
                };

                LogHelper.log(this, p);

                repo.Create(p);
            }

            ViewBag.Products = products;
        }
Ejemplo n.º 4
0
 public static void createProduct(int productTypeId, String name, int stock, int price)
 {
     ProductRepo.Create(productTypeId, name, stock, price);
 }
Ejemplo n.º 5
0
 public void Add(Product t)
 {
     repo.Create(t);
 }
Ejemplo n.º 6
0
        public Product Create(Product product)
        {
            var repo = new ProductRepo(_context);

            return(repo.Create(product));
        }
        private void Save(string strLink = "")
        {
            try
            {
                var Product = _ProductRepo.GetById(id);
                if (id > 0 && Product != null)
                {
                    Product.CODE       = txtCode.Text;
                    Product.SHAPE_CODE = ddlShape.SelectedValue;
                    if (FileUploadImage.Visible && FileUploadImage.HasFile)
                    {
                        string imgName     = Product.IMAGE;
                        string productPath = Server.MapPath(Cost.PRODUCTPATH) + imgName;
                        if (File.Exists(productPath))
                        {
                            File.Delete(productPath);
                        }

                        imgName     = Product.ID + Path.GetExtension(FileUploadImage.FileName);
                        productPath = Server.MapPath(Cost.PRODUCTPATH) + imgName;
                        FileUploadImage.SaveAs(productPath);

                        Product.IMAGE = imgName;
                    }
                    _ProductRepo.Update(Product);

                    strLink = string.IsNullOrEmpty(strLink) ? "chi-tiet-san-pham.aspx?id=" + id : strLink;
                }
                else
                {
                    Product            = new PRODUCT();
                    Product.CODE       = txtCode.Text;
                    Product.SHAPE_CODE = ddlShape.SelectedValue;
                    //Product.CREATOR_ID = Utils.CIntDef(Session["Userid"]);
                    //Product.CREATED_DATE = DateTime.Now;
                    _ProductRepo.Create(Product);

                    Product = _ProductRepo.GetById(Product.ID);
                    if (Product.ID > 0 && Product != null)
                    {
                        if (FileUploadImage.Visible && FileUploadImage.HasFile)
                        {
                            string imgName = Product.ID + Path.GetExtension(FileUploadImage.FileName);
                            FileUploadImage.SaveAs(Server.MapPath(Cost.PRODUCTPATH) + imgName);

                            Product.IMAGE = imgName;

                            _ProductRepo.Update(Product);
                        }
                    }
                    strLink = string.IsNullOrEmpty(strLink) ? "chi-tiet-san-pham.aspx?id=" + Product.ID : strLink;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (!string.IsNullOrEmpty(strLink))
                {
                    Response.Redirect(strLink);
                }
            }
        }