public ActionResult DeleteConfirmed(int id) { productDetail productdetail = db.productDetails.Find(id); db.productDetails.Remove(productdetail); db.SaveChanges(); return(RedirectToAction("Index")); }
public ProductDetailsWithImages PutProductDetails(productDetail pd, productImage pi) { ProductDetailsWithImages finalModel = new ProductDetailsWithImages(); finalModel.productdetails = pd; finalModel.productimages = pi; return(finalModel); }
public async Task <ActionResult> DeleteConfirmed(int id) { productDetail productDetail = await db.productDetails.FindAsync(id); db.productDetails.Remove(productDetail); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
// // GET: /Admin/Delete/5 public ActionResult Delete(int id = 0) { productDetail productdetail = db.productDetails.Find(id); if (productdetail == null) { return(HttpNotFound()); } return(View(productdetail)); }
public ActionResult Edit(productDetail productdetail) { if (ModelState.IsValid) { db.Entry(productdetail).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(productdetail)); }
public ActionResult productList(string newProd, string Price, int id) { productDetail addProd = new productDetail { menuId = id, nameOfProduct = newProd, Price = Price }; db.productDetails.Add(addProd); db.SaveChanges(); return(Redirect("~/Menu/productList/" + id)); }
public ActionResult Create(productDetail productdetail) { if (ModelState.IsValid) { db.productDetails.Add(productdetail); db.SaveChanges(); return(RedirectToAction("AddNewImage")); } return(View(productdetail)); }
public async Task <ActionResult> Edit([Bind(Include = "pdid,productID,name,description,bprice,sprice,discountAllowed,discountReceived,date")] productDetail productDetail) { if (ModelState.IsValid) { db.Entry(productDetail).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.productID = new SelectList(db.products, "pid", "name", productDetail.productID); return(View(productDetail)); }
// GET: productDetails/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } productDetail productDetail = await db.productDetails.FindAsync(id); if (productDetail == null) { return(HttpNotFound()); } return(View(productDetail)); }
// GET: productDetails/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } productDetail productDetail = await db.productDetails.FindAsync(id); if (productDetail == null) { return(HttpNotFound()); } ViewBag.productID = new SelectList(db.products, "pid", "name", productDetail.productID); return(View(productDetail)); }
public List <productDetail> getProductDetailsByOrder(int orderId) { List <productDetail> list = new List <productDetail>(); context.products_by_order.ToList().ForEach(x => { if (x.orderId == orderId) { productDetail p = new productDetail(x.products); p.quantity = x.quantity; list.Add(p); } }); return(list); }
public bool SaveProduct(ProductDetailsModel pod) { productDetail pd = new productDetail(); pd.ProductName = pod.ProductName; pd.ProductDetails = pod.ProductDetails; pd.ProductType = pod.ProductType; _dbContext.productDetails.Add(pd); if (_dbContext.SaveChanges() == 1) { return(true); } else { return(false); } }
public ActionResult productDetail(int id) { Products pro = ctx.productBll.getOne(id); if (pro != null) { productDetail detail = new productDetail { relatedProducts = ctx.productBll.getAll().Where(x => x.categoryID == pro.categoryID).Take(20).ToList(), singleProduct = pro, }; return(View(detail)); } else { return(PartialView("_error", "The Product is not Found")); } }
public void TC_AddProductToBasket([Values("ipad", "iphone")] string products) { test = extent.CreateTest("Test Case to Search " + products); var homePage = new home(); var loginPage = new login(driver); var searchPage = new searchResults(driver); var productDetailPage = new productDetail(driver); var basketPage = new basket(driver); string productNameCaptured; //Login to Amazon test.Log(Status.Info, "Login to Amamzon website"); //Assert.IsTrue(homePage.verifyHomePage("Sign in"), "Amamzon home page is unavailable"); AllClassesObjects aco = new AllClassesObjects(); Assert.IsTrue(aco.homePage.verifyHomePage("Sign in"), "Amamzon home page is unavailable"); homePage.clickOnSignIn(); loginPage.setUser_email(ConfigurationManager.AppSettings.Get("email")); loginPage.clickOnContinue(); loginPage.setUser_password(ConfigurationManager.AppSettings.Get("password")); loginPage.clickOnSubmit(); Assert.IsTrue(homePage.verifyHomePage(ConfigurationManager.AppSettings.Get("user")), "User is not logged in"); test.Log(Status.Info, "Login successfull"); //Search the product in Amazon homePage.setSearch_Product(products); homePage.clickOnSearchBtn(); productNameCaptured = searchPage.getFirstProductName(); searchPage.verifyProductLandPage(products); test.Log(Status.Info, "The first product name from search list: " + productNameCaptured); searchPage.clickOnFirstProduct(); //Add product to cart Assert.IsTrue(productDetailPage.verifyProduct(productNameCaptured), "Failed to verify the product: " + productNameCaptured); productDetailPage.clickOnAddToCartBtn(); Assert.IsTrue(basketPage.verifyProductAddedToCart(), "Failed to add product to basket"); test.Log(Status.Info, "Successfully added product to Basket"); }
public IActionResult Put(int id, [FromForm] IFormCollection data) { string customMessage = ""; string fileName = ""; //create Product object Product newProduct = new Product() { productDetails = new List <productDetail>(), productDiscountRates = new List <productDiscountRate>() }; //Create a new productDetail and productDiscountRate object productDetail foundOneProductDetail = new productDetail(); productDiscountRate foundOneProductDiscountRate = new productDiscountRate(); //Cloudinary account //Account account = new Account( // "singapore-polytechnic-csc-assignment-ca1", // "475859446543313", // "CQfmX8pn-pNZOFijjVn-nIhqKqs"); //Cloudinary cloudinary = new Cloudinary(account); discountRate foundOneDiscountRate = new discountRate(); try { var foundOneProd = Database.Products .SingleOrDefault(oneProd => oneProd.prodId == id); // //Required Fields foundOneProd.prodName = data["prodName"]; foundOneProd.prodCode = data["prodCode"]; foundOneProd.prodImgUrl = null; foundOneProd.brandId = Convert.ToInt32(data["brandId"]); foundOneProd.createdAt = DateTime.Now; // //Get File Path // if (fileInput != null) // { // foreach (var file in fileInput) // { // fileName = Path.GetFullPath(file.FileName); // } // } // //Image // if (fileName != null) // { // var uploadParams = new ImageUploadParams() // { // File = new FileDescription(fileName) // }; // var uploadResult = cloudinary.Upload(uploadParams); // } //Optional Fields foundOneProd.guaranteedAnalysis = data["GA"]; foundOneProd.prodDesc = data["prodDesc"]; foundOneProd.prodIngredients = data["prodIng"]; foundOneProd.updatedBy = data["updatedBy"]; foundOneProd.createdBy = data["createdBy"]; if (data["published"].Count != 0) { foundOneProd.published = Convert.ToInt32(data["published"]); } foundOneProd.updatedAt = DateTime.Now; //List of prices var priceArray = data["price"].ToArray(); List <String[]> priceAttributes = new List <String[]>(); //Update Database Database.Update(foundOneProd); //Save changess Database.SaveChanges(); } catch (Exception ex) { if (ex.InnerException != null) { if (ex.InnerException.Message.Contains("Product_prodName_UniqueConstraint") == true) { customMessage = "Unable to save Product record due to another record having the same name: " + data["prodName"]; return(BadRequest(new { message = customMessage })); } else { customMessage = "Unable to save Product record due to internal server errors"; return(BadRequest(new { message = customMessage })); } } else { Debug.WriteLine("THE EXCEPTION IS " + ex); } } ////List of prices //var discountArray = data["discount"].ToArray(); //List<String[]> discountAttributes = new List<String[]>(); //Debug.WriteLine("PRICE DATA " + discountArray[0] + " AND " + discountArray[0][0]); ////For each discount input in discount price //for (int i = 0; i < discountArray.Length; i++) //{ // try // { // discountAttributes.Add(discountArray[i].Split(",")); // for (int j = 0; j < discountAttributes[i].Count(); j++) // { // switch (j) // { // case 0: // foundOneDiscountRate.discName = discountAttributes[i][j]; // break; // case 1: // foundOneDiscountRate.discRate = Convert.ToInt32(discountAttributes[i][j]); // break; // default: // break; // } // } // Database.Update(foundOneDiscountRate); // Database.SaveChanges(); // foundOneProductDiscountRate.discountId = foundOneDiscountRate.discId; // foundOneProductDiscountRate.prodId = foundOneProductDiscountRate.prodId; // Database.Update(foundOneProductDiscountRate); // Database.SaveChanges(); // Debug.WriteLine("CHANGES TO DISCOUNT RATE TABLE SAVED"); // } // catch (Exception ex) // { // Debug.WriteLine("DISCOUNT RATE ERROR: " + ex); // } //} return(Ok(new { message = "Updated Brand Record" })); }
public async Task <IActionResult> Post(IFormCollection data, IList <IFormFile> fileInput) { //Initialize Variables string customMessage = ""; int fileCount = 0; string url = ""; //create Product object Product newProduct = new Product() { productDetails = new List <productDetail>(), productDiscountRates = new List <productDiscountRate>() }; //Create a new discountRate, productDetail and productDiscountRate object discountRate newDiscountRate = new discountRate(); productDetail newProductDetail = new productDetail(); productDiscountRate newProductDiscountRate = new productDiscountRate(); //Passing data into newProduct //Required Fields newProduct.prodName = data["prodName"]; newProduct.prodCode = data["prodCode"]; //newProduct.prodImgUrl = data["prodImgUrl"]; newProduct.brandId = Convert.ToInt32(data["brandId"]); newProduct.createdAt = DateTime.Now; //Image LogFile logFile = new LogFile(); foreach (IFormFile oneFile in fileInput) { if (oneFile != null) { var fileName = ContentDispositionHeaderValue .Parse(oneFile.ContentDisposition) .FileName .Trim('"'); string contentType = oneFile.ContentType; try { //http://stackoverflow.com/questions/16392751/unable-to-cast-base-class-data-contract-to-derived-class logFile = await CloudinaryAPIs. UploadFileToCloudinary <LogFile>(UPLOAD_PRESET, oneFile.OpenReadStream(), contentType, fileName); logFile.Description = data["description"]; } catch (Exception ex) { Console.WriteLine(ex.Message); } if (logFile.PublicCloudinaryId != "") { url = logFile.Url; Database.LogFiles.Add(logFile); Database.SaveChanges(); fileCount += 1; } else { return(BadRequest(new { message = "Unable to save file" })); } }//end of checking if there is a file for upload } newProduct.prodImgUrl = url; //Optional Fields newProduct.guaranteedAnalysis = data["GA"]; newProduct.prodDesc = data["prodDesc"]; newProduct.prodIngredients = data["prodIng"]; newProduct.updatedBy = data["updatedBy"]; newProduct.createdBy = data["createdBy"]; //newProduct.minQty = Convert.ToInt32(data["minQty"]); //newProduct.prodQty = Convert.ToInt32(data["prodQty"]); if (data["published"].Count != 0) { newProduct.published = Convert.ToInt32(data["published"]); } newProduct.updatedAt = DateTime.Now; //List of prices var priceArray = data["price"].ToArray(); List <String[]> priceAttributes = new List <String[]>(); Debug.WriteLine("PRICE DATA " + priceArray[0] + " AND " + priceArray[0][0]); try { //Add newStudent object Database.Add(newProduct); //Save changess Database.SaveChanges(); Debug.WriteLine("CHANGES TO PRODUCT TABLE SAVED"); } catch (Exception ex) { if (ex.InnerException != null) { if (ex.InnerException.Message.Contains("Product_prodName_UniqueConstraint") == true) { customMessage = "Unable to save Product record due to another record having the same name: " + data["prodName"]; return(BadRequest(new { message = customMessage })); } else { customMessage = "Unable to save Product record due to internal server errors"; return(BadRequest(new { message = customMessage })); } } else { Debug.WriteLine("THE EXCEPTION IS " + ex); } } ////For each price input in array price for (int i = 0; i < priceArray.Length; i++) { try { priceAttributes.Add(priceArray[i].Split(",")); for (int j = 0; j < priceAttributes[i].Count(); j++) { newProductDetail.prodId = newProduct.prodId; switch (j) { case 0: newProductDetail.weightAmount = Convert.ToInt32(priceAttributes[i][j]); break; case 1: newProductDetail.weightUnit = priceAttributes[i][j]; break; case 2: newProductDetail.price = Convert.ToInt32(priceAttributes[i][j]); break; default: break; } } Database.Add(newProductDetail); Database.SaveChanges(); Debug.WriteLine("CHANGES TO PRODUCT DETAIL TABLE SAVED"); } catch (Exception ex) { Debug.WriteLine("PRODUCT DETAIL ERROR: " + ex); } } //List of prices var discountArray = data["discount"].ToArray(); List <String[]> discountAttributes = new List <String[]>(); Debug.WriteLine("PRICE DATA " + discountArray[0] + " AND " + discountArray[0][0]); ////For each discount input in discount price for (int i = 0; i < discountArray.Length; i++) { try { discountAttributes.Add(discountArray[i].Split(",")); for (int j = 0; j < discountAttributes[i].Count(); j++) { switch (j) { case 0: newDiscountRate.discName = discountAttributes[i][j]; break; case 1: newDiscountRate.discRate = Convert.ToInt32(discountAttributes[i][j]); break; default: break; } } Database.Add(newDiscountRate); Database.SaveChanges(); newProductDiscountRate.discountId = newDiscountRate.discId; newProductDiscountRate.prodId = newProduct.prodId; Database.Add(newProductDiscountRate); Database.SaveChanges(); Debug.WriteLine("CHANGES TO DISCOUNT RATE TABLE SAVED"); } catch (Exception ex) { Debug.WriteLine("DISCOUNT RATE ERROR: " + ex); } } return(Ok(new { message = "Saved Brand Record" })); }