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); } }
public SellerProductModel GetProductAndMapToSellerProductModel(int?productid) { var productModel = new SellerProductModel(); var product = GetProduct(productid); if (product != null) { productModel.ProductId = product.ProductID; productModel.Name = product.Name; productModel.Edi = product.EDI; productModel.Sku = product.SKU; productModel.Year = product.Year; productModel.Material = product.Material; productModel.Size = product.Size; productModel.SeasonId = product.SeasonID; productModel.GenderId = product.GenderID; productModel.CategoryId = product.CategoryID; if (product.CollectionID != null) { productModel.CollectionId = (int)product.CollectionID; } productModel.BrandId = product.BrandID; } return(productModel); }
public SellerViewModel GetSellerInfo(long?sellerID) { SellerViewModel sellermodel = new SellerViewModel(); using (ShopDevEntities db = new ShopDevEntities()) { try { var sellerInfo = db.Sellers.Where(m => m.SellerID == sellerID).FirstOrDefault(); var lstproducts = db.SellerProducts.Where(m => m.SellerID == sellerID).ToList(); var AllInstallments = db.SellerInstallments.Where(m => m.SellerID == sellerID).ToList(); SellerModel bbModel = new SellerModel(); sellerInfo.CopyProperties(bbModel); List <SellerProductModel> lstcsproducts = new List <SellerProductModel>(); foreach (var cusprod in lstproducts) { SellerProductModel objcsproduct = new SellerProductModel(); cusprod.CopyProperties(objcsproduct); lstcsproducts.Add(objcsproduct); } List <SellerInstallmentModel> lstInstallments = new List <SellerInstallmentModel>(); foreach (var cusprod in AllInstallments) { SellerInstallmentModel objcsproduct = new SellerInstallmentModel(); cusprod.CopyProperties(objcsproduct); lstInstallments.Add(objcsproduct); } sellermodel.sellerInfor = bbModel; sellermodel.productInfo = new SellerProductModel(); sellermodel.Lstproducts = new List <SellerProductModel>(); sellermodel.Lstproducts.AddRange(lstcsproducts); sellermodel.Installments = new SellerInstallmentModel(); sellermodel.LstInstallments = new List <SellerInstallmentModel>(); sellermodel.LstInstallments.AddRange(lstInstallments); } catch (Exception) { } } return(sellermodel); }
public ActionResult SaveProduct(SellerProductModel productModel) { var successMessage = MessageIdEnum.NewProductSuccess; var failureMessage = MessageIdEnum.NewProductFailure; if (productModel.ProductId > 0) { successMessage = MessageIdEnum.EditProductSuccess; failureMessage = MessageIdEnum.EditProductFailure; } if (ModelState.IsValid) { if (_objectRepository.SaveProduct(productModel, WebSecurity.GetUserId(User.Identity.Name))) { TempData["Message"] = successMessage; return(RedirectToAction("Products", "Seller")); } } // If we got this far, something failed, display failure message TempData["Message"] = failureMessage; return(RedirectToAction("Products", "Seller")); }
public List <SellerProductModel> AddSellerProduct(SellerProductModel productModel) { List <SellerProductModel> lstcsproducts = new List <SellerProductModel>(); using (ShopDevEntities db = new ShopDevEntities()) { try { productModel.SellerID = productModel.SellerID == null ? 0 : productModel.SellerID; SellerProduct buyerproduct = null; int? oldunit = 0; if (productModel.SellerProductID > 0) { buyerproduct = db.SellerProducts.Where(m => m.SellerProductID == productModel.SellerProductID).FirstOrDefault(); oldunit = buyerproduct.Unit == null?0: buyerproduct.Unit; var diffUnit = oldunit - productModel.Unit; var product = db.Products.Where(m => m.CategoryID == productModel.CategoryID && m.ProductName == productModel.ProductName && m.CategoryID == productModel.CategoryID).FirstOrDefault(); if (product != null) { product.Unit += diffUnit; } } else { buyerproduct = new SellerProduct(); } productModel.CopyProperties(buyerproduct); if (productModel.SellerProductID == 0) { db.SellerProducts.Add(buyerproduct); if (productModel.SellerID > 0) { var oldproduct = db.Products.Where(m => m.ProductName == productModel.ProductName && m.Type == productModel.Type && m.CategoryID == productModel.CategoryID).FirstOrDefault(); if (oldproduct != null) { oldproduct.Unit += productModel.Unit; } else { Product prod = new Product(); prod.ProductName = productModel.ProductName; prod.ProdDesc = productModel.Description; prod.Type = productModel.Type; prod.CategoryID = productModel.CategoryID; prod.Unit = productModel.Unit; prod.IsActive = true; db.Products.Add(prod); } } } db.SaveChanges(); var lstproducts = db.SellerProducts.Where(m => m.SellerID == productModel.SellerID).ToList(); foreach (var cusprod in lstproducts) { SellerProductModel objcsproduct = new SellerProductModel(); cusprod.CopyProperties(objcsproduct); lstcsproducts.Add(objcsproduct); } return(lstcsproducts); } catch (Exception) { return(lstcsproducts); } } }
public bool SaveProduct(SellerProductModel product, int userid) { var saveSucceeded = false; try { Product tmpProduct; using (var db = new Entities()) { if (product.ProductId > 0) { tmpProduct = db.Products.SingleOrDefault(i => i.ProductID == product.ProductId); if (tmpProduct != null) { tmpProduct.Name = product.Name; tmpProduct.EDI = product.Edi; tmpProduct.SKU = product.Sku; tmpProduct.Year = product.Year; tmpProduct.Material = product.Material; tmpProduct.Size = product.Size; tmpProduct.BrandID = product.BrandId; tmpProduct.CategoryID = product.CategoryId; tmpProduct.CollectionID = product.CollectionId; tmpProduct.GenderID = product.GenderId; tmpProduct.SeasonID = product.SeasonId; tmpProduct.updated = DateTime.Now; tmpProduct.UserID = userid; } } else { tmpProduct = new Product { Name = product.Name, EDI = product.Edi, SKU = product.Sku, Year = product.Year, Material = product.Material, Size = product.Size, BrandID = product.BrandId, CategoryID = product.CategoryId, CollectionID = product.CollectionId, GenderID = product.GenderId, SeasonID = product.SeasonId, created = DateTime.Now, updated = DateTime.Now, UserID = userid }; db.Products.Add(tmpProduct); } db.SaveChanges(); } _luceneWorker.AddUpdateLuceneIndex(Thread.CurrentThread.CurrentCulture.ThreeLetterISOLanguageName, tmpProduct); saveSucceeded = true; } catch (Exception ex) { Logger.ErrorFormat("SaveProduct - error [{0}] - - \r\n {1} \r\n\r\n", ex.Message, ex.StackTrace); } return(saveSucceeded); }