public string Delete_Product(ProductParam product) { string status; using (var transaction = context.Database.BeginTransaction()) { try { var del = context.Product.Where(o => o.IdProduct == product.IdProduct).SingleOrDefault(); if (del != null) { context.Product.Remove(del); context.SaveChanges(); status = constant.SUCCEES; } else { status = constant.NULL; } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); status = constant.ERROR; } } return(status); }
public IActionResult Get_Edit_Product(ProductParam modelParam) // done { ProductAddandEditViewModel model = repository_product.Get_Edit_Product(modelParam); model.getUnit = repository_product.Get_Unit(); return(Json(model)); }
public ActionResult <string> AddProduct([FromBody] ProductParam product) { try { var db = new ShowcaseDatabase.ShowcaseDatabase(); var newProduct = new Product { ProductName = product.ProductName, Price = product.Price, Description = product.Description, CompanyId = product.CompanyId, Count = product.Count, CategoryId = product.CategoryId }; db.Products.Add(newProduct); db.SaveChanges(); return(Ok(new { newProduct.Id })); } catch (Exception e) { Console.WriteLine(e); return(_apiError.ServerError); } }
public async Task <IActionResult> AddProductAsync(ProductParam productParam) { bool isProductParamInserted = false; try { ProductBusiness productBusiness = new ProductBusiness(); if (productParam != null) { productBusiness = mapper.Map <ProductBusiness>(productParam); isProductParamInserted = await productService.AddProductAsync(productBusiness); } if (isProductParamInserted == true) { return(Ok()); } else { return(StatusCode(400)); } } catch (Exception) { return(StatusCode(500)); } }
public ActionResult <string> UpdateProduct(int id, [FromBody] ProductParam productParam) { try { var db = new ShowcaseDatabase.ShowcaseDatabase(); var product = db.Products.FirstOrDefault(p => p.Id == id); if (product == null) { return(_apiError.ProductNotFound); } product.ProductName = productParam.ProductName ?? product.ProductName; product.Price = productParam.Price <= 0 ? product.Price : productParam.Price; product.Description = productParam.Description ?? product.Description; product.Count = productParam.Count < 0 ? product.Count : productParam.Count; product.CompanyId = productParam.CompanyId <= 0 ? product.CompanyId : productParam.CompanyId; product.CategoryId = productParam.CategoryId <= 0 ? product.CategoryId : productParam.CategoryId; db.SaveChanges(); return(Ok(new { Message = "Продукт успешно обновлён" })); } catch (Exception e) { Console.WriteLine(e); return(_apiError.ServerError); } }
public void ProcessPurchase(string productIdentifier) { if (m_ProductParamMap.ContainsKey(productIdentifier)) { ProductParam productParam = m_ProductParamMap[productIdentifier]; switch (productParam.m_ProductType) { case InAppProductList.ProductType.COIN: GameData.Instance.m_Coin += productParam.m_nProductParam; Debug.Log(string.Format("InAppProcessor::ProcessPurchase: PASS. Product: '{0}'", productIdentifier)); // @todo Some feedback break; case InAppProductList.ProductType.AVATAR: GemLibrary.GemSet gemType = (GemLibrary.GemSet)productParam.m_nProductParam; /* * if ( !GameData.Instance.m_Sets.Contains( gemType ) ) * { * GameData.Instance.m_Sets.Add( gemType ); * GameData.Instance.m_GemList.Add( gemType ); * } */ GameData.Instance.UnlockGem(gemType); Debug.Log(string.Format("InAppProcessor::ProcessPurchase: PASS. Product: '{0}'", productIdentifier)); // Enable item screen controls GameObject shopManager = GameObject.FindGameObjectWithTag("Shop Manager"); ShopManager sm = shopManager.GetComponent <ShopManager>(); sm.EnableItemScreenControl(true); // Some feedback //GemLibrary gemLibrary = GameObject.Find( "Gem Library" ).GetComponent<GemLibrary>(); GemLibrary gemLibrary = GemLibrary.Instance; GemContainerSet gemSet = gemLibrary.GemsSetList[productParam.m_nProductParam]; GameObject explosion = ( GameObject )Instantiate(gemSet.m_Explosion, sm.GetCurrentItemIcon().transform.position, Quaternion.identity); explosion.layer = LayerMask.NameToLayer("UI Particles"); ParticleSystem ps = explosion.GetComponent <ParticleSystem>(); ps.GetComponent <Renderer>().sortingLayerName = "UI Particles"; ps.GetComponent <Renderer>().sortingOrder = LayerMask.NameToLayer("UI Particles"); Destroy(explosion, ps.duration + ps.startLifetime + Time.deltaTime); break; default: Debug.Log(string.Format("InAppProcessor::ProcessPurchase: FAIL. Invalid product type: '{0}'", productParam.m_ProductType.ToString())); return; } SaveLoad.Save(); } else { Debug.Log(string.Format("InAppProcessor::ProcessPurchase: FAIL. Unrecognized product: '{0}'", productIdentifier)); } }
public void ProcessPurchaseFail(string productIdentifier) { if (m_ProductParamMap.ContainsKey(productIdentifier)) { ProductParam productParam = m_ProductParamMap[productIdentifier]; switch (productParam.m_ProductType) { case InAppProductList.ProductType.COIN: Debug.Log(string.Format("InAppProcessor::ProcessPurchase: FAIL. Product: '{0}'", productIdentifier)); break; case InAppProductList.ProductType.AVATAR: Debug.Log(string.Format("InAppProcessor::ProcessPurchase: FAIL. Product: '{0}'", productIdentifier)); // Enable item screen controls GameObject shopManager = GameObject.FindGameObjectWithTag("Shop Manager"); ShopManager sm = shopManager.GetComponent <ShopManager>(); sm.EnableItemScreenControl(true); break; default: Debug.Log(string.Format("InAppProcessor::ProcessPurchase: FAIL. Invalid product type: '{0}'", productParam.m_ProductType.ToString())); return; } SaveLoad.Save(); } else { Debug.Log(string.Format("InAppProcessor::ProcessPurchase: FAIL. Unrecognized product: '{0}'", productIdentifier)); } }
public IActionResult Delete_Product([FromQuery] ProductParam model) // done { string status; status = repository_product.Delete_Product(model); return(Json(status)); }
public IActionResult Check_Edit_Product([FromBody] ProductParam model) // done { string status; status = repository_product.Check_Product(model); return(Json(status)); }
public async Task <IActionResult> GetProducts([FromQuery] ProductParam productParam) { var products = await _repo.GetProducts(productParam); var productToReturn = _mapper.Map <IEnumerable <ProductDto> >(products); return(Ok(productToReturn)); }
public ActionResult Put(int id, [FromBody] ProductParam product) { var item = new AdminProduct(); item.Id = id; item.ImgUrl = "/uploadpic/product/" + product.ImgURL; item.EditorState = product.EditorState; item.Name =product.Name; item.Price = Convert.ToDecimal(product.Price); item.OnSale = Convert.ToBoolean(product.OnSale); var obj = _productB.ModifyProduct(item); return Ok(obj); }
public async Task <IActionResult> Search([FromBody] ProductParam param) { Func <ProductView, bool> where = e => true; if (!string.IsNullOrEmpty(param.Name)) { where += p => p.Name.Contains(param.Name); } if (!string.IsNullOrEmpty(param.Code)) { where += p => p.Code.Contains(param.Code); } var result = _products.Where(where).Skip((param.PageIndex - 1) * param.PageSize).Take(param.PageSize).ToList(); return(await Task.FromResult(Json(new { total = _products.Count(where), rows = result }))); }
private ProductParam GetProductMaster(string productId) { using (List <ProductParam> .Enumerator enumerator = this.ProductMasters.GetEnumerator()) { while (enumerator.MoveNext()) { ProductParam current = enumerator.Current; if (productId == current.ProductId) { return(current); } } } return((ProductParam)null); }
public string Check_Product(ProductParam model) { string status; var edit = context.Product.Where(o => o.IdProduct == model.IdProduct).SingleOrDefault(); if (edit != null) { status = constant.SUCCEES; } else { status = constant.NULL; } return(status); }
public ProductAddandEditViewModel Get_Edit_Product(ProductParam modelParam) { IQueryable <ProductAddandEditViewModel> result = from a in context.Product where a.IdProduct == modelParam.IdProduct join b in context.Unit on a.IdUnit equals b.IdUnit select new ProductAddandEditViewModel { IdUnit = a.IdUnit, IdProduct = a.IdProduct, NameUnit = b.NameUnit, NameProduct = a.ProductName, ProductPrice = a.ProductPrice }; ProductAddandEditViewModel data = result.SingleOrDefault(); return(data); }
/// <summary> /// 以下方法只是演示,如果具体使用的话需要各种提取和拆分,以便复用,和以后扩展维护 /// </summary> /// <param name="productParam"></param> /// <returns></returns> public PageList <Product> LoadProducts(ProductParam productParam) { //Func<Product,bool> conditionFunc=new Func<Product, bool>(n=>n.) //如果用EF 且使用过ISpecification 的朋友对以下方法肯定很熟悉---ISpecification 可以把条件全部提出,方便重用和以后维护。不过在这里有点多此一举 var conditionFunc = new Func <IEnumerable <Product>, IEnumerable <Product> >( products => { products = string.IsNullOrWhiteSpace(productParam.KeyWord) ? products : products.Where(n => n.Name.Contains(productParam.KeyWord)); #region 针对时间的搜索也可以做统一处理, 这里仅是演示 //对结束时间做处理 if (null != productParam.EndTime) { productParam.EndTime = productParam.EndTime.Value.AddDays(1).AddMilliseconds(-1); products = products.Where(n => n.CreateTime <= productParam.EndTime); } products = null != productParam.StartTime ? products.Where(n => n.CreateTime >= productParam.StartTime) : products; #endregion #region 以下排序和分页应该做统一处理 if (!string.IsNullOrWhiteSpace(productParam.sort)) { //我这里只是实现了功能,EF在具体使用的时候要多字段动态指定排序这里需要操作Expression表达式树 products = products.OrderBy(productParam.sort, productParam.order != "asc"); } return(products.Skip((productParam.page - 1) * productParam.rows).Take(productParam.rows)); #endregion }); return(new PageList <Product>() { Items = conditionFunc(_products).ToList(), PageIndex = productParam.page, PageSize = productParam.rows, TotalCount = _products.Count }); }
public bool Update(int?Id, ProductParam productParam) { var result = 0; Product getProduct = Get(Id); getProduct.Name = productParam.Name; getProduct.Variety = productParam.Variety; getProduct.Description = productParam.Description; getProduct.Image = productParam.Image; getProduct.Price = productParam.Price; getProduct.Restaurants = myContext.Restaurants.Find(productParam.Restaurants_Id); getProduct.UpdateDate = DateTimeOffset.Now.LocalDateTime; result = myContext.SaveChanges(); if (result > 0) { status = true; } return(status); }
public IHttpActionResult GetInstallProductById([FromBody] ProductParam productParam) { string message = string.Empty; using (var productRepository = new ProductRepository(productParam.userId)) { ResponseSingleModel <ProductInstallDetails> result = null; if (productParam.productId > 0) { result = productRepository.GetInstallProductById(productParam.DtlproductId, productParam.productId, productParam.vehicleId); } else { log.Info("Product id is grater than zero"); return(Ok(new { Constants.WebApiStatusFail, data = "Product id is grater than zero" })); } return(Ok(new { result.Status, data = result.Message })); } }
public ActionResult Create([FromBody] ProductParam product) { var item = new AdminProduct(); item.EditorState = product.EditorState; item.OnSale = product.OnSale; item.Name = product.Name; item.Price = Convert.ToDecimal(product.Price); item.ImgUrl = "/uploadpic/product/" + product.ImgURL; try { var obj = _productB.CreateProduct(item); return Ok(obj); } catch (Exception ex) { throw ex; /*throw new Exception("exception happening");*/ } }
public bool Insert(ProductParam productParam) { var result = 0; product.Name = productParam.Name; product.Variety = productParam.Variety; product.Description = productParam.Description; product.Image = productParam.Image; product.Price = productParam.Price; product.Restaurants = myContext.Restaurants.Find(productParam.Restaurants_Id); product.CreateDate = DateTimeOffset.Now.LocalDateTime; product.IsDelete = false; myContext.Products.Add(product); result = myContext.SaveChanges(); if (result > 0) { status = true; } return(status); }
public void ProcessPurchaseFailed(string productIdentifier) { if (m_ProductParamMap.ContainsKey(productIdentifier)) { ProductParam productParam = m_ProductParamMap[productIdentifier]; switch (productParam.m_ProductType) { case InAppProductList.ProductType.COIN: Debug.Log(string.Format("InAppProcessor::ProcessPurchase: FAIL. Product: '{0}'", productIdentifier)); break; case InAppProductList.ProductType.AVATAR: Debug.Log(string.Format("InAppProcessor::ProcessPurchase: FAIL. Product: '{0}'", productIdentifier)); GameObject go = GameObject.FindGameObjectWithTag("Gacha"); GachaScript gacha = go.GetComponent <GachaScript>(); gacha.EnableBuyUI(true); break; case InAppProductList.ProductType.ADS: Debug.Log(string.Format("InAppProcessor::ProcessPurchase: FAIL. Product: '{0}'", productIdentifier)); MainMenuScript mainMenu = Camera.main.GetComponent <MainMenuScript>(); mainMenu.EnableDisableAdsButton(true); break; default: Debug.Log(string.Format("InAppProcessor::ProcessPurchase: FAIL. Invalid product type: '{0}'", productParam.m_ProductType.ToString())); return; } SaveLoad.Save(); } else { Debug.Log(string.Format("InAppProcessor::ProcessPurchase: FAIL. Unrecognized product: '{0}'", productIdentifier)); } }
public async Task <IEnumerable <Product> > GetProducts(ProductParam productParam) { var products = await _context.Products.Include(i => i.ProductImages).ToListAsync(); if (productParam.ProductName != null) { var prodFilter = _context.Products.Where(p => p.Name == productParam.ProductName); return(prodFilter); } if (!productParam.PriceHigh) { var prodprice = _context.Products.OrderBy(p => p.Price); return(prodprice); } if (productParam.PriceHigh) { var prodprice = _context.Products.OrderBy(p => p.Price).Reverse(); return(prodprice); } return(products); }
public JsonResult LoadTest1(ProductParam modelParam) { return(new JsonDataGridResult(Repository.LoadProducts(modelParam))); }
// PUT: api/Products/5 public void Put(int id, ProductParam productParam) { _productService.Update(id, productParam); }
public bool Insert(ProductParam productParam) { _productRepository.Insert(productParam); return(status = true); }
// POST: api/Products public void Post(ProductParam productParam) { _productService.Insert(productParam); }
public override void Reset() { productParam = ProductParam.Name; productName = null; productId = null; }
public bool Update(int?Id, ProductParam productParam) { _productRepository.Update(Id, productParam); return(status = true); }
public void ProcessPurchase(string productIdentifier) { if (m_ProductParamMap.ContainsKey(productIdentifier)) { ProductParam productParam = m_ProductParamMap[productIdentifier]; switch (productParam.m_ProductType) { case InAppProductList.ProductType.COIN: GameData.current.coin += productParam.m_nProductParam; Debug.Log(string.Format("InAppProcessor::ProcessPurchase: PASS. Product: '{0}'", productIdentifier)); // @todo Some feedback break; case InAppProductList.ProductType.AVATAR: Debug.Log(string.Format("InAppProcessor::ProcessPurchase: PASS. Product: '{0}'", productIdentifier)); GameObject go = GameObject.FindGameObjectWithTag("Gacha"); GachaScript gacha = go.GetComponent <GachaScript>(); gacha.ProcessBuyIcon(productParam.m_nProductParam); Analytics.CustomEvent("Bought_Tac", new Dictionary <string, object> { { ((Defines.ICONS)productParam.m_nProductParam).ToString().Substring(0, 4), 1 } }); break; case InAppProductList.ProductType.ADS: Defines.AdsInAppPurchase adsProductParam = (Defines.AdsInAppPurchase)productParam.m_nProductParam; switch (adsProductParam) { case Defines.AdsInAppPurchase.DISABLE: Debug.Log(string.Format("InAppProcessor::ProcessPurchase: PASS. Product: '{0}'", productIdentifier)); Adverts.Instance.RemoveAds(); // Disable disable ads button MainMenuScript mainMenu = Camera.main.GetComponent <MainMenuScript>(); mainMenu.EnableDisableAdsButton(true); mainMenu.DisableDisableAdsButton(); Analytics.CustomEvent("Bought_Ads", new Dictionary <string, object> { }); break; default: Debug.Log(string.Format("InAppProcessor::ProcessPurchase: FAIL. Unrecognized Ads Product Params: '{0}'", productIdentifier)); break; } break; default: Debug.Log(string.Format("InAppProcessor::ProcessPurchase: FAIL. Invalid product type: '{0}'", productParam.m_ProductType.ToString())); return; } SaveLoad.Save(); } else { Debug.Log(string.Format("InAppProcessor::ProcessPurchase: FAIL. Unrecognized product: '{0}'", productIdentifier)); } }