public void AddProduct(ProductViewModel product) { var myProduct = _mapper.Map <Product>(product); myProduct.Category = null; _productsRepo.AddProduct(myProduct); }
public void AddProduct(ProductViewModel data) { var p = _mapper.Map <Product>(data); p.Category = null; _productRepo.AddProduct(p); }
public async Task <IActionResult> CreateProductCollection([FromBody] IEnumerable <DTO.Create.Product> products) { try { //validate input and check categories IEnumerable <DAL.Entities.Product> productEntities = _mapper.Map <IEnumerable <DAL.Entities.Product> >(products); foreach (DAL.Entities.Product p in productEntities) { _repo.AddProduct(p); } await _repo.SaveChangesAsync(); IEnumerable <DAL.Entities.Product> productsToReturn = await _repo.GetProductsAsync(productEntities.Select(p => p.Id).ToList()); string productIds = string.Join(",", productsToReturn.Select(p => p.Id)); return(CreatedAtRoute("GetProducts", new { productIds }, productsToReturn)); } catch (Exception ex) { _logger.LogCritical("error message here", ex); return(StatusCode(500, "error message here")); } }
public void AddProduct(ProductViewModel data) { //Product >>> ProductViewModel var prod = _mapper.Map <Product>(data); _productRepo.AddProduct(prod); }
private void OnAddCommandExecute() { IsDialogOpen = false; newProduct = new Product { Id = Guid.NewGuid(), Name = NewProductName, Description = NewProductDescription, ProductCategory = NewProductCategory }; Products.Add(newProduct); _productsRepository.AddProduct(newProduct); _productsRepository.Save(); RecipeProduct recipeProduct = new RecipeProduct { Id = Guid.NewGuid(), RecipeId = SelectedRecipe.Id, ProductId = newProduct.Id }; SelectedRecipe.RecipeProducts.Add(recipeProduct); SelectedRecipeProductLookups.Add(new RecipeProductLookup { ProductId = newProduct.Id, RecipeProductId = recipeProduct.Id, ProductName = newProduct.Name }); }
public async Task <IActionResult> CreateProduct( [FromBody] Models.ProductsForCreation productToCreate) { if (productToCreate == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } var productEntity = _mapper.Map <Products>(productToCreate); _productsRepository.AddProduct(productEntity); await _productsRepository.SaveChanges(); await _productsRepository.GetProduct(productEntity.ProductId); return(Ok(CreatedAtRoute("GetProduct", new { productId = productEntity.ProductId }, _mapper.Map <Models.Products>(productEntity)))); }
public void AddProduct(ProductViewModel product) { //changing this using automapper later on //Converting from //ProductViewModel >> Product /* Product newProduct = new Product() * { * Description = product.Description, * Name = product.Name, * Price = product.Price, * CategoryId = product.Category.Id, * ImageUrl = product.ImageUrl * }; * * _productsRepo.AddProduct(newProduct); */ var myProduct = _mapper.Map <Product>(product); myProduct.Category = null; _productsRepo.AddProduct(myProduct); }
public void AddProduct(ProductViewModel product) { //Changing this using automapper later on //Ctrl + . //Old Method /* * Product newProduct = new Product() * { * Description = product.Description, * Name = product.Name, * Price = product.Price, * CategoryId = product.Category.Id, * ImageUrl = product.ImageUrl * * }; */ var myProduct = _mapper.Map <Product>(product); //This is done to avoid an error from the automapper, which is trying to insert a category myProduct.Category = null; _productsRepo.AddProduct(myProduct); }
public ActionResult <Product> CreateProduct(ProductForCreationDto product) { var productEntity = _mapper.Map <Entities.Product>(product); _productRepository.AddProduct(productEntity); _productRepository.Save(); return(CreatedAtRoute("GetProduct", new { productId = productEntity.Id }, productEntity)); }
public void AddProduct(ProductViewModel p) { /* Product pr = new Product() * { * Name = p.Name, * Price = p.Price * };*/ productsRepository.AddProduct(_autoMapper.Map <Product>(p)); }
public async Task <ActionResult> AddProduct(ProductCreateModel createProductModel) { var product = _mapper.Map <Product>(createProductModel); await _repository.AddProduct(product); await _repository.SaveChanges(); return(Ok()); }
public IActionResult AddProduct(Product product) { if (product != null) { return(Ok(_products.AddProduct(product))); } else { return(BadRequest("Please enter the product to add")); } }
public async Task <IActionResult> AddNewProduct(Product product) { if (ModelState.IsValid) { await _productsRepo.AddProduct(product); return(RedirectToAction(nameof(Index))); } return(PartialView("_CreateProductPartial", product)); }
public void AddProduct(ProductViewModel data) { Product p = new Product(); p.Description = data.Description; p.ImageUrl = data.ImageUrl; p.Name = data.Name; p.Price = data.Price; p.CategoryId = data.Category.Id; _productRepo.AddProduct(p); }
public async Task <ActionResult> Create([Bind(Include = "Id,Sku,Name,Price,Stock")] Product product) { if (ModelState.IsValid) { _productRepository.AddProduct(product); await _productRepository.SaveAsync(); return(RedirectToAction("Index")); } return(View(product)); }
public async Task <IActionResult> PostProduct(ATITransactionDto newTransaction) { var userId = HttpContext.GetUserId(); var isSuccess = await _repo.AddProduct(newTransaction, userId, newTransaction.Content.ProductId == -1); if (isSuccess) { return(RedirectToAction("Index", "Products")); } return(RedirectToAction("Error", "Home")); }
public Guid AddProduct(ProductDto dto) { var model = dto.ToDbModel(); model.Id = Guid.NewGuid(); model.CreatedOn = DateTime.Now; model.ModifiedOn = DateTime.Now; repository.AddProduct(model); return(model.Id); }
public void AddProduct(ProductViewModels product) { Product newProduct = new Product() { Desc = product.Desc, Name = product.Name, Price = product.Price, CategoryID = product.category.id, ImageUrl = product.ImageUrl }; _productsRep.AddProduct(newProduct); }
public async Task <IActionResult> Post(ProductCreateInputModel model) { try { var response = await _repo.AddProduct(model); return(Ok(response)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void Post(Product product) { try { Product item = SanitizeInput(product.Id, product); _repository.AddProduct(item); } catch (Exception exception) { _logger.LogError(LoggingEvents.AddProduct, exception, "AddProduct Exception {id}", product.Id); throw; } }
public async Task <Guid> AddProduct(string Name, decimal Price) { Guid id = Guid.NewGuid(); var product = await _productRepository.GetProductById(id); if (product != null) { throw new Exception($"Event with id: {id} already exists!"); } product = new Product(id, Name, Price); await _productRepository.AddProduct(product); return(id); }
public HttpResponseMessage AddProduct([FromBody] ProductViewModel model) { try { var data = productrepository.AddProduct(model); if (data != null) { return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, result = model, message = "The record Created Successfully" })); } return(Request.CreateResponse(HttpStatusCode.OK, new { success = false, message = "The was an error creating this record" })); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.OK, new { success = false, message = $"there was an error creating this record {e.Message}" })); } }
public IActionResult AddProduct([FromBody] Product product) { if (product == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } var NewCategory = _repository.AddProduct(product); return(CreatedAtAction("GetProducts", new { ProductId = product.ProductId }, product)); }
public void AddProduct(ProductViewModel data) { //AutoMapper (NuGet Package) //ProductViewModel ====> Product Product p = new Product(); p.Description = data.Description; p.ImageUrl = data.ImageUrl; p.Name = data.Name; p.Price = data.Price; p.CategoryId = data.Category.Id; _productRepo.AddProduct(p); }
public void AddProduct(ProductViewModel product) { /* * Product newProduct = new Product() * { * Description = product.Description, * Name = product.Name, * Price = product.Price, * CategoryId = product.Category.Id, * ImageUrl = product.ImageUrl * }; * * _productsRepo.AddProduct(newProduct);*/ _productsRepo.AddProduct(_mapper.Map <Product>(product)); }
public void AddProduct(ProductViewModel product) { /*var newProduct = _mapper.Map<ProductViewModel, Product>(product); * _productsRepo.AddProduct(newProduct);*/ Product newProduct = new Product() { Description = product.Description, Name = product.Name, Price = product.Price, CategoryId = product.Category.Id, ImageUrl = product.ImageUrl }; _productsRepo.AddProduct(newProduct); }
public IActionResult Create(Product product) { var flag = false; if (ModelState.IsValid) { if (product != null) { flag = productService.AddProduct(product); } if (flag) { return RedirectToAction("Index"); } } return View(product); }
public ActionResult <ProductDto> CreateProduct(ProductForCreationDto product) { if (product == null) { return(BadRequest()); } var productEntity = _mapper.Map <Entities.Products>(product); _productRepository.AddProduct(productEntity); _productRepository.Save(); var productToReturn = _mapper.Map <ProductDto>(productEntity); return(CreatedAtRoute("GetProduct", new { productId = productToReturn.productId }, productToReturn)); }
public async Task <ActionResult <Products> > CreateProduct([FromBody] Products product) { try { if (product == null) { return(BadRequest()); } var createdProduct = await productsRepository.AddProduct(product); return(CreatedAtAction(nameof(GetProduct), new { productId = createdProduct.ProductId }, createdProduct)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error creating data")); } }
public void AddProduct(ProductViewModel product) { //changing this using automapper later on //Converting from //ProductViewModel >>> Product //Ctrl + . Product newProduct = new Product() { Description = product.Description, Name = product.Name, Price = product.Price, CategoryId = product.Category.Id, ImageUrl = product.ImageUrl }; _productsRepo.AddProduct(newProduct); }