public async Task <int> AddAsync(ProductLanguage productLanguage) { var cmd = QueriesCreatingHelper.CreateQueryInsert(productLanguage); cmd += ";SELECT LAST_INSERT_ID();"; return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First()); }
public static ProductLanguageModel ToModel(ProductLanguage entity) { if (entity == null) { return(null); } return(new ProductLanguageModel() { Id = entity.Id, ProductId = entity.ProductId, Language = entity.Language, TypeName = entity.TypeName, ImageDetailText = entity.ImageDetailText, DescriptionDetailText = entity.DescriptionDetailText, DescriptionDetailHeader = entity.DescriptionDetailHeader, ReviewText = entity.ReviewText, VideoDetailText = entity.VideoDetailText, VideoDetailSrc = entity.VideoDetailSrc, VideoDetailAlt = entity.VideoDetailAlt, LinkStoreHeader = entity.LinkStoreHeader, LinkStoreContent = entity.LinkStoreContent, Description = entity.Description, ImageSrc = entity.ImageSrc, ImageAlt = entity.ImageAlt, TitleTagForSEO = entity.TitleTagForSEO, TitleText = entity.TitleText, ProductDetailText = entity.ProductDetailText }); }
internal static void Load(ProductLanguageCollection languages) { string query = " SELECT OptionId, OptionName, LocalName, CultureId" + " FROM ListLanguages WHERE WebsiteSupport = 1"; using (SqlConnection cnn = new SqlConnection(Configurations.ConnectionString)) { using (SqlCommand cmd = new SqlCommand(query, cnn)) { cmd.CommandType = CommandType.Text; cnn.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader != null && reader.HasRows) { while (reader.Read()) { ProductLanguage language = new ProductLanguage(); language.Id = Repository.Utils.Convert.ToInt32(reader[0]); language.Name = Repository.Utils.Convert.ToString(reader[1]); // reader[2] language.CultureId = Repository.Utils.Convert.ToString(reader[3]); languages.Add(language); } } cnn.Close(); } } }
public JsonResult Add(int id, int quantity, int sizeId) { int langId = HttpContext.GetLanguage("langId"); ProductLanguage prd = db.ProductLanguages.Where(pl => pl.ProductId == id && pl.LanguageId == langId) .Include(pl => pl.Product).FirstOrDefault(); if (prd == null) { return(Json(new { status = 404 })); } if (HttpContext.Session.GetString("Card") == null) { HttpContext.Session.SetObjectAsJson("Card", new List <Card>()); } List <Card> Carts = HttpContext.Session.GetObjectFromJson <Card>("Card") as List <Card>; if (Carts.Find(c => c.Id == prd.ProductId && c.SizeId == sizeId) != null) { Carts.Find(c => c.Id == prd.ProductId).Quantity += quantity; } else { Card card = new Card { Id = prd.ProductId, Quantity = quantity, Name = prd.Name, Price = prd.Product.DiscountPercent != 0 ? (decimal)(prd.Product.Price - (prd.Product.Price * prd.Product.DiscountPercent / 100)) : prd.Product.Price, Photo = "/Admin/Uploads/Products/" + db.ProductPhotos.Where(p => p.ProductId == prd.ProductId).FirstOrDefault().PhotoPath, ProductDbQuantity = prd.Product.Quantity, SizeId = sizeId, SizeName = db.Sizes.Where(s => s.Id == sizeId).FirstOrDefault().Name }; Carts.Add(card); } HttpContext.Session.SetObjectAsJson("Card", Carts); return(Json(new { status = 200, data = new { count = Carts.Sum(c => c.Quantity), total = Carts.Sum(c => c.Quantity * c.Price).ToString(), list = Carts } })); }
public async Task <Product> ScaffoldProductForCreationAsync(ProductForCreationDto productForCreationDto, Requirements requirements, Category selectedCategory) { if (productForCreationDto == null) { throw new ArgumentException("Product that was passed to CreateAsync method is null"); } var product = new Product { Name = productForCreationDto.Name, Description = productForCreationDto.Description, Pegi = productForCreationDto.Pegi, Price = productForCreationDto.Price, IsDigitalMedia = productForCreationDto.IsDigitalMedia, ReleaseDate = productForCreationDto.ReleaseDate, Category = selectedCategory, Requirements = requirements, Languages = new List <ProductLanguage>(), SubCategories = new List <ProductSubCategory>(), Stock = new Stock() }; if (productForCreationDto.LanguagesId != null) { foreach (var languageId in productForCreationDto.LanguagesId) { var selectedLanguages = await _ctx.Languages.FirstOrDefaultAsync(l => l.Id == languageId); var pl = new ProductLanguage { Product = product, Language = selectedLanguages }; product.Languages.Add(pl); } } if (productForCreationDto.SubCategoriesId != null) { foreach (var subCategoryId in productForCreationDto.SubCategoriesId) { var selectedSubCategory = await _ctx.SubCategories.FirstOrDefaultAsync(sc => sc.Id == subCategoryId); var psc = new ProductSubCategory { Product = product, SubCategory = selectedSubCategory }; product.SubCategories.Add(psc); } } return(product); }
public JsonResult Remove(int id, int sizeId) { int langId = HttpContext.GetLanguage("langId"); ProductLanguage prd = db.ProductLanguages.Where(pl => pl.ProductId == id && pl.LanguageId == langId) .Include(pl => pl.Product).FirstOrDefault(); if (prd == null) { return(Json(new { status = 404 })); } if (HttpContext.Session.GetString("Card") == null) { return(Json(new { status = 405 })); } List <Card> Carts = HttpContext.Session.GetObjectFromJson <Card>("Card") as List <Card>; if (Carts.Find(c => c.Id == prd.ProductId && c.SizeId == sizeId) == null) { return(Json(new { status = 406 })); } Carts.Remove(Carts.Find(c => c.Id == prd.ProductId)); HttpContext.Session.SetObjectAsJson("Card", Carts); return(Json(new { status = 200, data = new { count = Carts.Sum(c => c.Quantity), total = Carts.Sum(c => c.Quantity * c.Price).ToString(), list = Carts } })); }
public JsonResult Add(int id) { int langId = HttpContext.GetLanguage("langId"); ProductLanguage prd = db.ProductLanguages.Where(pl => pl.ProductId == id && pl.LanguageId == langId) .Include(pl => pl.Product).FirstOrDefault(); if (prd == null) { return(Json(new { status = 404 })); } if (HttpContext.Session.GetString("Wishlist") == null) { HttpContext.Session.SetObjectAsJson("Wishlist", new List <Card>()); } List <Card> Wishlist = HttpContext.Session.GetObjectFromJson <Card>("Wishlist") as List <Card>; if (Wishlist.Find(c => c.Id == prd.ProductId) != null) { Wishlist.Remove(Wishlist.Find(c => c.Id == prd.ProductId)); } else { Card wishlistCard = new Card { Id = prd.ProductId, Name = prd.Name, Price = prd.Product.Price, Photo = "/Admin/Uploads/Products/" + db.ProductPhotos.Where(p => p.ProductId == prd.ProductId).FirstOrDefault().PhotoPath, ProductDbQuantity = prd.Product.Quantity, DiscountPercent = prd.Product.DiscountPercent }; Wishlist.Add(wishlistCard); } HttpContext.Session.SetObjectAsJson("Wishlist", Wishlist); return(Json(new { status = 200, list = Wishlist, })); }
public static void Load(string culture, Entities.CategoryParent categories) { ProductLanguage language = Repository.Memory.Languages.Instance.Items[culture]; string query = " SELECT CategoryId, CategoryName, UrlName" + " FROM Categories" + " WHERE (ParentId<0 AND LanguageId=@LanguageId)" + " ORDER BY CategoryName"; using (SqlConnection cnn = new SqlConnection(Configurations.ConnectionString)) { using (SqlCommand cmd = new SqlCommand(query, cnn)) { cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SqlParameter("@LanguageId", language.Id)); foreach (SqlParameter Parameter in cmd.Parameters) { if (Parameter.Value == null) { Parameter.Value = DBNull.Value; } } cnn.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader != null && reader.HasRows) { while (reader.Read()) { Entities.Category cat = new Entities.Category(); cat.CategoryId = Repository.Utils.Convert.ToInt32(reader[0]); cat.CategoryName = Repository.Utils.Convert.ToString(reader[1]); cat.UrlName = Repository.Utils.Convert.ToString(reader[2]); LoadSubCategories(cat.SubCategories, cat.CategoryId, language.Id); categories.Add(cat); } } cnn.Close(); } } }
public async Task <Product> ScaffoldProductForEditAsync(int id, ProductEditDto productToEditDto, Requirements requirements, Category selectedCategory, Product productFromDb) { var updatedProduct = new Product { Id = id, Name = productToEditDto.Name, Description = productToEditDto.Description, Pegi = productToEditDto.Pegi, Price = productToEditDto.Price, IsDigitalMedia = productToEditDto.IsDigitalMedia, ReleaseDate = productToEditDto.ReleaseDate, Category = selectedCategory, Requirements = requirements, Languages = new List <ProductLanguage>(), SubCategories = new List <ProductSubCategory>() }; foreach (var languageId in productToEditDto.LanguagesId) { var selectedLanguages = await _ctx.Languages.FirstOrDefaultAsync(l => l.Id == languageId); var pl = new ProductLanguage { Product = updatedProduct, Language = selectedLanguages }; if (!productFromDb.Languages.Contains(pl)) { updatedProduct.Languages.Add(pl); } } foreach (var subCategoryId in productToEditDto.SubCategoriesId) { var selectedSubCategory = await _ctx.SubCategories.FirstOrDefaultAsync(sc => sc.Id == subCategoryId); var psc = new ProductSubCategory { Product = updatedProduct, SubCategory = selectedSubCategory }; if (!productFromDb.SubCategories.Contains(psc)) { updatedProduct.SubCategories.Add(psc); } } return(updatedProduct); }
public async Task <int> AddOrUpdateLanguage(ProductLanguage language) { string cmd = QueriesCreatingHelper.CreateQuerySelect <ProductLanguage>($"product_id = {language.ProductId} AND language_id = {language.LanguageId}"); var lang = (await DALHelper.ExecuteQuery <ProductLanguage>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).FirstOrDefault(); if (lang == null) { cmd = QueriesCreatingHelper.CreateQueryInsert(language); cmd += ";SELECT LAST_INSERT_ID();"; return(await DALHelper.Execute(cmd, dbTransaction : DbTransaction, connection : DbConnection)); } else { language.Id = lang.Id; cmd = QueriesCreatingHelper.CreateQueryUpdate(language); var rs = await DALHelper.Execute(cmd, dbTransaction : DbTransaction, connection : DbConnection); return(rs == 0 ? -1 : language.Id); } }
public JsonResult Remove(int id) { int langId = HttpContext.GetLanguage("langId"); ProductLanguage prd = db.ProductLanguages.Where(pl => pl.ProductId == id && pl.LanguageId == langId) .Include(pl => pl.Product).FirstOrDefault(); if (prd == null) { return(Json(new { status = 404 })); } if (HttpContext.Session.GetString("Wishlist") == null) { return(Json(new { status = 405 })); } List <Card> WishListCards = HttpContext.Session.GetObjectFromJson <Card>("Wishlist") as List <Card>; if (WishListCards.Find(w => w.Id == id) == null) { return(Json(new { status = 406 })); } WishListCards.Remove(WishListCards.Find(c => c.Id == prd.ProductId)); HttpContext.Session.SetObjectAsJson("Wishlist", WishListCards); return(Json(new { status = 200 })); }
public async Task <JsonResult> Delete(int id) { if (id != 0) { //Find Product Product product = await db.Products.Where(p => p.Id == id).FirstOrDefaultAsync(); //Find ProductCategory ProductCategory pc = await db.ProductCategories.Where(p => p.Product == product).FirstOrDefaultAsync(); //Find ProductLanguage ProductLanguage pl = await db.ProductLanguages.Where(p => p.Product == product).FirstOrDefaultAsync(); //Delete Product and All Relations db.Products.Remove(product); db.ProductLanguages.Remove(pl); db.ProductCategories.Remove(pc); await db.SaveChangesAsync(); return(Json(new { status = 200 })); } return(Json(new { status = 400 })); }
public async Task <int> UpdateAsync(ProductLanguage productLanguage) { var cmd = QueriesCreatingHelper.CreateQueryUpdate(productLanguage); return(await DALHelper.Execute(cmd, dbTransaction : DbTransaction, connection : DbConnection)); }
public async Task <JsonResult> Add(ProductViewModel model) { //Check All Models foreach (string item in model.Categories) { if (item == null) { return(Json(new { status = 400, errorMessage = "En azi 1 category elave edin" })); } } if (model.Description == "") { return(Json(new { status = 400, errorMessage = "Description elave edin" })); } if (model.SubCategory == "") { return(Json(new { status = 400, errorMessage = "En azi 1 Subcategory elave edin" })); } if (model.Photo == null) { return(Json(new { status = 400, errorMessage = "Sekil elave edin" })); } foreach (string item in model.RealPartNos) { if (item == null) { return(Json(new { status = 400, errorMessage = "En azi 1 realpartno elave edin" })); } } if (model.LanguageId == "") { return(Json(new { status = 400, errorMessage = "Dil elave edile bilmir" })); } //Find Language Language language = db.Languages.Where(l => l.Key == model.LanguageId).FirstOrDefault(); var sub = model.SubCategory; var description = model.Description; //Make Category and RealPartNo Arrays List <string> categories = MakeArray(model.Categories); List <string> realPartNos = MakeArray(model.RealPartNos); //Upload Photo var photo = model.Photo; var file_name = photo.FileName; var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Uploads", "Products", file_name); if (MyFile.isImage(photo)) { await MyFile.Upload(photo, path); } //Create Product Product product = new Product(); product.SubCategory = await db.SubCategories.Where(s => s.Name == sub).FirstOrDefaultAsync(); product.PhotoPath = photo.FileName; //Creat RealPartNo foreach (var realPartNo in realPartNos) { RealPartNo number = new RealPartNo(); number.Name = realPartNo; number.Product = product; await db.RealPartNos.AddAsync(number); } //Create Category foreach (var item in categories) { if (item != null) { Category category = await db.Categories.Where(c => c.Name == item).FirstOrDefaultAsync(); ProductCategory productCategory = new ProductCategory(); productCategory.Category = category; productCategory.Product = product; db.ProductCategories.Add(productCategory); } } //Create MultiLanguage Product ProductLanguage productLanguage = new ProductLanguage(); productLanguage.LanguageId = language.Id; productLanguage.Product = product; productLanguage.Description = model.Description; await db.ProductLanguages.AddAsync(productLanguage); await db.Products.AddAsync(product); await db.SaveChangesAsync(); return(Json(new { status = 200, message = "Mehsul Elave Edildi" })); }
public async Task <IActionResult> Edit(ProductModel model, int id, int langId) { bool change = false; Product product = await db.Products.Where(pr => pr.Id == id).FirstOrDefaultAsync(); ProductLanguage productLanguage = await db.ProductLanguages.Where(pr => pr.ProductId == product.Id && pr.LanguageId == langId).FirstOrDefaultAsync(); List <ProductCategory> productCategories = await db.ProductCategories.Where(p => p.ProductId == product.Id).ToListAsync(); //Update Description if (model.Description != null) { change = true; productLanguage.Description = model.Description; } //Update Categories if (model.CategoryNames.Count() != 0) { change = true; //Delete Product Categories db.ProductCategories.RemoveRange(productCategories); foreach (var item in model.CategoryNames) { if (item != null) { var category = await db.Categories.Where(c => c.Name == item).FirstOrDefaultAsync(); ProductCategory pr = new ProductCategory(); pr.Category = category; pr.Product = product; await db.ProductCategories.AddAsync(pr); } } } //Update Subcategory if (model.SubCategory != null) { change = true; product.SubCategory = model.SubCategory; } //Update Photo if (Request.Form.Files.Count > 0) { change = true; var file = Request.Form.Files[0]; if (MyFile.isImage(file)) { string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Uploads", "Products", file.FileName); if (!System.IO.File.Exists(path)) { await MyFile.Upload(file, path); } product.PhotoPath = file.FileName; } } if (change) { db.SaveChanges(); } return(RedirectToAction(nameof(Index))); }
public JsonResult ChangeQty(int id, int qty, int sizeId, string key) { int langId = HttpContext.GetLanguage("langId"); decimal shipPrice; if (key != "0" && key != null) { shipPrice = db.Shippings.Where(s => s.Name == key).FirstOrDefault().Price; } else { shipPrice = 0; } ProductLanguage prd = db.ProductLanguages.Where(pl => pl.ProductId == id && pl.LanguageId == langId) .Include(pl => pl.Product).FirstOrDefault(); if (prd == null) { return(Json(new { status = 404 })); } if (HttpContext.Session.GetString("Card") == null) { return(Json(new { status = 405 })); } List <Card> Carts = HttpContext.Session.GetObjectFromJson <Card>("Card") as List <Card>; if (Carts.Find(c => c.Id == prd.ProductId && c.SizeId == sizeId) == null) { return(Json(new { status = 406 })); } if (HttpContext.Session.GetString("Total") != null) { var total = Convert.ToDecimal(HttpContext.Session.GetString("Total")); var oldPrice = Carts.Find(c => c.Id == prd.ProductId).Quantity *Carts.Find(c => c.Id == prd.ProductId).Price; var shipping = total - Carts.Sum(c => c.Quantity * c.Price); Carts.Find(c => c.Id == prd.ProductId && c.SizeId == sizeId).Quantity = qty; var newPrice = Carts.Find(c => c.Id == prd.ProductId).Quantity *Carts.Find(c => c.Id == prd.ProductId).Price; var newTotal = newPrice + shipPrice; HttpContext.Session.SetString("Total", newTotal.ToString()); return(Json(new { status = 200, data = new { count = Carts.Sum(c => c.Quantity), subtotal = (Carts.Find(c => c.Id == prd.ProductId).Quantity *Carts.Find(c => c.Id == prd.ProductId).Price).ToString(), total = newTotal, list = Carts } })); } Carts.Find(c => c.Id == prd.ProductId && c.SizeId == sizeId).Quantity = qty; HttpContext.Session.SetObjectAsJson("Card", Carts); return(Json(new { status = 200, data = new { count = Carts.Sum(c => c.Quantity), subtotal = (Carts.Find(c => c.Id == prd.ProductId).Quantity *Carts.Find(c => c.Id == prd.ProductId).Price).ToString(), total = Carts.Sum(c => c.Quantity * c.Price), list = Carts } })); }
public async Task <IActionResult> Checkout(string cardType, string Zip, string City, string Address) { string user_id = HttpContext.Session.GetString("user_id"); if (user_id != null) { List <Card> cards = HttpContext.Session.GetObjectFromJson <Card>("Card") as List <Card>; if (cardType != null && Zip != null && City != null && Address != null) { #region Make CPaymentItem For API decimal amount = Convert.ToDecimal(HttpContext.Session.GetString("Total")); decimal shippingPrice = amount - cards.Sum(c => c.Quantity * c.Price); CPaymentItem cPaymentItem = new CPaymentItem(); cPaymentItem.merchantName = configuration["PaymentInformation:MerchantName"]; cPaymentItem.amount = (int)(amount * 100); cPaymentItem.cardType = cardType; cPaymentItem.lang = "lv"; cPaymentItem.description = "Product"; cPaymentItem.hashCode = GetMD5HashCode(configuration["PaymentInformation:AuthKey"] + configuration["PaymentInformation:MerchantName"] + cPaymentItem.cardType + cPaymentItem.amount + cPaymentItem.description); #endregion #region Create Payment List <Payment> userOrders = new List <Payment>(); for (var i = 0; i < cards.Count; i++) { Payment currentPayment = new Payment(); //City currentPayment.City = City; //Postal Code currentPayment.PostalCode = Zip; //Address currentPayment.Address = Address; currentPayment.ProductDiscount = cards[i].DiscountPercent; //User string userId = HttpContext.Session.GetString("user_id"); User user = db.Users.Where(u => u.Id == userId).FirstOrDefault(); currentPayment.UserName = user.Name; currentPayment.UserSurname = user.Surname; currentPayment.UserEmail = user.Email; currentPayment.UserId = user.Id; //If user address was null on register then on payment we take address and append to it user.Address = user.Address == null ? Address : user.Address; //Cardtype CardType type = await db.CardTypes.Where(c => c.Key == cardType).FirstOrDefaultAsync(); currentPayment.CardType = type; //Product Product orderedProduct = await db.Products.Where(p => p.Id == cards[i].Id).FirstOrDefaultAsync(); ProductLanguage productLanguage = await db.ProductLanguages .Include(l => l.Language) .Where(p => p.Language.Key == "az" && p.ProductId == orderedProduct.Id) .FirstOrDefaultAsync(); currentPayment.ProductName = productLanguage.Name; currentPayment.ProductPrice = orderedProduct.Price; currentPayment.ProductId = orderedProduct.Id; //Datetime currentPayment.Date = DateTime.Now; //Shipping Price currentPayment.ShippingPrice = shippingPrice; //ProductSize currentPayment.ProductSize = cards[i].SizeName; //Quantity currentPayment.Count = cards[i].Quantity; //Total Price if (currentPayment.ProductDiscount != 0 || currentPayment.ProductDiscount != null) { currentPayment.TotalPrice = (decimal)(cards[i].Price * currentPayment.ProductDiscount / 100) * cards[i].Quantity; } else { currentPayment.TotalPrice = cards[i].Price * cards[i].Quantity; } //Status currentPayment.Status = 2; //TransactionId currentPayment.TransactionId = cPaymentItem.hashCode; userOrders.Add(currentPayment); } await db.Payments.AddRangeAsync(userOrders); await db.SaveChangesAsync(); #endregion #region Send Web Request var jsonValues = JsonConvert.SerializeObject(cPaymentItem); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(configuration["PaymentInformation:RequestToServerUrlGetPaymentKey"]); request.ContentType = "application/json; charset=utf-8"; request.Method = "POST"; request.Accept = "application/json"; using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(jsonValues); streamWriter.Flush(); } #endregion #region Get Web Response string responseData = string.Empty; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { responseData = reader.ReadToEnd(); } CRespGetPaymentKey cRespPymnt = (CRespGetPaymentKey)JsonConvert.DeserializeObject(responseData, typeof(CRespGetPaymentKey)); #endregion if (cRespPymnt.status.code != 1) { throw new Exception("Error while getting paymentKey, code=" + cRespPymnt.status.code + ", message=" + cRespPymnt.status.message); } return(Redirect(configuration["PaymentInformation:ReuqestToServerUrlPayPage"] + cRespPymnt.paymentKey)); } else { return(RedirectToAction("Error", "Payment")); } } else { return(RedirectToAction("Login", "Account")); } }
public static string Format(decimal?money, ProductLanguage culture) { return(Format(money, culture.CultureId)); }
public IActionResult Add(ProductModel model) { if (ModelState.IsValid) { if (model.SubCategoryId != 0 && model.CategoryId != 0) { #region Product Static Properties Add Product product = new Product(); product.CreatedDate = DateTime.Now; product.DiscountPercent = Convert.ToInt32(model.DiscountPercent); product.Price = Math.Ceiling(Convert.ToDecimal(model.Price)); product.SubcategoryId = model.SubCategoryId; for (int i = 0; i < model.Count.Count; i++) { product.Quantity += Convert.ToInt32(model.Count[i]); } //product.Quantity = Convert.ToInt32(model.Quantity); db.Products.Add(product); #endregion List <Language> languages = db.Languages.ToList(); if (Checker.CheckList(model.Names) && Checker.CheckList(model.Sizes) && Checker.CheckList(model.Count) && Checker.CheckList(model.Descriptions) && Checker.CheckList(model.Photos)) { #region Product Language Add for (int i = 0; i < languages.Count; i++) { ProductLanguage productLanguage = new ProductLanguage(); productLanguage.LanguageId = languages[i].Id; productLanguage.Name = model.Names[i]; productLanguage.ProductId = product.Id; productLanguage.Description = model.Descriptions[i]; db.ProductLanguages.Add(productLanguage); } #endregion #region Product Size Add for (int i = 0; i < model.Sizes.Count; i++) { ProductSizeCount productSizeCount = new ProductSizeCount(); productSizeCount.ProductId = product.Id; productSizeCount.SizeId = model.Sizes[i]; productSizeCount.Count = Convert.ToInt32(model.Count[i]); db.ProductSizeCounts.Add(productSizeCount); } #endregion //#region Product Color Add //for (int i = 0; i < model.Colors.Count; i++) //{ // ProductColor productColor = new ProductColor(); // productColor.ProductId = product.Id; // productColor.ColorId = model.Colors[i]; // db.ProductColors.Add(productColor); //} //#endregion #region Product Photo Add for (int i = 0; i < model.Photos.Count; i++) { ProductPhoto productPhoto = new ProductPhoto(); productPhoto.Product = product; productPhoto.PhotoPath = model.Photos[i]; db.ProductPhotos.Add(productPhoto); } #endregion db.SaveChanges(); HttpContext.Session.SetString("productId", product.Id.ToString()); return(RedirectToAction(nameof(Index))); } else { ModelState.AddModelError("", "Category or Subcategory not selected"); return(RedirectToAction(nameof(Add))); } } else { ModelState.AddModelError("", "Make sure that you fill all required blanks!"); return(RedirectToAction(nameof(Add))); } } else { ModelState.AddModelError("", "Make sure that you fill all required blanks!"); return(RedirectToAction(nameof(Add))); } }
public static string ToCulture(System.DateTime?time, ProductLanguage destinationCulture) { return(ToCulture(time, destinationCulture.CultureId)); }
public static bool Load(string productUrlName, string cultureId, ApplicationProduct product, Int64?userId) { bool res = false; string query = "CatalogLoad"; using (SqlConnection cnn = new SqlConnection(Configurations.ConnectionString)) { using (SqlCommand cmd = new SqlCommand(query, cnn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@UrlName", productUrlName)); cmd.Parameters.Add(new SqlParameter("@CultureId", cultureId)); cmd.Parameters.Add(new SqlParameter("@UserId", userId)); foreach (SqlParameter Parameter in cmd.Parameters) { if (Parameter.Value == null) { Parameter.Value = DBNull.Value; } } cnn.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader != null && reader.HasRows) { // Read first table: SoftwareProduct if (reader.Read()) { product.ProductId = Repository.Utils.Convert.ToInt64(reader[0]); product.ProductWebsite = Repository.Utils.Convert.ToString(reader[1]); product.ProductVersion = Repository.Utils.Convert.ToString(reader[2]); product.ProductReleaseDate = Repository.Utils.Convert.ToDateTime(reader[3]); product.Price = Repository.Utils.Convert.ToDecimal(reader[4]); product.MinimumVolumeSize = Repository.Utils.Convert.ToFloat(reader[5]); product.MultiUser = Repository.Utils.Convert.ToBool(reader[6]); product.MultiLanguage = Repository.Utils.Convert.ToBool(reader[7]); product.LanguageExtendable = Repository.Utils.Convert.ToBool(reader[8]); } // Read next table: Details reader.NextResult(); while (reader.Read()) { product.ProductName = Repository.Utils.Convert.ToString(reader[0]); product.BriefDescription = Repository.Utils.Convert.ToString(reader[1]); product.PriceDetails = Repository.Utils.Convert.ToString(reader[2]); product.GuarantyDetails = Repository.Utils.Convert.ToString(reader[3]); } // Read next table: Brands reader.NextResult(); while (reader.Read()) { ProductBrand brand = new ProductBrand(); //brand.BrandId = ; brand.BrandName = Utils.Convert.ToString(reader[0]); product.Brands.Add(brand); } // Read next table: Catalog reader.NextResult(); if (reader.Read()) { product.Catalog.SearchPriority = Repository.Utils.Convert.ToInt32(reader[0]); product.Catalog.UserRating = Repository.Utils.Convert.ToDecimal(reader[1]); product.Catalog.EditorRating = Repository.Utils.Convert.ToDecimal(reader[2]); product.Catalog.UrlName = Repository.Utils.Convert.ToString(reader[3]); product.Catalog.ViewsCount = Repository.Utils.Convert.ToInt32(reader[4]); product.Catalog.UpdateDate = Repository.Utils.Convert.ToDateTime(reader[5]); product.Catalog.InsertDate = Repository.Utils.Convert.ToDateTime(reader[6]); } // UNDONE: // Read next table: Categories reader.NextResult(); // Read next table: Contacts reader.NextResult(); while (reader.Read()) { ProductContact contact = new ProductContact(); ContactUnit unit = new ContactUnit(); ContactMediaType media = new ContactMediaType(); contact.Unit = unit; contact.MediaType = media; contact.Id = Repository.Utils.Convert.ToInt64(reader[0]); unit.Id = Repository.Utils.Convert.ToInt32(reader[1]); unit.Name = Repository.Utils.Convert.ToString(reader[2]); contact.ContactValue = Repository.Utils.Convert.ToString(reader[3]); contact.ContactPerson = Repository.Utils.Convert.ToString(reader[4]); media.Id = Repository.Utils.Convert.ToInt32(reader[5]); media.Name = Repository.Utils.Convert.ToString(reader[6]); product.ProductContacts.Add(contact); } // Read next table: Customization reader.NextResult(); while (reader.Read()) { ProductCustomizationOption customize = new ProductCustomizationOption(); customize.Id = Repository.Utils.Convert.ToInt32(reader[0]); customize.Name = Repository.Utils.Convert.ToString(reader[1]); product.CustomizationOptions.Add(customize); } // Read next table: Backup reader.NextResult(); while (reader.Read()) { ProductDataBackupOption backup = new ProductDataBackupOption(); backup.Id = Repository.Utils.Convert.ToInt32(reader[0]); backup.Name = Repository.Utils.Convert.ToString(reader[1]);; product.BackupOptions.Add(backup); } // Read next table: Demo reader.NextResult(); while (reader.Read()) { ProductDemoOption demo = new ProductDemoOption(); demo.Id = Repository.Utils.Convert.ToInt32(reader[0]); demo.Name = Repository.Utils.Convert.ToString(reader[1]);; product.DemoOptions.Add(demo); } // Read next table: Environment reader.NextResult(); while (reader.Read()) { ProductEnvironmentOption env = new ProductEnvironmentOption(); env.Id = Repository.Utils.Convert.ToInt32(reader[0]); env.Name = Repository.Utils.Convert.ToString(reader[1]);; product.EnvironmentOptions.Add(env); } // Read next table: Extension reader.NextResult(); while (reader.Read()) { ProductExtensionOptions ext = new ProductExtensionOptions(); ext.Id = Repository.Utils.Convert.ToInt32(reader[0]); ext.Name = Repository.Utils.Convert.ToString(reader[1]);; product.ExtensionOptions.Add(ext); } // Read next table: Guaranty reader.NextResult(); while (reader.Read()) { ProductGuarantyOption guaranty = new ProductGuarantyOption(); guaranty.Id = Repository.Utils.Convert.ToInt32(reader[0]); guaranty.Name = Repository.Utils.Convert.ToString(reader[1]); product.GuarantyOptions.Add(guaranty); } // Read next table: Requirements reader.NextResult(); while (reader.Read()) { product.HardwareRequirements.Add(Repository.Utils.Convert.ToString(reader[1])); } // Read next table: Installation reader.NextResult(); while (reader.Read()) { ProductInstallationOption inst = new ProductInstallationOption(); inst.Id = Repository.Utils.Convert.ToInt32(reader[0]); inst.Name = Repository.Utils.Convert.ToString(reader[1]); product.InstallationOptions.Add(inst); } // Read next table: Languages reader.NextResult(); while (reader.Read()) { ProductLanguage lang = new ProductLanguage(); lang.Id = Repository.Utils.Convert.ToInt32(reader[0]); lang.Name = Repository.Utils.Convert.ToString(reader[1]); product.SupportedLanguages.Add(lang); } // Read next table: Payment reader.NextResult(); while (reader.Read()) { ProductPaymentOption payment = new ProductPaymentOption(); payment.Id = Repository.Utils.Convert.ToInt32(reader[0]); payment.Name = Repository.Utils.Convert.ToString(reader[1]); product.PaymentOptions.Add(payment); } // Read next table: SoftwarePlatforms reader.NextResult(); while (reader.Read()) { SoftwarePlatform platform = new SoftwarePlatform(); platform.Id = Repository.Utils.Convert.ToInt32(reader[0]); platform.Name = Repository.Utils.Convert.ToString(reader[1]); product.SupportedPlatforms.Add(platform); } // Read next table: Publish reader.NextResult(); while (reader.Read()) { ProductPublishOption publish = new ProductPublishOption(); publish.Id = Repository.Utils.Convert.ToInt32(reader[0]); publish.Name = Repository.Utils.Convert.ToString(reader[1]); product.PublishOptions.Add(publish); } // Read next table: Source reader.NextResult(); while (reader.Read()) { ProductSourceOption source = new ProductSourceOption(); source.Id = Repository.Utils.Convert.ToInt32(reader[0]); source.Name = Repository.Utils.Convert.ToString(reader[1]); product.SourceOptions.Add(source); } // Read next table: Support reader.NextResult(); while (reader.Read()) { ProductSupportOption support = new ProductSupportOption(); support.Id = Repository.Utils.Convert.ToInt32(reader[0]); support.Name = Repository.Utils.Convert.ToString(reader[1]); product.SupportOptions.Add(support); } // Read next table: SupportTypes reader.NextResult(); while (reader.Read()) { ProductSupportType type = new ProductSupportType(); type.Id = Repository.Utils.Convert.ToInt32(reader[0]); type.Name = Repository.Utils.Convert.ToString(reader[1]); product.SupportTypes.Add(type); } // Read next table: Tags reader.NextResult(); while (reader.Read()) { ProductTag tag = new ProductTag(); tag.Id = Repository.Utils.Convert.ToInt32(reader[0]); tag.Name = Repository.Utils.Convert.ToString(reader[1]); product.Tags.Add(tag); } // Read next table: Technologies reader.NextResult(); while (reader.Read()) { ProductTechnology tech = new ProductTechnology(); tech.Id = Repository.Utils.Convert.ToInt32(reader[0]); tech.Name = Repository.Utils.Convert.ToString(reader[1]); product.ProductTechnologies.Add(tech); } // Read next table: Update reader.NextResult(); while (reader.Read()) { ProductUpdateOption update = new ProductUpdateOption(); update.Id = Repository.Utils.Convert.ToInt32(reader[0]); update.Name = Repository.Utils.Convert.ToString(reader[1]); product.UpdateOptions.Add(update); } // Read next table: Update reader.NextResult(); if (reader.Read()) { product.Article.Content = Repository.Utils.Convert.ToString(reader[0]); } // Read next table: VoteCounts reader.NextResult(); if (reader.Read()) { product.Catalog.VoteCounts = Repository.Utils.Convert.ToInt32(reader[0]); } // Read next table: User vote reader.NextResult(); if (reader.Read()) { product.Catalog.CurrentUserRating = Repository.Utils.Convert.ToInt32(reader[0]); } res = true; } cnn.Close(); } } return(res); }