// GET: details of the makeupproduct with id =id public ActionResult Show(int?id) { //if the id is null, then return this message of the bad request. if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MakeupProduct MakeupProduct = db.MakeupProducts.SqlQuery("select * from makeupproducts where makeupproductid=@MakeupProductID", new SqlParameter("@MakeupProductID", id)).FirstOrDefault(); //if id exists, but the makeupproduct does not exist, then return this message. if (MakeupProduct == null) { return(HttpNotFound()); } //need information about the list of stores associated with that makeupproduct string query = "select * from stores inner join StoreMakeupProducts on Stores.StoreID = StoreMakeupProducts.Store_StoreID where MakeupProduct_MakeupProductID = @id"; SqlParameter param = new SqlParameter("@id", id); List <Store> StoreMakeupProducts = db.Stores.SqlQuery(query, param).ToList(); //using viewmodel here to get the list of the stores ShowMakeupProduct viewmodel = new ShowMakeupProduct(); viewmodel.makeupProduct = MakeupProduct; viewmodel.stores = StoreMakeupProducts; return(View(viewmodel)); }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,Product,Brand,Ounce,Price,ProductLink,Comments,DatePurchased,MakeupCategory")] MakeupProduct makeupProduct) { if (id != makeupProduct.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(makeupProduct); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MakeupProductExists(makeupProduct.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(EyeIndex))); } ViewData["MakeupCategory"] = new SelectList(_context.MakeupCategory, "Id", "Category", makeupProduct.MakeupCategory); return(View(makeupProduct)); }
//for the confirmation of the delete. public ActionResult DeleteConfirm(int id) { string query = "select * from makeupproducts where makeupproductid = @id"; SqlParameter param = new SqlParameter("@id", id); MakeupProduct selectedmakeupproduct = db.MakeupProducts.SqlQuery(query, param).FirstOrDefault(); return(View(selectedmakeupproduct)); }
public ActionResult Edit(int id, string MakeupName_Edit, string MakeupDescription_Edit, string MakeupColour_Edit, string MakeupCategory_Edit, string MakeupIngredients_Edit, DateTime MakeupDateOpened_Edit, int MakeupMonthShelfLife_Edit, int MakeupRating_Edit, int?MakeupIsRecommended_Edit, int MakeupBrand_Edit, HttpPostedFileBase makeupImg) { string query = "UPDATE MakeupProducts " + "SET MakeupName=@name, MakeupDescription=@description, MakeupCategory=@category, MakeupIngredients=@ingredients," + "MakeupDateOpened=@dateOpened, MakeupMonthShelfLife=@MonthShelfLife, MakeupRating=@rating, IsRecommended=@isRecommended, HasPic=@pic, ImgType=@type, Brand_BrandId=@bId " + "WHERE MakeupProductId=@mId"; MakeupProduct makeupProduct = db.MakeupProducts.Find(id); //current image values of makeup product int MakeupHasPic_Edit = makeupProduct.HasPic; string MakeupImgType_Edit = makeupProduct.ImgType; //Referenced Christines FirstMVC example if (makeupImg?.ContentLength > 0) { //file extensioncheck taken from https://www.c-sharpcorner.com/article/file-upload-extension-validation-in-asp-net-mvc-and-javascript/ var validTypes = new[] { "jpeg", "jpg", "png", "gif" }; var extension = Path.GetExtension(makeupImg.FileName).Substring(1); if (validTypes.Contains(extension)) { string fileName = id + "." + extension; string path = Path.Combine(Server.MapPath("~/imgs/makeupProducts"), fileName); makeupImg.SaveAs(path); //New HasPic and ImgType value for makeup product MakeupHasPic_Edit = 1; MakeupImgType_Edit = extension; } } //if makeup product was not recommended (not checked off), changes value to 0 if (MakeupIsRecommended_Edit != 1) { MakeupIsRecommended_Edit = 0; } SqlParameter[] parameters = { new SqlParameter("@name", MakeupName_Edit), new SqlParameter("@description", MakeupDescription_Edit), new SqlParameter("@category", MakeupCategory_Edit), new SqlParameter("@ingredients", MakeupIngredients_Edit), new SqlParameter("@dateOpened", MakeupDateOpened_Edit), new SqlParameter("@MonthShelfLife", MakeupMonthShelfLife_Edit), new SqlParameter("@rating", MakeupRating_Edit), new SqlParameter("@isRecommended", MakeupIsRecommended_Edit), new SqlParameter("@pic", MakeupHasPic_Edit), new SqlParameter("@type", MakeupImgType_Edit), new SqlParameter("@bId", MakeupBrand_Edit), new SqlParameter("@mId", id), }; db.Database.ExecuteSqlCommand(query, parameters); return(RedirectToAction("Details/" + id)); }
public async Task <IActionResult> Create([Bind("Id,Product,Brand,Ounce,Price,ProductLink,Comments,DatePurchased,MakeupCategory")] MakeupProduct makeupProduct) { if (ModelState.IsValid) { makeupProduct.Id = Guid.NewGuid(); _context.Add(makeupProduct); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(EyeIndex))); } ViewData["MakeupCategory"] = new SelectList(_context.MakeupCategory, "Id", "Category", makeupProduct.MakeupCategory); return(View(makeupProduct)); }
public ActionResult Update(int id) { //to get information for a makeupproduct that we want to update. MakeupProduct selectedmakeupproduct = db.MakeupProducts.SqlQuery("select * from makeupproducts where makeupproductid = @id", new SqlParameter("@id", id)).FirstOrDefault(); List <Brand> Brands = db.Brands.SqlQuery("select * from brands").ToList(); UpdateMakeupProduct UpdateMakeupProductViewModel = new UpdateMakeupProduct(); UpdateMakeupProductViewModel.MakeupProduct = selectedmakeupproduct; UpdateMakeupProductViewModel.Brand = Brands; //using viewmodel to get the list of all the brands in order to perform updation of the makeupproduct. return(View(UpdateMakeupProductViewModel)); //Debug.WriteLine("Want to update a makeupproduct with name " + MakeupProductName + " and notes " + MakeupProductNotes) ; }
public ActionResult Edit(int?id) { //check to see if makeup product with this id exists in the database MakeupProduct makeupProduct = new MakeupProduct(); makeupProduct = db.MakeupProducts.Find(id); if (id == null || makeupProduct == null) { return(HttpNotFound()); } else { MakeupProductEdit makeupEdit = new MakeupProductEdit { MakeupProduct = makeupProduct, Brands = db.Brands.ToList() }; return(View(makeupEdit)); } }