public void SimpleUpdateProduct(ProductRequest request) { try { Product currentProduct = GetProductById(request.ProductId); currentProduct.Description = request.Description; currentProduct.Factory = request.Factory; currentProduct.Price = request.Price; currentProduct.Eliminated = false; currentProduct.ProductName = request.ProductName; productRepository.UpdateEntity(currentProduct); } catch (RepositoryException e) { throw new OperationException(e.Message, e); } }
public override async Task <ProductResponse> RemoveProduct(ProductRequest request, ServerCallContext context) { if (!Guid.TryParse(request.Product.Id, out Guid id)) { throw new ArgumentException($"invalid product id {request.Product.Id}"); } var response = new ProductResponse(); var product = await this.repo.RemoveProductAsync(id); if (product != null) { response.Products.Add(request.Product); } return(response); }
// GET: ProductRequests/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductRequest productRequest = db.ProductRequests.Find(id); if (productRequest == null) { return(HttpNotFound()); } ViewBag.ProductID = new SelectList(db.Products, "ID", "ProductName", productRequest.ProductID); ViewBag.RequesterID = new SelectList(db.Requesters, "ID", "Name", productRequest.RequesterID); return(View(productRequest)); }
public IActionResult Add(ProductRequest product) { if (ModelState.IsValid) { Product newProduct = new Product() { Name = product.Name, Description = product.Description, Pictures = PictureListToCollection(product), }; userProductService.AddProduct(newProduct, GetCurrentUserId()); return(RedirectToAction(nameof(Index))); } return(View(product)); }
static async Task Main(string[] args) { var productId = args != null && args.Length > 0 && int.TryParse(args[0], out int value) ? value : 1; var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new ProductsService.ProductsServiceClient(channel); var request = new ProductRequest() { Id = productId }; var result = await client.GetProductByIdAsync(request); Console.WriteLine($"{result.Id} {result.Name} {result.Price} {result.IsAvailable} {result.Category}"); Console.ReadKey(); }
public void GetProductsDescriptionExactMatchTest() { var orderService = new OrderService(); var request = new ProductRequest { TextFilter = "Xbox One Controller" }; var response = orderService.GetProducts(request); Assert.IsTrue(response.Success, response.Message); Assert.IsNotNull(response.Value, "Response's Value should not be null"); Assert.AreEqual(1, response.Value.Count, "Expected 1 record"); }
public void GetProductsCodeTest() { var orderService = new OrderService(); var request = new ProductRequest { TextFilter = "XB" }; var response = orderService.GetProducts(request); Assert.IsTrue(response.Success, response.Message); Assert.IsNotNull(response.Value, "Response's Value should not be null"); Assert.AreEqual(2, response.Value.Count, "Expected 2 records"); }
public ProductResponse InsertProduct(ProductRequest productRequest) { ProductResponse productResponse = new ProductResponse(); try { IproductR.InsertProduct(productRequest.product); productResponse.Success = true; } catch (Exception e) { productResponse.Exception = e; productResponse.Success = false; } return(productResponse); }
public virtual ProductResponse GetProductList(ProductRequest request) { try { var url = string.Format(_urlTemplate, request.Keyword); var doc = _web.Load(url); var result = MapDocumentToProduct(doc); result.Keyword = request.Keyword; return(result); } catch (Exception ex) { } return(null); }
public async Task <BaseResponseDto <List <ProductDto> > > Handle(ProductRequest request, CancellationToken cancellationToken) { var response = new BaseResponseDto <List <ProductDto> >(new List <ProductDto>()); var allProduct = await _repository.ListAllAsync(); foreach (var product in allProduct) { response.Data.Add(new ProductDto() { Price = product.Price, Name = product.Name }); } return(response); }
public IActionResult Post([FromBody] ProductRequest product) { if (product == null) { return(BadRequest("There is no product information to handle")); } var productSaved = _productService.Save(product); if (productSaved == null) { return(BadRequest(_productService.GetErrorMessages())); } return(Created(".", productSaved)); }
public void ApproveRequest(Guid requestId) { Guard.ArgNotEmpty(requestId, nameof(requestId)); IIdentity requestIdentity = requestId.ToIdentity(); ProductRequest productRequest = requestRepository.GetEntityById(requestIdentity); if (productRequest == null) { throw new Exception("Product request not found"); } productRequest.Approve(); requestRepository.Update(productRequest); }
public void GetProductsBasicTest() { var orderService = new OrderService(); var request = new ProductRequest { TextFilter = null }; var response = orderService.GetProducts(request); Assert.IsTrue(response.Success, response.Message); Assert.IsNotNull(response.Value, "Response's Value should not be null"); Assert.IsTrue(response.Value.Count >= 3, "At least 3 products should have been returned"); }
private Product ToProduct(ProductRequest request) { return(new Product { Category = request.Category, CategoryId = request.CategoryId, Description = request.Description, Image = request.Image, IsActive = request.IsActive, LastPurchase = request.LastPurchase, Price = request.Price, ProductId = request.ProductId, Remarks = request.Remarks, Stock = request.Stock, }); }
public void UpdateProductPresenter() { ProductRequest productRequest = new ProductRequest(); productRequest.product = _view.Product; ProductResponse productResponse = productService.UpdateProduct(productRequest); if (productResponse.Success) { _view.SuccessUpdate("Se actualizo"); } else { _view.ErrorUpdate(string.Format("{0}", productResponse.Exception.Message)); } }
public Shop AddProduct(Guid id, ProductRequest request) { var shop = _dbcontext.Shops.FirstOrDefault(x => x.Id == id); var product = _mapper.Map <Product>(request); if (shop.Products == null) { shop.Products = new List <Product>(); } shop.Products.Add(product); _dbcontext.SaveChanges(); return(shop); }
public ProductResponse Delete([FromBody] ProductRequest productRequest) { if (productRequest.aut.userName != "bulut" || productRequest.aut.password != "123") { return(new ProductResponse { status = new Status() { code = Enums.MessageCode.Basarisiz, message = "Erişim Engellendi!" } }); } else { try { productService.Delete(new Entity.Models.Product { CategoryId = productRequest.product.CategoryId, ProductName = productRequest.product.ProductName, Price = productRequest.product.Price, PriceVat = productRequest.product.PriceVat }); return(new ProductResponse { status = new Status() { code = Enums.MessageCode.Basarili, message = "Başarılı!" } }); } catch (Exception e) { return(new ProductResponse { status = new Status() { code = Enums.MessageCode.Basarisiz, message = e.Message } }); } } }
public async Task <ActionResult <Product> > UpdateProduct(int id, [FromForm] ProductRequest productRequest) { if (id != productRequest.ProductId) { return(BadRequest()); } var product = await productservice.GetProductByID(id); if (product == null) { return(NotFound()); } productRequest.Adapt(product); await productservice.Update(product); return(NoContent()); }
public void ShouldReturnBadRequestWhenExceptionOccurs() { const string EXCEPTION_MESSAGE = "Exception Message"; var statusCodeExpected = (int)HttpStatusCode.InternalServerError; var product = new ProductRequest(); var productService = new Mock <IProductService>(MockBehavior.Strict); productService .Setup(ps => ps.Update(It.IsAny <ProductRequest>())) .Throws(new Exception(EXCEPTION_MESSAGE)); var productController = new ProductController(productService.Object); var response = productController.Put(product); response.As <ObjectResult>().StatusCode.Should().Be(statusCodeExpected); response.As <ObjectResult>().Value.Should().BeEquivalentTo(new { error = EXCEPTION_MESSAGE }); }
/// <summary> /// Gets list of products. /// </summary> /// <param name="criterion"></param> /// <returns></returns> public List <Product> GetList(Criterion criterion = null) { var request = new ProductRequest().Prepare(); request.LoadOptions = new string[] { "Products" }; request.Criteria = new ProductCriteria { CategoryId = int.Parse(criterion.Filters.Single(f => f.Attribute == "CategoryId").Operand.ToString()), SortExpression = criterion.OrderByExpression }; var response = Client.GetProducts(request); Correlate(request, response); return(response.Products == null ? null : response.Products.ToList()); }
public async Task <IActionResult> Post(ProductRequest request) { try { Product product = _mapper.Map(request); product = await _repository.AddAsync(product); return(CreatedAtAction(nameof(GetById), new { id = product.Id }, _mapper.Map(product))); } catch (DataStoreException e) { _logger.LogError(e.Message, e, request); return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public async Task <Product> addAsync(ProductRequest entity) { string sql = "exec [AddProduct] @ProductName, @Description, @RetailPrice, @CreateDate, @LastModified"; using (SqlConnection db = new SqlConnection(_configuration.GetConnectionString("DefaultConnection"))) { await db.OpenAsync(); int rowsModified = await db.ExecuteAsync(sql, entity); string getProduct = "SELECT * FROM Product WHERE Id=(SELECT max(Id) FROM Product)"; var products = await db.QueryAsync <Product>(getProduct, entity); return(products.FirstOrDefault()); } }
public IActionResult Post(ProductRequest productRequest) { var product = createManager.Create( productRequest.Description, productRequest.Name, productRequest.FriendlyName, productRequest.Price, productRequest.Tax, productRequest.InitialStock, productRequest.TaxDescription); return(CreatedAtAction( nameof(ProductsGetController.GetById), nameof(ProductsGetController).Replace("Controller", ""), new { productId = product.Id }, product)); }
public async Task FindAllProducts() { Console.WriteLine("***** Task FindAllProducts *****"); using (var call = _client.FindAllProducts(new Empty())) { int i = 1; while (await call.ResponseStream.MoveNext()) { Console.WriteLine("***** Task FindAllProducts Iteration " + i + " *****"); ProductRequest product = call.ResponseStream.Current; Console.WriteLine(i + " Received; Product: " + product.ToString()); Console.WriteLine("***** Iteration " + i + " done *****"); i++; } } Console.WriteLine("***** Task End *****"); }
public LacesResponse RemoveProduct(ProductRequest request) { LacesResponse response = new LacesResponse(); try { if (request.SecurityString == ConfigurationManager.AppSettings[Constants.APP_SETTING_SECURITY_TOKEN]) { LacesDataModel.Product.Product product = new LacesDataModel.Product.Product(request.ProductId); product.ProductStatusId = (int)ProductStatusOptions.Removed; if (product.Update()) { response.Success = true; response.Message = "Product succesfully removed."; } else { response.Success = false; response.Message = "An error occurred when communicating with the database."; } } else { response.Success = false; response.Message = "Invalid security token."; } } catch (Exception ex) { response = new LacesResponse(); response.Success = false; if (ex.Message.Contains("find product")) { response.Message = ex.Message; } else { response.Message = "An unexpected error has occurred; please verify the format of your request."; } } return(response); }
private void DeleteImageFileIO(List <int> ids) { var request = new ProductRequest { IDs = ids }; var products = this.ImsService.GetProductList(request); foreach (Product product in products) { if (!string.IsNullOrEmpty(product.CoverPicture)) { string CoverPath = Path.Combine(System.Web.HttpContext.Current.Server.MapPath(product.CoverPicture)); if (System.IO.File.Exists(CoverPath)) { System.IO.File.Delete(CoverPath); } string thumNailCoverPath = Path.Combine(System.Web.HttpContext.Current.Server.MapPath(product.CoverPicture.Replace(".", "_s."))); if (System.IO.File.Exists(thumNailCoverPath)) { System.IO.File.Delete(thumNailCoverPath); } } if (product.Images != null) { foreach (Image image in product.Images) { string filePath = Path.Combine(System.Web.HttpContext.Current.Server.MapPath(image.PictureURL)); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } string thumNailfilePath = Path.Combine(System.Web.HttpContext.Current.Server.MapPath(image.PictureURL.Replace(".", "_s."))); if (System.IO.File.Exists(thumNailfilePath)) { System.IO.File.Delete(thumNailfilePath); } } } } }
public ProductsResponse GetProductList(ProductRequest request) { var product = new ProductsResponse(); try { using (var bus = RabbitHutch.CreateBus(_rmqConnectionString)) { product = bus.Rpc.Request <ProductRequest, ProductsResponse>(request); } } catch (Exception ex) { // log exception here } return(product); }
private List <string> ValidateName(ProductRequest product) { var NameRegex = new Regex(@"^[a-zA-Z]+$"); if (string.IsNullOrWhiteSpace(product.Name)) { product.Errors.Add("Product name is required!"); return(product.Errors); } if (!NameRegex.IsMatch(product.Name)) { product.Errors.Add("Product name is not correct."); } return(product.Errors); }
public JsonResult CreateOrEditNewProduct(ProductModel productRequest) { if (Session["UserLogon"] != null) { productRequest.Account = (AccountModel)Session["UserLogon"]; } var request = new ProductRequest { Data = productRequest }; ProductResponse _response = new ProductResponse(); new ProductValidator(_unitOfWork).Validate(request, out _response); return(Json(new { data = _response.Entity }, JsonRequestBehavior.AllowGet)); }
public IList <Product> GetProducts(int categoryId, string sortExpression) { var request = new ProductRequest().Prepare(); request.LoadOptions = new string[] { "Products" }; request.Criteria = new ProductCriteria { CategoryId = categoryId, SortExpression = sortExpression }; var response = Client.GetProducts(request); Correlate(request, response); return(response.Products); }
/// <summary> /// Searches for products. /// </summary> /// <param name="productName">Product name.</param> /// <param name="priceRangeId">Price range identifier.</param> /// <param name="sortExpression">Sort order in which products are returned.</param> /// <returns>List of products that meet the search criteria.</returns> public IList<Product> SearchProducts(string productName, int priceRangeId, string sortExpression) { ProductRequest request = new ProductRequest(); request.RequestId = NewRequestId; request.AccessToken = AccessToken; request.ClientTag = ClientTag; request.LoadOptions = new string[] { "Products", "Search" }; double priceFrom = -1; double priceThru = -1; if (priceRangeId > 0) { PriceRangeItem pri = PriceRange.List[priceRangeId]; priceFrom = pri.RangeFrom; priceThru = pri.RangeThru; } request.Criteria = new ProductCriteria { ProductName = productName, PriceFrom = priceFrom, PriceThru = priceThru, SortExpression = sortExpression }; ProductResponse response = ActionServiceClient.GetProducts(request); if (request.RequestId != response.CorrelationId) throw new ApplicationException("SearchProducts: Request and CorrelationId do not match."); return response.Products; }
public IList<Product> GetProducts(int categoryId, string sortExpression) { ProductRequest request = new ProductRequest(); request.RequestId = NewRequestId; request.AccessToken = AccessToken; request.ClientTag = ClientTag; request.LoadOptions = new string[] { "Products" }; request.Criteria = new ProductCriteria { CategoryId = categoryId, SortExpression = sortExpression }; ProductResponse response = ActionServiceClient.GetProducts(request); if (request.RequestId != response.CorrelationId) throw new ApplicationException("GetProductsByCategory: RequestId and CorrelationId do not match."); return response.Products; }
public Product GetProduct(int productId) { ProductRequest request = new ProductRequest(); request.RequestId = NewRequestId; request.AccessToken = AccessToken; request.ClientTag = ClientTag; request.LoadOptions = new string[] { "Product" }; request.Criteria = new ProductCriteria { ProductId = productId }; ProductResponse response = ActionServiceClient.GetProducts(request); if (request.RequestId != response.CorrelationId) throw new ApplicationException("GetProductsByCategory: RequestId and CorrelationId do not match."); return response.Product; }
public IList<Category> GetCategories() { ProductRequest request = new ProductRequest(); request.RequestId = NewRequestId; request.AccessToken = AccessToken; request.ClientTag = ClientTag; request.LoadOptions = new string[] { "Categories" }; ProductResponse response = ActionServiceClient.GetProducts(request); if (request.RequestId != response.CorrelationId) throw new ApplicationException("GetCategories: RequestId and CorrelationId do not match."); return response.Categories; }