Ejemplo n.º 1
0
        public IActionResult Post([FromBody] Product product)
        {
            productsService.Add(product);

            //return Created($"https://localhost:44320/api/products/{product.Id}", product);
            return(CreatedAtRoute("GetProductLink", new { id = product.Id }, product));
        }
Ejemplo n.º 2
0
        public async Task <Guid> Add(AddProductModel model)
        {
            var id = Guid.NewGuid();
            await _service.Add(new Product(new Id(id), new Title(model.Title), new Money(model.Price), new Image(model.ImageId)));

            return(id);
        }
Ejemplo n.º 3
0
 public ActionResult create(int id, string brand, string name, string description, DateTime expiration, string img,
                            string price, string netWeight, string origin, int categoryId, int quantity, string storeId, DateTime startDate, string size, Boolean status)
 {
     try
     {
         Products products = new Products
         {
             Brand       = brand,
             Name        = name,
             Description = description,
             Expiration  = expiration,
             Img         = img,
             Price       = price,
             NetWeight   = netWeight,
             Origin      = origin,
             CategoryId  = categoryId,
             Quantity    = quantity,
             StoreId     = storeId,
             StartDate   = startDate,
             Size        = size,
             Status      = status
         };
         _productsService.Add(products);
         _productsService.SaveChanges();
         return(Ok(products.Id));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        public ActionResult <ProductDto> Post([FromBody] ProductDetailsDto productDetails)
        {
            var product = _productsService.Add(productDetails);

            return(Created(
                       Url.Action(nameof(Get), ControllerContext.ActionDescriptor.ControllerName, new { product.Id }),
                       product));
        }
        public IActionResult AddProduct([FromBody] AddProductDTO addProductDTO)
        {
            Products product = _mapper.Map <Products>(addProductDTO);

            product.AddedDate = DateTime.Now;
            _servicePro.Add(product);
            return(Ok(product));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> PostProduct([FromBody] Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _service.Add(product);

            return(CreatedAtAction("GetProduct", new { id = product.Id }, product));
        }
Ejemplo n.º 7
0
        public ActionResult Add(ProductViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            productsService.Add(mapper.Map <Product>(viewModel));

            return(View("Success"));
        }
        public HttpResponse Add(AddProductInputModel inputModel)
        {
            if (inputModel.Name.Length < 4 || inputModel.Name.Length > 20 || inputModel.Description.Length > 10)
            {
                return(this.Redirect("/Products/Add"));
            }

            int productId = productService.Add(inputModel.Name, inputModel.Description, inputModel.ImageUrl, inputModel.Category, inputModel.Gender, inputModel.Price);

            return(this.Redirect($"/Products/Details?id={productId}"));
        }
        private void Add()
        {
            // TODO: Show ProductView
            var product = new Product {
                Name = "Produkt 1", Color = "Red", Price = 99.9m
            };

            // navigationService.Navigate("ProductView");

            productsService.Add(product);
            this.Products.Add(product);
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Add([FromBody] InProductDTO model)
        {
            var product = await _productsService.Add(model, HttpContext);

            if (product != null)
            {
                return(Ok(product));
            }
            else
            {
                return(BadRequest(product));
            }
        }
Ejemplo n.º 11
0
 public IActionResult AddProduct(ProductModel product)
 {
     try
     {
         _productsService.Add(product);
     }
     catch (ProductAlreadyExists)
     {
         ModelState.AddModelError("AlreadyExists", "Product already exists!");
         return(View());
     }
     return(View());
 }
Ejemplo n.º 12
0
        public IActionResult Add(string id, ProductInputViewModel productInput)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(productInput));
            }
            var currentOrderId = id;
            var orderedProduct = _productsService.Add(currentOrderId,
                                                      productInput.ProductCode,
                                                      productInput.ProductName,
                                                      productInput.Count,
                                                      productInput.Weight);

            return(Redirect($"/Orders/Edit?id={orderedProduct.OrderId}"));
        }
Ejemplo n.º 13
0
        public async void Add_WhenCalled_CheckThatAdded()
        {
            var product = new Models.Product {
                ProductId = 0, OwnerId = 1, ManufacturerId = 1, CategoryId = 1, ProductName = "product added", Description = "descr", Price = 1312.65m, Owner = null, Producer = null
            };
            // Act
            await _service.Add(product);

            await _ufw.CommitAsync();

            var item = await _service.Find(product.ProductId);

            // Assert
            Assert.NotNull(item);
            Assert.True(item.ProductName == "product added");
        }
Ejemplo n.º 14
0
 public ActionResult add(Products model)
 {
     if (ModelState.IsValid)
     {
         model.CreateTime = DateTime.Now;
         model.IsCheck    = 1;
         model.IsShow     = true;
         model            = productBll.Add(model);
         if (model.Id > 0)
         {
             return(RedirectToAction("list"));
         }
         else
         {
             ModelState.AddModelError("", "添加失败!");
         }
     }
     return(View());
 }
Ejemplo n.º 15
0
        public async Task <ActionResult <ProductDto> > Post([FromBody] NewProductDto newProduct)
        {
            var addedProduct = await _productsService.Add(newProduct);

            return(Ok(addedProduct));
        }
        public ActionResult <ProductDto> Post([FromBody] NewProductDto newProduct)
        {
            var addedProduct = _productsService.Add(newProduct);

            return(Ok(addedProduct));
        }
Ejemplo n.º 17
0
        public ActionResult Post(Product product)
        {
            _productsService.Add(product);

            return(CreatedAtRoute(new { id = product.Id }, product));
        }
Ejemplo n.º 18
0
        public HttpResponse Add(ProductAddInputModel inputModel)
        {
            var productId = productsService.Add(inputModel);

            return(this.View());
        }