public ActionResult CreateFromASIN(AmazonImportModel.CreateFromASINModel model) { //allow this page to been seen only after logging in if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) { return(null); } if (ModelState.IsValid) { var allASINs = GetAllAmazonProductASINs(); if (GetAllAmazonProductASINs().Contains(model.ASIN)) //product already exists, show error { ModelState["ASIN"].Errors.Add("A product with this ASIN already exists"); } else { AmazonItem item = AmazonSearcher.GetItem(model.ASIN); if (item != null) //item was found on Amazon { //add the created Product to the database int productId = AddAmazonItem(item); //open "Edit product" page for the newly created product return(RedirectToAction("Edit", "Product", new { id = productId })); } else //item was not found { ModelState["ASIN"].Errors.Add("An item with this ASIN was not found on Amazon"); } } //if (GetAllAmazonProductASINs().Contains(model.ASIN)) } //if ModelState.IsValid //problem occured, display the form again with an appropriate error message return(View("Nop.Plugin.Misc.AmazonImport.Views.MiscAmazonImport.CreateFromASIN", model)); }
public ActionResult CreateFromASIN(string ASIN) { //allow this page to been seen only after logging in if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) { return(null); } if (ASIN == null) //no ASIN supplied, show form { var model = new AmazonImportModel.CreateFromASINModel(); return(View("Nop.Plugin.Misc.AmazonImport.Views.MiscAmazonImport.CreateFromASIN", model)); } //if product already exists, show error if (GetAllAmazonProductASINs().Contains(ASIN)) { return(View("Nop.Plugin.Misc.AmazonImport.Views.MiscAmazonImport.ItemAlreadyExists")); } //search for product form amazon AmazonItem item = AmazonSearcher.GetItem(ASIN); if (item != null) //add product to database and open the product editing form { int productId = AddAmazonItem(item); //open "Edit product" page for the newly created product return(RedirectToAction("Edit", "Product", new { id = productId })); } else //product could no longer be found on amazon { _logger.Error("Adding product failed: product could no longer be found on Amazon"); return(null); } }