コード例 #1
0
 public ActionResult Create(ProductAdd newItem)
 {
     // Model state validity check
     // If not valid, redirect to the index view
     // Otherwise, continue
     // Attempt to add the new item, using the manager method
     // If the attempt fails, redirect to the index view
     // Otherwise, redirect to the details view for the added object
     return View();
 }
コード例 #2
0
        public async Task <IActionResult> Create(ProductAdd productAdd)
        {
            if (ModelState.IsValid)
            {
                await _productApiService.AddAsync(productAdd);

                return(RedirectToAction("Index", "Home"));
            }
            ModelState.AddModelError("", "Something else wrong !");

            return(View(productAdd));
        }
コード例 #3
0
        public async Task AddAsync(ProductAdd productAdd)
        {
            var token = _accessor.HttpContext.Session.GetString("token");

            if (!string.IsNullOrWhiteSpace(token))
            {
                using var httpClient = new HttpClient();
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                var jsonData        = JsonConvert.SerializeObject(productAdd);
                var stringContent   = new StringContent(jsonData, Encoding.UTF8, "application/json");
                var responseMessage = await httpClient.PostAsync("http://localhost:59334/api/products", stringContent);
            }
        }
コード例 #4
0
 public ProductBase AddNewProduct(ProductAdd newItem)
 {
     // Attempt to fetch the supplier object
     // If that fails, return null
     // Otherwise, continue
     // Create a new design model object
     // Its properties come from the passed-in 'newItem' object
     // Remember to configure the Supplier property correctly
     // Add to the peristent store, and save changes
     // Prepare the return result
     // Return the result
     return null;
 }
コード例 #5
0
        public async Task <dynamic> Add([FromBody] ProductAdd item)
        {
            if (item == null)
            {
                return new { JsonString = "Error" }
            }
            ;

            var currentUser = JwtIdentity.UserInfo(Thread.CurrentPrincipal.Identity);
            //item.SubmiterUserId = currentUser.Id;
            var result = await _sqlData.Product.Add(item);

            return(new { Result = JsonConvert.DeserializeObject(result) });
        }
コード例 #6
0
        public IHttpActionResult Post(ProductAdd product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateProductService();

            if (!service.ProductAdd(product))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
コード例 #7
0
        public Product Add(ProductAdd product)
        {
            var res = new Product()
            {
                Id    = _AUTOINCREMENT_ID,
                Color = product.Color,
                Iban  = product.Iban,
                Name  = product.Name,
                Price = product.Price
            };

            _PRODUCT_DB.Add(res);

            return(res);
        }
コード例 #8
0
        public bool ProductAdd(ProductAdd model)
        {
            var entity = new Product()
            {
                OwnerId            = _pUserId,
                ProductName        = model.ProductName,
                ProductPrice       = model.ProductPrice,
                ProductDescription = model.ProductDescription,
                CreatedUtc         = DateTimeOffset.Now,
                ProductReviewId    = model.ProductReviewId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Products.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #9
0
        public async Task <IActionResult> CreateProduct(ProductAdd addProduct)
        {
            if (ModelState.IsValid)
            {
                var skuBarcodeValid = await _productService.CheckProduct(addProduct.Sku, addProduct.Barcode);

                if (skuBarcodeValid)
                {
                    if (await _productService.SaveProduct(addProduct.ToProduct(), addProduct.Images))
                    {
                        return(LocalRedirect("/admin/products"));
                    }
                }
                else
                {
                    ViewData["Message"] = "Sku Or Barcode Must Unique";
                }
            }

            return(View("Create", addProduct));
        }
コード例 #10
0
        // GET: Admin/Product/Add
        public virtual ActionResult Add()
        {
            ProductAdd Product = new ProductAdd();

            return(View(Product));
        }
コード例 #11
0
 public ActionResult <Product> Put(int id, [FromBody] ProductAdd product)
 {
     return(Ok(_productRepository.Update(id, product)));
 }
コード例 #12
0
        public ActionResult <Product> Post([FromBody] ProductAdd product)
        {
            var addedProduct = _productRepository.Add(product);

            return(Ok(addedProduct));
        }
コード例 #13
0
        // GET api/<controller>/Add/5
        public ProductSummary Post([FromBody] ProductAdd product)
        {
            int            qty       = product.quantity;
            string         productId = product.productId;
            ProductSummary summary   = new ProductSummary
            {
                Status = false
            };

            if (string.IsNullOrEmpty(productId))
            {
                return(summary);
            }

            if (qty < 1)
            {
                return(summary);
            }

            HttpContextBase abstractContext = new System.Web.HttpContextWrapper(HttpContext.Current);
            string          visitorId       = session.getUser(abstractContext.Session);

            Basket existingItem = db.Baskets.Where(b => b.VisitorId == visitorId && b.ProductId == productId).FirstOrDefault();

            if (existingItem != null)
            {
                existingItem.Quantity += qty;
                try
                {
                    db.Entry(existingItem).State = EntityState.Modified;
                    db.SaveChanges();
                }
                catch (Exception)
                {
                    return(summary);
                }
            }
            else
            {
                Basket basket = new Basket
                {
                    BasketId    = Guid.NewGuid(),
                    VisitorId   = visitorId,
                    Quantity    = qty,
                    ProductId   = productId,
                    CreatedDate = DateTime.UtcNow
                };
                try
                {
                    db.Baskets.Add(basket);
                    db.SaveChanges();
                }
                catch (Exception)
                {
                    return(summary);
                }
            }

            List <Basket> basketItems = store.GetBasketItems(visitorId, db);
            int           countItems  = basketItems.Sum(a => a.Quantity);

            summary.Status   = true;
            summary.Quantity = countItems;

            return(summary);
        }
コード例 #14
0
        private void button2_Click(object sender, EventArgs e)
        {
            ProductAdd productAdd = new ProductAdd();

            frmgecis.OperantFormPass(productAdd);
        }