public ActionResult EditProduct(AddedProduct product) { if (!ModelState.IsValid) { return(View(product)); } string userEmail = authorizationManagement.IsUserLogedIn(); Account currentUser = context.Accounts.FirstOrDefault(a => a.Email == userEmail); int currentUserId = currentUser.Id; Product realProduct = context.Products.FirstOrDefault(p => p.Id == product.Id); if (realProduct.AccountId != currentUserId) { messageScreen.Typr = "false"; messageScreen.Content = "فضل تحديث المنتج "; return(RedirectToAction("Index", "Message", messageScreen)); } realProduct.Name = product.Name; realProduct.Stock = product.Stock; realProduct.SmallDisc = product.SmallDisc; realProduct.Price = product.Price; realProduct.DiscountPercentage = product.DiscountPercentage; realProduct.Discription = product.Discription; realProduct.SubCategoryId = product.SubCategoryId; context.SaveChanges(); messageScreen.Typr = "true"; messageScreen.Content = "تم تحديث المنتج بنجاح"; return(RedirectToAction("Index", "Message", messageScreen)); }
public ActionResult EditProduct(int productId) { string userEmail = authorizationManagement.IsUserLogedIn(); Account currentUser = context.Accounts.FirstOrDefault(a => a.Email == userEmail); int currentUserId = currentUser.Id; var product = context.Products.FirstOrDefault(p => p.Id == productId); if (product.AccountId != currentUserId) { messageScreen.Typr = "false"; messageScreen.Content = "فضل تحديث المنتج "; return(RedirectToAction("Index", "Message", messageScreen)); } AddedProduct addProduct = new AddedProduct() { Id = product.Id, Name = product.Name, Price = product.Price, Stock = product.Stock, SmallDisc = product.SmallDisc, DiscountPercentage = product.DiscountPercentage, Discription = product.Discription, SubCategoryId = product.SubCategoryId, IsService = product.IsService, AccountId = product.AccountId }; return(View(addProduct)); }
public void BuyProduct(AddedProduct addedProduct) { if (!AllInOneMobileSettings.Instance.useInAppPurchases) { Debug.LogError("InApp-Purchases are disabled."); return; } string id = AllInOneMobileSettings.Instance.products.Find(x => x.name == addedProduct.ToString()).id; BuyProductID(id); }
public void AddToBasket(Basket basket, Products product) { try { AddedProduct addedProduct = basket.AddedProducts.FirstOrDefault(x => x.Product.ID == product.ID); if (addedProduct != null) { addedProduct.Quantity++; } else { basket.AddedProducts.Add(new AddedProduct { Product = product, Quantity = 1 }); } product.UnitInStock--; _ProductService.Update(product); } catch (Exception) { } }
public ActionResult AddProduct(AddedProduct product, HttpPostedFileBase[] ImageFiles) { if (!ModelState.IsValid) { return(View(product)); } if (ImageFiles.Length == 0) { product.Error = "الرجاء رفع صورة واحدة للمنتج على الأقل"; return(View(product)); } string userEmail = authorizationManagement.IsUserLogedIn(); Account currentUser = context.Accounts.FirstOrDefault(a => a.Email == userEmail); int currentUserId = currentUser.Id; foreach (HttpPostedFileBase file in ImageFiles) { string FileName = Path.GetFileNameWithoutExtension(file.FileName); string FileExtension = Path.GetExtension(file.FileName); if (FileExtension.ToLower() != ".jpg" && FileExtension.ToLower() != ".png") { product.Error = "الرجاء إختيار جميع الصور بصيغة png او jpg"; return(View(product)); } } Product realProduct = new Product() { Name = product.Name, AccountId = currentUserId, Price = product.Price, Stock = product.Stock, SmallDisc = product.SmallDisc, DiscountPercentage = product.DiscountPercentage, SubCategoryId = product.SubCategoryId, Discription = product.Discription, IsService = product.IsService }; context.Products.Add(realProduct); context.SaveChanges(); Product lastProduct = context.Products.Where(p => p.AccountId == currentUserId).OrderByDescending(p => p.Id).FirstOrDefault(); foreach (HttpPostedFileBase file in ImageFiles) { string FileName = Path.GetFileNameWithoutExtension(file.FileName); string FileExtension = Path.GetExtension(file.FileName); FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "-" + FileName.Trim() + FileExtension; string UploadPath = AppDomain.CurrentDomain.BaseDirectory + "ProductPicture\\"; Picture picture = new Picture() { ProductId = lastProduct.Id, Path = FileName }; file.SaveAs(UploadPath + FileName); context.Pictures.Add(picture); context.SaveChanges(); } messageScreen.Typr = "true"; messageScreen.Content = "تم تسجيل المنتج بنجاح"; messageScreen.Action = "MyProducts"; messageScreen.Control = "Store"; return(RedirectToAction("Index", "Message", messageScreen)); }
public ActionResult AddProduct() { AddedProduct product = new AddedProduct(); return(View(product)); }