public IHttpActionResult Post(Product product)
        {
            if (product.SubCategoryID != null)
            {
                product.MainCategoryId = SubCategory.Get((int)product.SubCategoryID).MainCategoryId;
            }
            if (product.FinalSubCategoryID != null)
            {
                product.SubCategoryID  = FinalSub.Get((int)product.FinalSubCategoryID).SubCategoryId;
                product.MainCategoryId = SubCategory.Get((int)product.SubCategoryID).MainCategoryId;
            }


            product.AddedDate = DateTime.Now;
            product.ImageFile = "0";
            productRepository.Insert(product);

            ProductHistory Phistory = new ProductHistory();

            Phistory.AddedDate          = product.AddedDate;
            Phistory.OnHand             = product.OnHand;
            Phistory.Product_name       = product.Product_name;
            Phistory.UnitPrice          = product.UnitPrice;
            Phistory.Description        = product.Description;
            Phistory.ImageFile          = product.ImageFile;
            Phistory.Cost               = product.Cost;
            Phistory.MainCategoryId     = product.MainCategoryId;
            Phistory.SubCategoryID      = product.SubCategoryID;
            Phistory.FinalSubCategoryID = product.FinalSubCategoryID;
            Phistory.SizeCategory       = product.SizeCategory;
            producthistory.Insert(Phistory);

            pid  = product.ProductId;
            phid = Phistory.ProductHistoryId;

            return(Ok(product));
        }
 public ActionResult getProducts(int id, int category)
 {
     Session["admin"]         = null;
     Session["adminLoginID"]  = null;
     Session["adminUserName"] = null;
     Session["paymentmethod"] = null;
     if (category == 1)
     {
         mainCategoryRepository.Get(id);
         return(View(mainCategoryRepository));
     }
     else if (category == 2)
     {
         subCategoryRepository.Get(id);
         return(View(subCategoryRepository));
     }
     else
     {
         finalSubCategoryRepository.Get(id);
         return(View(finalSubCategoryRepository));
     }
 }
示例#3
0
        public ActionResult AddProduct(Product product, HttpPostedFileBase[] files)
        {
            if (Session["admin"] == null)
            {
                return(RedirectToAction("index", "Home"));
            }
            if (ModelState.IsValid)
            {
                if (product.SubCategoryID != null)
                {
                    product.CategoryID = SubCategory.Get((int)product.SubCategoryID).MCategory_id;
                }
                if (product.FinalSubCategoryID != null)
                {
                    product.SubCategoryID = FinalSub.Get((int)product.FinalSubCategoryID).SubCate_id;
                    product.CategoryID    = SubCategory.Get((int)product.SubCategoryID).MCategory_id;
                }
                if (productRepository.GetByProductName(product.Product_name, (int)product.CategoryID))
                {
                    ViewData["errorm"] = "product name already exist!";
                    return(Json(new
                    {
                        newUrl = Url.Action("AddProduct")
                    }
                                ));
                }
                String filename = "";
                //iterating through multiple file collection
                foreach (HttpPostedFileBase file in files)
                {
                    if (file != null && file.ContentLength > 0)
                    {
                        try
                        {
                            string path = System.IO.Path.Combine(Server.MapPath("~/content/image"), System.IO.Path.GetFileName(file.FileName));
                            file.SaveAs(path);
                            filename += System.IO.Path.GetFileName(file.FileName) + '|';
                        }
                        catch (Exception exp)
                        {
                            ViewBag.Message = "ERROR:" + exp.Message.ToString();
                            return(Json(new
                            {
                                newUrl = Url.Action("AddProduct")
                            }
                                        ));
                        }
                    }
                }
                product.AddedDate = DateTime.Now;
                product.ImageFile = filename.Remove(filename.Length - 1, 1);
                productRepository.Insert(product);

                ProductHistory Phistory = new ProductHistory();
                Phistory.AddedDate          = product.AddedDate;
                Phistory.OnHand             = product.OnHand;
                Phistory.Product_name       = product.Product_name;
                Phistory.UnitPrice          = product.UnitPrice;
                Phistory.Description        = product.Description;
                Phistory.ImageFile          = product.ImageFile;
                Phistory.Cost               = product.Cost;
                Phistory.CategoryID         = product.CategoryID;
                Phistory.SubCategoryID      = product.SubCategoryID;
                Phistory.FinalSubCategoryID = product.FinalSubCategoryID;
                Phistory.SizeCategory       = product.SizeCategory;
                producthistory.Insert(Phistory);
                if (product.SizeCategory == "other")
                {
                    return(Json(new
                    {
                        newUrl = Url.Action("Index")
                    }
                                ));
                }
                else
                {
                    return(Json(new
                    {
                        newUrl = Url.Action("AddSize", new { id = product.Product_id }) //Payment as Action; Process as Controller
                    }
                                ));
                }
            }
            ViewData["MainCatagories"] = mainCategoryRepository.GetAll().ToList();
            Session["ProductError"]    = ModelState
                                         .Where(x => x.Value.Errors.Count > 0)
                                         .ToDictionary(
                kvp => kvp.Key,
                kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).ToArray()
                );
            Session["product"] = product;
            return(Json(new
            {
                newUrl = Url.Action("AddProduct") //Payment as Action; Process as Controller
            }
                        ));
        }