public List <SellerProductModel> DeleteSellerProduct(long Id, long sellerID) { List <SellerProductModel> lstbulkproducts = new List <SellerProductModel>(); using (ShopDevEntities db = new ShopDevEntities()) { try { SellerProduct product = GetProduct(db, Id); db.SellerProducts.Remove(product); db.SaveChanges(); var lstproducts = db.SellerProducts.Where(m => m.SellerID == sellerID).ToList(); foreach (var cusprod in lstproducts) { SellerProductModel objcsproducts = new SellerProductModel(); cusprod.CopyProperties(objcsproducts); lstbulkproducts.Add(objcsproducts); } } catch (Exception) { } return(lstbulkproducts); } }
private void UpdateProductSellers(string[] selectedSellers, Product productToUpdate) { if (selectedSellers == null) { productToUpdate.SellerProducts = new List <SellerProduct>(); return; } var selectedSellersHS = new HashSet <string>(selectedSellers); var productSellers = new HashSet <int> (productToUpdate.SellerProducts.Select(c => c.Seller.Id)); foreach (var seller in _context.Sellers) { if (selectedSellersHS.Contains(seller.Id.ToString())) { if (!productSellers.Contains(seller.Id)) { productToUpdate.SellerProducts.Add(new SellerProduct { ProductId = productToUpdate.Id, SellerId = seller.Id }); } } else { if (productSellers.Contains(seller.Id)) { SellerProduct sellerToRemove = productToUpdate.SellerProducts.FirstOrDefault(i => i.SellerId == seller.Id); _context.Remove(sellerToRemove); } } } }
public async Task DeleteAsync(SellerProduct parameters) { var SellerProduct = Uow.Repository <SellerProduct>().FindByKey(parameters.SellerProductId); await Uow.RegisterDeletedAsync(SellerProduct); await Uow.CommitAsync(); }
public JsonResult Create(Guid productId) { try { if (productId != null) { var userId = User.Identity.GetUserId(); var exist = db.SellerProducts.Any(x => x.UserId == userId && x.OwnerProductId == productId); if (!exist) { var newSellerProduct = new SellerProduct(); { newSellerProduct.OwnerProductId = productId; newSellerProduct.UserId = userId; } db.SellerProducts.Add(newSellerProduct); db.SaveChanges(); } } return(Json(true)); } catch { return(Json(false)); } }
private async Task LoadImages(IEnumerable <string> pictureUrls, SellerProduct item, List <byte[]> imageHashes) { const int ImageLoadCount = 6; using (var client = new HttpClient()) { var getTasks = pictureUrls.Take(ImageLoadCount).Select(x => client.GetByteArrayAsync(x)); var imagesData = await Task.WhenAll(getTasks); var productImages = imagesData.Select(x => new ProductImage() { ImageData = x, Item = item }); using (MD5 md5 = MD5.Create()) { foreach (var img in productImages) { var hash = md5.ComputeHash(img.ImageData); if (!imageHashes.Any(x => x.SequenceEqual(hash))) { _imageRepo.Add(img); imageHashes.Add(hash); } } } } if (pictureUrls.Count() > imageHashes.Count) { await LoadImages(pictureUrls.Skip(ImageLoadCount), item, imageHashes); } }
public SellerProductViewModel(SellerProduct dbModel) { this.Id = dbModel.Id; this.UserId = dbModel.UserId; this.OwnerProductId = dbModel.OwnerProductId; this.OwnerProduct = new OwnerProductViewModel(dbModel.OwnerProduct); }
public static string GetAllMessages() { SellerDTO Sellerinfo = new SellerDTO(); iSellerProduct ISellerdetails = new SellerProduct(); var ck = HttpContext.Current.Request.Cookies["Info"].Value; string output = ck.Substring(ck.IndexOf('=') + 1); Sellerinfo.userName = output; DataSet _getProductInfo = ISellerdetails._GetAllMessages(Sellerinfo); return JsonConvert.SerializeObject(_getProductInfo); }
public ResultDto Add(RequestAddSellerProductDto request) { #region Validate Enteries if (request.CatId == 0) { return(new ResultDto() { IsSuccess = false, Message = "!دسته بندی را انتخاب نمایید", }); } if (request.ProductId == 0) { return(new ResultDto() { IsSuccess = false, Message = "!محصول را انتخاب نمایید", }); } if (request.Inventory == 0) { return(new ResultDto() { IsSuccess = false, Message = "!تعداد موجودی را وارد نمایید", }); } if (request.SellerPrice == 0) { return(new ResultDto() { IsSuccess = false, Message = "!قیمت محصول را نمایید", }); } #endregion SellerProduct _selllerproduct = new SellerProduct() { Inventory = request.Inventory, ProductId = request.ProductId, SellerId = _context.Sellers.SingleOrDefault(s => s.UserId == request.SellerId.ToString() && s.CategoryId == request.CatId).Id, SellerPrice = request.SellerPrice, }; _context.SellerProducts.Add(_selllerproduct); _context.SaveChanges(); return(new ResultDto { IsSuccess = true, Message = "کالا با موفقیت به لیست فروشگاه شمااضافه شد", }); }
public static string GetAllMessages() { SellerDTO Sellerinfo = new SellerDTO(); iSellerProduct ISellerdetails = new SellerProduct(); var ck = HttpContext.Current.Request.Cookies["Info"].Value; string output = ck.Substring(ck.IndexOf('=') + 1); Sellerinfo.userName = output; DataSet _getProductInfo = ISellerdetails._GetAllMessages(Sellerinfo); return(JsonConvert.SerializeObject(_getProductInfo)); }
public ActionResult Edit([Bind(Include = "Id,UserId,OwnerProductId")] SellerProduct sellerProduct) { if (ModelState.IsValid) { db.Entry(sellerProduct).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.OwnerProductId = new SelectList(db.OwnerProducts, "Id", "UserId", sellerProduct.OwnerProductId); ViewBag.UserId = User.Identity.GetUserId(); return(View(sellerProduct)); }
public async Task <IActionResult> Create([Bind("Name,Info,Specification,Rating,SubcategoryId")] Product product, string[] selectedSellers) { /*if (ModelState.IsValid) * { * _context.Add(product); * await _context.SaveChangesAsync(); * return RedirectToAction(nameof(Index)); * } * ViewData["SubcategoryId"] = new SelectList(_context.Set<Subcategory>(), "Id", "Name", product.SubcategoryId); * return View(product);*/ if (selectedSellers != null) { product.SellerProducts = new List <SellerProduct>(); foreach (var seller in selectedSellers) { var sellerToAdd = new SellerProduct { ProductId = product.Id, SellerId = int.Parse(seller) }; product.SellerProducts.Add(sellerToAdd); } } try { if (ModelState.IsValid) { var products = _context.Products.Where(p => p.Name == product.Name).Where(p => p.Info == product.Info).Where(p => p.Specification == product.Specification).FirstOrDefault(); if (products != null) { ModelState.AddModelError(string.Empty, "This product already exists"); return(RedirectToAction("Create", "Products", new { subcategoryId = product.SubcategoryId })); } else { _context.Add(product); await _context.SaveChangesAsync(); //return RedirectToAction(nameof(Index)); return(RedirectToAction("Index", "Products", new { Id = product.SubcategoryId, name = _context.Subcategories.Where(c => c.Id == product.SubcategoryId).FirstOrDefault().Name })); } } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } //return View(product); PopulateAssignedSellerData(product); return(RedirectToAction("Index", "Products", new { Id = product.SubcategoryId, name = _context.Subcategories.Where(c => c.Id == product.SubcategoryId).FirstOrDefault().Name })); }
public SellerProduct GetProduct(ShopDevEntities db, long Id) { SellerProduct objProduct = null; try { objProduct = db.SellerProducts.Where(m => m.SellerProductID == Id).FirstOrDefault(); } catch (Exception) { } return(objProduct); }
// GET: SellerProducts/Details/5 public ActionResult Details(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SellerProduct sellerProduct = db.SellerProducts.Find(id); if (sellerProduct == null) { return(HttpNotFound()); } return(View(sellerProduct)); }
public ResultDto Edit(RequestEditSellerProductDto request) { SellerProduct Sp = _context.SellerProducts.SingleOrDefault(s => s.Id == request.Id); Sp.Inventory = request.Inventory; Sp.SellerPrice = request.SellerPrice; _context.SaveChanges(); return(new ResultDto { IsSuccess = true, Message = "عمیات ویرایش با موفقیت انجام شد", }); }
public async Task Execute(string userName) { var seller = await _sellerRepo.Find(userName); var listedItems = await _ebayFindingService.FindItemsAdvanced(userName); List <string> processed = new List <string>(); foreach (var itemInfo in listedItems) { if (!processed.Contains(itemInfo.ItemId) && !await _itemRepo.Exists(itemInfo.ItemId)) { var item = await _ebayTradingService.GetItem(itemInfo.ItemId); string pictureUrls = null; if (item.PictureURLs?.Any() ?? false) { pictureUrls = string.Join(Environment.NewLine, item.PictureURLs); } var product = new SellerProduct() { Country = itemInfo.Country, EbayBuyItNowPrice = item.EbayBuyItNowPrice, EbayDescription = itemInfo.EbayDescription, EbayLongDescription = item.EbayDescription, ItemId = item.ItemId, EbayItemLocation = itemInfo.EbayItemLocation, EbayItemPictureDetails = pictureUrls, EbayViewItemUrl = itemInfo.EbayViewItemUrl, SKU = item.SKU, UserId = seller.Id, CrossboarderTrade = item.CrossboarderTrade, }; _itemRepo.Add(product); processed.Add(item.ItemId); if (item.PictureURLs?.Any() ?? false) { var imageHashes = new List <byte[]>(); await LoadImages(item.PictureURLs, product, imageHashes); } await _uow.SaveEntitiesAsync(); } } //return new ReviewsResultDto //{ // Escalated = processed.Count, // Total = seller.Total + processed.Count //}; }
public async Task <Unit> Handle(AddProductToSellerCommand request, CancellationToken cancellationToken) { var product = await _productRepository.GetAsync(x => x.Sku == request.Sku); if (product is null) { throw new ProductNotFoundException(); } var sellerProduct = new SellerProduct(request.SellerCode, product.ProductName, request.Qty, product.CategoryName, request.Pricing, product.Unit, product.Sku); await _sellerProductRepository.AddAsync(sellerProduct, cancellationToken); return(Unit.Task.Result); }
// GET: SellerProducts/Edit/5 public ActionResult Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SellerProduct sellerProduct = db.SellerProducts.Find(id); if (sellerProduct == null) { return(HttpNotFound()); } ViewBag.OwnerProductId = new SelectList(db.OwnerProducts, "Id", "UserId", sellerProduct.OwnerProductId); ViewBag.UserId = User.Identity.GetUserId(); return(View(sellerProduct)); }
public SellerProduct EditSellerProduct(SellerProduct currentSellerProduct, int?count = null, int?price = null, Product product = null) { if (count <= 0 && price <= 0) { return(null); } var newSellerProduct = new SellerProduct { Id = currentSellerProduct.Id, Product = product ?? currentSellerProduct.Product, Count = count ?? currentSellerProduct.Count, Price = price ?? currentSellerProduct.Price }; context.SellerProducts.Update(newSellerProduct); context.SaveChanges(); return(newSellerProduct); }
public SellerProduct AddSellerProduct(Product product, Seller seller, int count, int price) { if (count <= 0 && price <= 0) { return(null); } var newSellerProduct = new SellerProduct { Product = product, Seller = seller, Count = count, Price = price }; context.SellerProducts.Add(newSellerProduct); context.SaveChanges(); return(newSellerProduct); }
public OwnerProductViewModel(SellerProduct dbModel) { this.Id = dbModel.Id; this.UserId = dbModel.UserId; this.Name = dbModel.OwnerProduct.Name; this.Price = dbModel.OwnerProduct.Price; this.Quantity = dbModel.OwnerProduct.Quantity; this.Margin = dbModel.OwnerProduct.Margin; this.Description = dbModel.OwnerProduct.Description; this.UserName = dbModel.User.UserName; if (dbModel.OwnerProduct.OwnerProductImages != null && dbModel.OwnerProduct.OwnerProductImages.Count > 0) { this.ProfileImagePath = dbModel.OwnerProduct.OwnerProductImages.FirstOrDefault().Path; } else { this.ProfileImagePath = "/Imgs/diaochan.jpg"; } }
public async Task <IActionResult> Create([Bind("Name,Adress,Rating")] Seller seller, string[] selectedProducts) { /*if (ModelState.IsValid) * { * _context.Add(seller); * await _context.SaveChangesAsync(); * return RedirectToAction(nameof(Index)); * } * return View(seller);*/ if (selectedProducts != null) { seller.SellerProducts = new List <SellerProduct>(); foreach (var product in selectedProducts) { var productToAdd = new SellerProduct { SellerId = seller.Id, ProductId = int.Parse(product) }; seller.SellerProducts.Add(productToAdd); } } if (ModelState.IsValid) { var sellers = _context.Sellers.Where(s => s.Name == seller.Name).Where(s => s.Rating == seller.Rating).Where(s => s.Adress == seller.Adress).FirstOrDefault(); if (sellers != null) { ModelState.AddModelError(string.Empty, "This seller already exists"); //return View(seller); } else { _context.Add(seller); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } PopulateAssignedProductData(seller); return(View(seller)); }
public SellerProduct AddSellerProduct(Product product, Seller seller, int count, int price, string desc, string name) { if (count <= 0 || price <= 0 || desc == null || desc == string.Empty) { return(null); } var newSellerProduct = new SellerProduct { ProductId = product.Id, SellerId = seller.Id, Count = count, Price = price, Description = desc, Name = name }; context.SellerProducts.Add(newSellerProduct); context.SaveChanges(); return(newSellerProduct); }
public HashSet <string> DeleteValidation(SellerProduct parameters) { return(ValidationMessages); }
public async Task UpdateAsync(SellerProduct entity) { await Uow.RegisterDirtyAsync(entity); await Uow.CommitAsync(); }
public HashSet <string> UpdateValidation(SellerProduct entity) { return(ValidationMessages); }
public async Task AddAsync(SellerProduct entity) { await Uow.RegisterNewAsync(entity); await Uow.CommitAsync(); }
public async Task <object> GetBy(SellerProduct parameters) { return(await Uow.Repository <SellerProduct>().FindByAsync(t => t.SellerProductId == parameters.SellerProductId)); }
public async Task <object> GetAsync(SellerProduct parameters) { return(await Uow.Repository <SellerProduct>().AllAsync()); }
public void Add(SellerProduct item) { _context.SellerProducts.Add(item); }
public async Task <IActionResult> Import(IFormFile fileExcel, int categoryId) { List <S> errors = new List <S>(); int h = 0; string FieldErrors = ""; string ValueError = ""; Category category = _context.Categories.Find(categoryId); if (ModelState.IsValid) { try { if (fileExcel.FileName == "" || fileExcel.FileName == null || fileExcel.FileName == string.Empty) { throw new NullReferenceException(); } if (!fileExcel.FileName.Contains(".xlsx")) { throw new FileFormatException(); } if (fileExcel != null) { using (var stream = new FileStream(fileExcel.FileName, FileMode.Create)) { await fileExcel.CopyToAsync(stream); using (XLWorkbook workBook = new XLWorkbook(stream, XLEventTracking.Disabled)) { //перегляд усіх листів (в даному випадку категорій) foreach (IXLWorksheet worksheet in workBook.Worksheets) { errors.Add(new S { worksheet = worksheet.Name, lines = new List <int>() }); //worksheet.Name - назва категорії. Пробуємо знайти в БД, якщо відсутня, то створюємо нову Subcategory newsubcat; if (!CountRu(worksheet.Name)) { FieldErrors += "Error in " + worksheet.Name + " worksheet; "; h++; continue; } string worksheetName = worksheet.Name.ToLower(); var s = (from subcat in _context.Subcategories where subcat.Name.ToLower().Contains(worksheetName) select subcat).ToList(); if (s.Count > 0) { newsubcat = s[0]; } else { newsubcat = new Subcategory(); newsubcat.Name = worksheet.Name; newsubcat.CategoryId = categoryId; _context.Subcategories.Add(newsubcat); } if (worksheet.Row(1).Cell(1).Value.ToString() != "Name") { FieldErrors += "Error in " + worksheet.Name + " worksheet; "; h++; continue; } if (worksheet.Row(1).Cell(2).Value.ToString() != "Info") { FieldErrors += "Error in " + worksheet.Name + " worksheet; "; h++; continue; } if (worksheet.Row(1).Cell(3).Value.ToString() != "Specification") { FieldErrors += "Error in " + worksheet.Name + " worksheet; "; h++; continue; } if (worksheet.Row(1).Cell(4).Value.ToString() != "Rating") { FieldErrors += "Error in " + worksheet.Name + " worksheet; "; h++; continue; } int l = 5; try { while (true) { string cell = worksheet.Row(1).Cell(l).Value.ToString(); if (cell == null || cell == "" || cell == string.Empty) { break; } if (!cell.Contains("Seller") && !cell.Contains("seller")) { throw new ArgumentException(); } l++; } } catch (ArgumentException a) { FieldErrors += "Error in " + worksheetName + " worksheet; "; h++; continue; } //перегляд усіх рядків foreach (IXLRow row in worksheet.RowsUsed().Skip(1)) { try { Product product = new Product(); product.Name = row.Cell(1).Value.ToString(); if (!CountRu(product.Name)) { throw new Exception(); } product.Info = row.Cell(2).Value.ToString(); product.Specification = row.Cell(3).Value.ToString(); if (Convert.ToDouble(row.Cell(4).Value) > 10 || Convert.ToDouble(row.Cell(4).Value) < 0) { throw new Exception(); } product.Rating = Convert.ToDouble(row.Cell(4).Value); product.Subcategory = newsubcat; if (product.Name == null || product.Specification == null || product.Rating == null) { throw new Exception(); } string name = product.Name.ToLower(); //string Name = Char.ToUpper(name[0]) + name.Substring(1); Product p = _context.Products.Where(p => p.Name.ToLower() == name).FirstOrDefault(); if (p != null) { p.Info = product.Info; p.Specification = product.Specification; p.Rating = product.Rating; p.Subcategory = product.Subcategory; for (int i = 5; i <= l; i++) { if (row.Cell(i).Value.ToString().Length > 0) { Seller seller; var a = (from aut in _context.Sellers where aut.Name.ToLower().Contains(row.Cell(i).Value.ToString().ToLower()) select aut).ToList(); if (a.Count > 0) { seller = a[0]; var selpr = (from o in _context.SellerProducts where o.ProductId == p.Id && o.SellerId == seller.Id select o).ToList(); if (selpr.Count > 0) { continue; } SellerProduct sp = new SellerProduct(); sp.Product = p; sp.Seller = seller; _context.SellerProducts.Add(sp); } else { seller = new Seller(); seller.Name = row.Cell(i).Value.ToString(); seller.Adress = "FromExcel"; if (!CountRu(seller.Name)) { errors[h].lines.Add(row.RowNumber()); continue; } //додати в контекст _context.Add(seller); SellerProduct sp = new SellerProduct(); sp.Product = p; sp.Seller = seller; _context.SellerProducts.Add(sp); } } } _context.Update(p); } else { _context.Products.Add(product); for (int i = 5; i <= l; i++) { if (row.Cell(i).Value.ToString().Length > 0) { Seller seller; var a = (from aut in _context.Sellers where aut.Name.ToLower().Contains(row.Cell(i).Value.ToString().ToLower()) select aut).ToList(); if (a.Count > 0) { seller = a[0]; } else { seller = new Seller(); seller.Name = row.Cell(i).Value.ToString(); seller.Adress = "FromExcel"; if (!CountRu(seller.Name)) { errors[h].lines.Add(row.RowNumber()); continue; } //throw new Exception(); _context.Add(seller); } SellerProduct sp = new SellerProduct(); sp.Product = product; sp.Seller = seller; _context.SellerProducts.Add(sp); } } } } catch (Exception e) { errors[h].lines.Add(row.RowNumber()); } } h++; } } } } } catch (FileFormatException) { return(RedirectToAction("Index", "Subcategories", new { name = category.Name, Id = categoryId, formatError = "Incorrect File Format" })); } catch (NullReferenceException) { return(RedirectToAction("Index", "Subcategories", new { name = category.Name, Id = categoryId, formatError = "Error! Choose file" })); } await _context.SaveChangesAsync(); } foreach (var e in errors) { if (e.lines.Count() == 0) { continue; } ValueError += e.worksheet + ": "; foreach (var line in e.lines) { ValueError += "line " + line.ToString() + "; "; } } return(RedirectToAction("Index", "Subcategories", new { name = category.Name, Id = categoryId, fieldError = FieldErrors, valueError = ValueError })); }
//HitlineContext context public static void Initialize(IdentityContext context) { context.Database.EnsureCreated(); // Look for any students. if (context.Products.Any()) { return; // DB has been seeded } var categories = new Category[] { new Category { Name = "Category 1" }, new Category { Name = "Category 2" } }; foreach (Category category in categories) { context.Categories.Add(category); } context.SaveChanges(); var subcategories = new Subcategory[] { new Subcategory { Name = "Subcategory 1", CategoryId = categories.Single(s => s.Name == "Category 1").Id }, new Subcategory { Name = "Subcategory 2", CategoryId = categories.Single(s => s.Name == "Category 1").Id } }; foreach (Subcategory subcategory in subcategories) { context.Subcategories.Add(subcategory); } context.SaveChanges(); var products = new Product[] { new Product { Name = "Iphone", Info = "info 1", Specification = "specif 1", Rating = 0, SubcategoryId = subcategories.Single(s => s.Name == "Subcategory 1").Id }, new Product { Name = "GalaxyS20", Info = "info 2", Specification = "specif 2", Rating = 0, SubcategoryId = subcategories.Single(s => s.Name == "Subcategory 1").Id }, new Product { Name = "Xiaomi", Info = "info 3", Specification = "specif 3", Rating = 0, SubcategoryId = subcategories.Single(s => s.Name == "Subcategory 1").Id }, new Product { Name = "Ipad", Info = "info 4", Specification = "specif 4", Rating = 0, SubcategoryId = subcategories.Single(s => s.Name == "Subcategory 2").Id }, new Product { Name = "Airpods", Info = "info 5", Specification = "specif 5", Rating = 0, SubcategoryId = subcategories.Single(s => s.Name == "Subcategory 2").Id } }; foreach (Product s in products) { context.Products.Add(s); } context.SaveChanges(); var sellers = new Seller[] { new Seller { Name = "Citrus", Adress = "afafaf", Rating = 7 }, new Seller { Name = "Allo", Adress = "agssgsg", Rating = 5 }, new Seller { Name = "Rozetka", Adress = "hddhhd", Rating = 10 } }; foreach (Seller c in sellers) { context.Sellers.Add(c); } context.SaveChanges(); var sellerProducts = new SellerProduct[] { new SellerProduct { ProductId = products.Single(s => s.Name == "Iphone").Id, SellerId = sellers.Single(s => s.Name == "Citrus").Id, }, new SellerProduct { ProductId = products.Single(s => s.Name == "Iphone").Id, SellerId = sellers.Single(s => s.Name == "Allo").Id, }, new SellerProduct { ProductId = products.Single(s => s.Name == "Xiaomi").Id, SellerId = sellers.Single(s => s.Name == "Citrus").Id, }, new SellerProduct { ProductId = products.Single(s => s.Name == "GalaxyS20").Id, SellerId = sellers.Single(s => s.Name == "Rozetka").Id, }, new SellerProduct { ProductId = products.Single(s => s.Name == "Iphone").Id, SellerId = sellers.Single(s => s.Name == "Rozetka").Id, } }; foreach (SellerProduct sp in sellerProducts) { var sellerProductInDataBase = context.SellerProducts.Where( s => s.Product.Id == sp.ProductId && s.Seller.Id == sp.SellerId).SingleOrDefault(); if (sellerProductInDataBase == null) { context.SellerProducts.Add(sp); } } context.SaveChanges(); }