public bool UpdatePricesByCategoryId(PriceUpdateDTO priceUpdate) { bool result = false; var queryParameters = new DynamicParameters(); queryParameters.Add("@CategoryId", priceUpdate.CategoryId); queryParameters.Add("@PercentageValue", (double)priceUpdate.PercentageValue / 100); using SqlConnection connection = new SqlConnection( _connectionString); int affectedRows = 0; switch (priceUpdate.PriceUpdateType) { case Domain.Enums.PriceUpdateType.Adjustment: affectedRows = connection.Execute(ProductScripts.INCREASE_PRICES, queryParameters); break; case Domain.Enums.PriceUpdateType.Discount: affectedRows = connection.Execute(ProductScripts.REDUCE_PRICES, queryParameters); break; default: break; } if (affectedRows > 0) { result = true; } return(result); }
public ActionResult <Price> PutPrice(int GSid, int Pid, PriceUpdateDTO price) { var foundPrice = _repository.GetPriceById(GSid, Pid); if (foundPrice == null) { return(NotFound()); } else if (price.A95Price == 0 || price.A98Price == 0 || price.DPrice == 0 || price.DzPrice == 0 || price.GasPrice == 0) { return(BadRequest()); } else { var priceMapped = _mapper.Map <Price>(price); try { _repository.PutPrice(GSid, Pid, priceMapped); } catch (Exception) { return(NotFound()); } foundPrice = _repository.GetPriceById(GSid, Pid); return(Ok(_mapper.Map <PriceReadDTO>(foundPrice))); } }
public ActionResult Put(PriceUpdateDTO priceUpdate) { try { if (_productRepository.UpdatePricesByCategoryId(priceUpdate)) { return(Ok(new { Message = "Products prices successfully updated!" })); } else { return(NotFound(new { Mensagem = "Product not found!" })); } } catch (Exception ex) { return(BadRequest(new { ex.Message })); } }
public ActionResult PutPrice(int GSid, PriceUpdateDTO price) { return(BadRequest()); }