public List <view_ProductMobileApp> SearchViewProductMongo( int?Sort = 1, int PIndex = 1, int PSize = 20, string searchKey = "", int?BizTypeID = 0, int CateLevel = 0, int CategoryID = 0, int?Complevel = 0, int ProvinceID = 0) { var keywords = SearchProductMongo(Sort, PIndex, PSize, searchKey, BizTypeID, CateLevel, CategoryID, Complevel, ProvinceID); var products = new List <view_ProductMobileApp>(); foreach (var item in keywords) { Mapper.CreateMap <Models.tbProduct, view_ProductMobileApp>(); view_ProductMobileApp model = Mapper.Map <Models.tbProduct, view_ProductMobileApp>(item); products.Add(model); } return(products); }
public ActionResult SearchProduct( int?Sort = 1, int PIndex = 1, int PSize = 20, string searchKey = "", int?BizTypeID = 0, int CateLevel = 0, int CategoryID = 0, int?Complevel = 0, int ProvinceID = 0) { var mgKeyword = new KeywordMongo(); var keywords = mgKeyword.SearchProductMongo(Sort, PIndex, PSize, searchKey, BizTypeID, CateLevel, CategoryID, Complevel, ProvinceID); var products = new List <view_ProductMobileApp>(); foreach (var item in keywords) { Mapper.CreateMap <Models.tbProduct, view_ProductMobileApp>(); view_ProductMobileApp model = Mapper.Map <Models.tbProduct, view_ProductMobileApp>(item); products.Add(model); } return(Json(new { totalrow = mgKeyword.TotalRow, products = products }, JsonRequestBehavior.AllowGet)); }
public bool SaveKeywordMongo(view_ProductMobileApp model, string ProvinceName = "") { var products = new List <tbProduct>(); var isResult = false; var database = server.GetDatabase("dbb2bthai"); var collection = database.GetCollection <tbProduct>("tbProduct"); try { if (model != null && model.ProductID > 0) { #region Set Keyword var product = new tbProduct(); product = GetProductMongoById((int)model.ProductID); if (product != null && product.ProductID > 0) { var query = Query <tbProduct> .EQ(e => e.ProductID, model.ProductID); #region Edit product.ProductName = model.ProductName; product.ProductID = model.ProductID; product.ProductGroupID = model.ProductGroupID; product.ShortDescription = model.ShortDescription; product.CateLV1 = (int)model.CateLV1; product.CateLV2 = (int)model.CateLV2; product.CateLV3 = (int)model.CateLV3; product.ListNo = (int)model.ListNo; product.Price = (decimal)model.Price; product.Qty = (decimal)model.Qty; product.QtyUnit = model.QtyUnit; product.ProductImgPath = model.ProductImgPath; product.ContactMobile = model.ContactMobile; product.ServiceType = (int)model.ServiceType; product.CompID = (int)model.CompID; product.CompName = model.CompName; product.Complevel = (int)model.Complevel; product.CompProvinceID = (int)model.CompProvinceID; product.ProvinceName = ProvinceName; product.CompDistrictID = (int)model.CompDistrictID; product.BizTypeID = (int)model.BizTypeID; product.BizTypeOther = model.BizTypeOther; product.CreatedDate = model.CreatedDate; product.RowFlag = model.RowFlag; product.ModifiedDate = model.ModifiedDate; product.ViewCount = (short)model.ViewCount; product.ContactCount = (short)model.ContactCount; product.IsSME = false; product.IsDelete = false; product.Keyword = new List <string>(); SetProductKeyword(product.Keyword, model.ProductName); SetProductKeyword(product.Keyword, model.ProductKeyword); #endregion collection.Save(product); isResult = true; } else { #region Insert product = new tbProduct(); product.Keyword = new List <string>(); product.ProductName = model.ProductName; product.ProductID = model.ProductID; product.ProductGroupID = model.ProductGroupID; product.ProductName = model.ProductName; product.ProductKeyword = model.ProductKeyword; product.ShortDescription = model.ShortDescription; product.CateLV1 = (int)model.CateLV1; product.CateLV2 = (int)model.CateLV2; product.CateLV3 = (int)model.CateLV3; product.Price = (decimal)model.Price; product.Qty = (decimal)model.Qty; product.QtyUnit = model.QtyUnit; product.ProductImgPath = model.ProductImgPath; product.ContactMobile = model.ContactMobile; product.ServiceType = (int)model.ServiceType; product.CompID = (int)model.CompID; product.CompName = model.CompName; product.Complevel = (int)model.Complevel; product.CompProvinceID = (int)model.CompProvinceID; product.ProvinceName = ProvinceName; product.CompDistrictID = (int)model.CompDistrictID; product.BizTypeID = (int)model.BizTypeID; product.BizTypeOther = model.BizTypeOther; product.CreatedDate = model.CreatedDate; product.RowFlag = model.RowFlag; product.ModifiedDate = model.ModifiedDate; product.ViewCount = (short)model.ViewCount; product.ContactCount = (short)model.ContactCount; product.IsSME = false; product.IsDelete = false; SetProductKeyword(product.Keyword, model.ProductName); SetProductKeyword(product.Keyword, model.ProductKeyword); #endregion collection.Insert(product); isResult = true; } #endregion } } catch (Exception ex) { isResult = false; throw; } return(isResult); }