Esempio n. 1
0
        public IActionResult UpdateProduct(int id, [FromForm] ProductInput productInput)
        {
            ProductDTO productDTO = _productRepository.GetProduct(id);

            if (productDTO == null)
            {
                return(NotFound());
            }
            if (string.IsNullOrWhiteSpace(productInput.Name))
            {
                if (string.IsNullOrWhiteSpace(productInput.Price))
                {
                    return(BadRequest());
                }
                else
                {
                    productDTO.Price = productInput.Price;
                }
            }
            else
            {
                productDTO.Name = productInput.Name;
                if (!string.IsNullOrWhiteSpace(productInput.Price))
                {
                    productDTO.Price = productInput.Price;
                }
            }

            _productRepository.UpdateProduct(productDTO);
            return(Ok());
        }
Esempio n. 2
0
        private void updateInventory(ProductInput productInput)
        {
            Inventory inventory = ClarityDB.Instance.Inventories.FirstOrDefault(x => x.ProductID == productInput.ProductID);

            inventory.Quantity   += productInput.Quantity;
            inventory.LatestPrice = productInput.SalePrice;
        }
Esempio n. 3
0
 public void Create(ProductInput model)
 {
     //Check for column values types
     Assert.AreEqual(model.ProductName, typeof(string));
     Assert.AreEqual(model.Description, typeof(string));
     Assert.AreEqual(model.Price, typeof(decimal));
 }
Esempio n. 4
0
        public async Task <ProductOutput> SaveProduct(ProductInput saveProduct)
        {
            Product product;

            if (saveProduct.Id.HasValue)
            {
                product = await _productRepository.GetAsync(saveProduct.Id.Value);

                product = saveProduct.MapTo(product);
                if (saveProduct.IsSet)
                {
                    IEnumerable <SetProductInput> newSetProducts = saveProduct.SetProductsInput.Where(x => !x.Id.HasValue);
                    foreach (SetProductInput newSetProduct in newSetProducts)
                    {
                        product.SetProducts.Add(newSetProduct.MapTo <SetProduct>());
                    }
                }
                await _productRepository.UpdateAsync(product);
            }
            else
            {
                product = saveProduct.MapTo <Product>();
                if (saveProduct.IsSet)
                {
                    product.SetProducts = saveProduct.SetProductsInput.MapTo <List <SetProduct> >();
                }
                await _productRepository.InsertAndGetIdAsync(product);
            }

            return(product.MapTo <ProductOutput>());
        }
Esempio n. 5
0
        public ProductInput GetProduct([FromBody] ProductInput input)
        {
//            _logger.LogError("这是个异常");
            return(new ProductInput {
                ProductName = "一体机"
            });
        }
        public ActionResult <Product> UpdateProduct(int productId, [FromBody] ProductInput productData)
        {
            if (productId < 1)
            {
                return(BadRequest());
            }

            if (productData == null)
            {
                return(BadRequest());
            }

            if (this.GetProduct(productId).Value == null)
            {
                return(NotFound());
            }

            var newProduct = new Product();

            newProduct.code  = 0;
            newProduct.name  = productData.name;
            newProduct.price = productData.price;

            return(productManager.UpdateProduct(productId, newProduct));
        }
        public RestApiResult CreateList(JArray jsonList)
        {
            if (jsonList == null)
            {
                return(new RestApiResult {
                    StatusCode = HttpStatusCode.BadRequest
                });
            }

            foreach (JObject json in jsonList)
            {
                ProductInput productInputs = ProductInput.FromJson(json);
                productInputs.CreatedDate = DateTime.Now;
                ClarityDB.Instance.ProductInputs.Add(productInputs);
                //update Inventory and Product
                long productId = json.Value <long>("productId");
                long quantity  = json.Value <long>("quantity");
                long price     = json.Value <long>("price");
                UpdateInventory(productId, quantity);
            }
            ClarityDB.Instance.SaveChanges();

            return(new RestApiResult {
                StatusCode = HttpStatusCode.OK
            });
        }
Esempio n. 8
0
        public void Index()
        {
            ProductInput model = new ProductInput();

            model.lstProduct = TblProduct.GetAllProduct();
            //Checks for count of records
            Assert.AreNotEqual(model.lstProduct.Count, 0);
        }
Esempio n. 9
0
 public async override Task Validate(ProductInput input)
 {
     if (input.Doses.Any() && string.IsNullOrWhiteSpace(input.Id) && input.Doses.Any(s => !string.IsNullOrWhiteSpace(s.IdProduct)))
     {
         throw new Exception($"si el producto {input.Name} es nuevo, sus dosis no deben llevar id");
     }
     await base.Validate(input);
 }
Esempio n. 10
0
 public IActionResult AddProduct([FromForm] ProductInput productInput)
 {
     if (string.IsNullOrWhiteSpace(productInput.Name) || string.IsNullOrWhiteSpace(productInput.Price))
     {
         return(BadRequest());
     }
     _productRepository.AddProduct(productInput.Name, productInput.Price);
     return(Ok());
 }
        public Product Update(int id, [FromBody] ProductInput product)
        {
            var entity = new Product()
            {
                Id = id, Name = product.Name, CategoryId = product.CategoryId, Description = product.Description, ImageUrl = product.ImageUrl, Price = product.Price, IsActive = product.IsActive
            };

            return(_productRepo.Update(entity));
        }
Esempio n. 12
0
        public ContentResult AddProduct(ProductInput inputData)
        {
            try
            {
                var pro = dbContext.Products.FirstOrDefault(x => x.ProductName == inputData.ProductName);
                if (pro is null)
                {
                    var product = new Product()
                    {
                        ProductId   = Guid.NewGuid(),
                        ProductName = inputData.ProductName,
                        Quantity    = inputData.Quantity,
                        IsActive    = true
                    };

                    dbContext.Products.Add(product);
                    var result = dbContext.SaveChanges();

                    if (result is 1)
                    {
                        return(new ContentResult
                        {
                            Content = JsonConvert.SerializeObject("Success"),
                            ContentType = "application/json",
                            StatusCode = 200
                        });
                    }
                    else
                    {
                        return(new ContentResult
                        {
                            Content = JsonConvert.SerializeObject("Fail"),
                            ContentType = "application/json",
                            StatusCode = 204
                        });
                    }
                }
                else
                {
                    return(new ContentResult
                    {
                        Content = JsonConvert.SerializeObject("Entered Product Name Already Exists"),
                        ContentType = "application/json",
                        StatusCode = 204
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ContentResult
                {
                    Content = JsonConvert.SerializeObject(ex.InnerException.ToString()),
                    ContentType = "application/json",
                    StatusCode = 417
                });
            }
        }
Esempio n. 13
0
 private void hàngHóaToolStripMenuItem_Click(object sender, EventArgs e)
 {
     panelPreference.Controls.Clear();
     panelContents.Controls.Clear();
     pmProduct    = pmProduct ?? new PMProduct();
     productInput = productInput ?? new ProductInput();
     panelPreference.Controls.Add(pmProduct);
     panelContents.Controls.Add(productInput);
 }
Esempio n. 14
0
        public IActionResult Post([FromBody] ProductInput product)
        {
            var inputUpdate = new Products
            {
                Price = product.Price,
                Name  = product.Name
            };

            return(Ok(_productService.Add(inputUpdate)));
        }
Esempio n. 15
0
        private void CreateProductInputForInputOrder(JObject json, InputOrder inputOrder, long productId)
        {
            ProductInput productInput = ProductInput.FromJson(json);

            productInput.ProductID    = productId;
            productInput.CreatedDate  = DateTime.Now;
            productInput.InputOrderID = inputOrder.ID;
            inputOrder.ProductInputs.Add(productInput);
            //Increase quantity in Inventory
            updateInventory(productInput);
        }
Esempio n. 16
0
 public ActionResult AddProduct(ProductInput model)
 {
     ValidateModel(model);
     if (Request.Files.Count <= 0)
     {
         throw new UserFriendlyException("Image no encontrada");
     }
     model.Imagen = Request.Files[0];
     _productAdminService.AddProductToStore(model);
     return(RedirectToAction("Index"));
 }
Esempio n. 17
0
        public bool Add(ProductInput productInput)
        {
            var product = new Product
            {
                Name          = productInput.Name,
                MainProductId = productInput.MainProductId,
                Price         = productInput.Price
            };

            return(_productService.Add(product));
        }
Esempio n. 18
0
        public IActionResult Put([FromRoute] int id, [FromBody] ProductInput product)
        {
            var inputUpdate = new Products
            {
                Id    = id,
                Price = product.Price,
                Name  = product.Name
            };

            return(Ok(_productService.Update(inputUpdate)));
        }
Esempio n. 19
0
 public ActionResult Create()
 {
     try
     {
         ProductInput model = new ProductInput();
         return(View(model));
     }
     catch (Exception)
     {
         throw new Exception();
     }
 }
Esempio n. 20
0
        public Guid AddProductToStore(ProductInput input)
        {
            var     slug     = input.ProductName.CreateSlug();
            var     tenantId = AbpSession.TenantId ?? 1;
            Product instance;

            if (input.Id.HasValue)
            {
                instance = _productManager.GetProduct(input.Id.Value);
                instance.SetSlug(instance.ProductName.CreateSlug());
                instance = input.MapTo(instance);
            }
            else
            {
                instance = Product.CreateProduct(input.ProductName,
                                                 input.AvailableStock,
                                                 input.TrackStock,
                                                 input.ProductPrice,
                                                 input.ProductDescription,
                                                 input.Sku,
                                                 input.IsFeatured,
                                                 input.ProductName.CreateSlug());
                if (input.Active)
                {
                    instance.Active = input.Active;
                }
            }

            if (input.Imagen.ContentLength > 0)
            {
                //Small image
                var formatedFolderSmall = string.Format(ImageFolder, tenantId, slug, FolderSizeSmall);
                var smallImage          = _imageManager.SaveImage(250, 250, input.Imagen, formatedFolderSmall);
                //Medium Image
                var formatedFolderMed = string.Format(ImageFolder, tenantId, slug, FolderSizeMedium);
                var medImage          = _imageManager.SaveImage(650, 350, input.Imagen, formatedFolderMed);

                //Default Image
                var formatedFolderDef = string.Format(ImageFolder, tenantId, slug, FolderSizeDefault);
                var defImage          = _imageManager.SaveImage(null, null, input.Imagen, formatedFolderDef);


                instance.SetMainImage(defImage);
                instance.SetMedImage(medImage);
                instance.SetSmallImage(smallImage);
                instance.SetDataImage(input.DataImage);
            }


            var id = _productManager.AddProduct(instance);

            return(id);
        }
Esempio n. 21
0
        public ContentResult EditProduct(ProductInput inputData)
        {
            try
            {
                var product = dbContext.Products.FirstOrDefault(x => x.ProductId == inputData.ProductId);
                if (product is null)
                {
                    return(new ContentResult
                    {
                        Content = JsonConvert.SerializeObject("Invaild Product Id"),
                        ContentType = "application/json",
                        StatusCode = 204
                    });
                }
                else
                {
                    product.ProductName = inputData.ProductName;
                    product.Quantity    = inputData.Quantity;
                    product.IsActive    = inputData.IsActive;
                    dbContext.Products.Update(product);
                    var result = dbContext.SaveChanges();

                    if (result is 1)
                    {
                        return(new ContentResult
                        {
                            Content = JsonConvert.SerializeObject("Success"),
                            ContentType = "application/json",
                            StatusCode = 200
                        });
                    }
                    else
                    {
                        return(new ContentResult
                        {
                            Content = JsonConvert.SerializeObject("Fail"),
                            ContentType = "application/json",
                            StatusCode = 204
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                return(new ContentResult
                {
                    Content = JsonConvert.SerializeObject(ex.InnerException.ToString()),
                    ContentType = "application/json",
                    StatusCode = 417
                });
            }
        }
Esempio n. 22
0
 public ActionResult Index()
 {
     try
     {
         ProductInput model = new ProductInput();
         model.lstProduct = TblProduct.GetAllProduct();
         return(View(model.lstProduct));
     }
     catch (Exception)
     {
         throw new Exception();
     }
 }
Esempio n. 23
0
        public async Task <int> CreateOrUpdateProduct(ProductInput input)
        {
            if (input.Id != 0)
            {
                await UpdateProductAsync(input);
            }
            else
            {
                input.Id = CreateProductAsync(input);
            }

            return(input.Id);
        }
Esempio n. 24
0
        public void TestAddProductExpectTrue()
        {
            var product = new ProductInput()
            {
                ProductId   = Guid.NewGuid(),
                ProductName = "SurfaceX",
                Quantity    = 100
            };
            var addProduct = productService.AddProduct(product);
            var valConv    = JsonConvert.DeserializeObject(addProduct.Content.ToString());
            var _result    = valConv.ToString() == "Success" ? true : false;

            Assert.True(_result);
        }
        public RestApiResult GetProductInputByID(long id)
        {
            ProductInput productInput = ClarityDB.Instance.ProductInputs.FirstOrDefault(x => x.ID == id);

            if (productInput == null)
            {
                return(new RestApiResult {
                    StatusCode = HttpStatusCode.NotFound
                });
            }

            return(new RestApiResult {
                StatusCode = HttpStatusCode.OK, Json = productInput.ToJson()
            });
        }
        public ActionResult <Product> AddProduct([FromBody] ProductInput productData)
        {
            if (productData == null)
            {
                return(BadRequest());
            }

            var newProduct = new Product();

            newProduct.code  = 0;
            newProduct.name  = productData.name;
            newProduct.price = productData.price;

            return(productManager.AddProduct(newProduct));
        }
Esempio n. 27
0
        public void TestEditProductExpectTrue()
        {
            var product = new ProductInput()
            {
                ProductId   = Guid.Parse("99714c41-e378-44f1-b0b4-4c5eec741909"),
                ProductName = "IPhone5SE",
                Quantity    = 150,
                IsActive    = true
            };
            var editProduct = productService.EditProduct(product);
            var valConv     = JsonConvert.DeserializeObject(editProduct.Content.ToString());
            var _result     = valConv.ToString() == "Success" ? true : false;

            Assert.True(_result);
        }
Esempio n. 28
0
        public int CreateProductAsync(ProductInput input)
        {
            var Id      = 0;
            var product = input.MapTo <Product>();
            var val     = _productRepository.GetAll().Where(p => p.ProductName == input.ProductName || p.ProductCode == input.ProductCode || p.SuspectCode == input.SuspectCode || p.Gpcode == input.Gpcode).FirstOrDefault();

            if (val == null)
            {
                Id = _productRepository.InsertAndGetId(product);
            }
            else
            {
                throw new UserFriendlyException("Ooops!", "Duplicate Data Occured in MileProduct Name '" + input.ProductName + "' or Product Code '" + input.ProductCode + "' or Suspect Code '" + input.SuspectCode + "' or Gp Code '" + input.Gpcode + "'...");
            }
            return(Id);
        }
Esempio n. 29
0
        public virtual async Task UpdateProductAsync(ProductInput input)
        {
            var product = await _productRepository.GetAsync(input.Id);

            ObjectMapper.Map(input, product);

            var val = _productRepository.GetAll().Where(p => (p.ProductCode == input.ProductCode || p.SuspectCode == input.SuspectCode || p.Gpcode == input.Gpcode) && p.Id != input.Id).FirstOrDefault();

            if (val == null)
            {
                await _productRepository.UpdateAsync(product);
            }
            else
            {
                throw new UserFriendlyException("Ooops!", "Duplicate Data Occured in MileProduct Name '" + input.ProductName + "' or Product Code '" + input.ProductCode + "'or Suspect Code '" + input.SuspectCode + "' or Gp Code '" + input.Gpcode + "'...");
            }
        }
Esempio n. 30
0
        public void Product_Title_Shoulde_Be_Unique()
        {
            //Arrange
            var product = new ProductInput
            {
                Id       = 100,
                Title    = "A",
                Price    = 30,
                NewPrice = 40
            };

            //Act
            var response = _productService.Create(product);


            //Assert
            Assert.IsFalse(response.result);
        }