Пример #1
0
        public IActionResult AddProduct(Products Products)
        {
            try
            {
                _logger.LogWarning("اجرای متد اضاقه کردن محصولات");
                if (!ModelState.IsValid)
                {
                    var errors = ModelState.Values.SelectMany(a => a.Errors).Select(a => a.ErrorMessage);
                    _logger.LogError("Model state not valid");
                    return(BadRequest(string.Join(",", errors)));
                }
                var result = _product.AddProduct(new Products
                {
                    ProductName = Products.ProductName,
                    CategoryId  = Products.CategoryId,
                    UnitPrice   = Products.UnitPrice
                });

                if (result.IsSucceed)
                {
                    _logger.LogInformation("محصول اضافه شد");
                    return(Ok(result.Data));
                }
                return(BadRequest(string.Join(",", result.Errors)));
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
        public async Task <ActionResult <ProductReadDTO> > CreateProduct([FromBody] ProductCreateDTO productCreateDto)
        {
            if (productCreateDto == null)
            {
                return(BadRequest());
            }

            var model = new Product
                        (
                productCreateDto.Name,
                productCreateDto.Price,
                productCreateDto.Color,
                productCreateDto.Description,
                productCreateDto.CategoryId
                        );
            await _productService.AddProduct(model);

            var productReadDto = new ProductReadDTO
            {
                ProductId   = model.ProductId,
                Name        = model.Name,
                Price       = model.Price,
                Color       = model.Color,
                Description = model.Description
            };

            return(CreatedAtRoute(nameof(GetProduct), new { Id = productReadDto.ProductId }, productReadDto));
        }
Пример #3
0
        public IActionResult OnPost(IFormFile imgUp, List <int> selectedColor, List <int> selectedSize)
        {
            if (ModelState.IsValid)
            {
                Product.ProductCode = Product.ProductCode.Trim();
                if (_productService.CodeProductIsExist(Product.ProductCode))
                {
                    ModelState.AddModelError("ProductCode", "کد محصول تکراری می باشد . کد کحصول جدید انتخاب کنید");
                    return(Page());
                }
                else
                {
                    _productService.AddProduct(Product, imgUp, selectedColor, selectedSize);
                    return(RedirectToPage("index"));
                }
            }

            var groups = _productService.GetAllProductGroupsSelectList();

            ViewData["Groups"] = new SelectList(groups, "Value", "Text");

            ViewData["Color"] = _productService.GetAllColors();
            ViewData["Size"]  = _productService.GetAllSize();

            return(Page());
        }
        public async Task <IActionResult> CreateProduct(ViewModelsDataEntry model)
        {
            if (ModelState.IsValid)
            {
                ProductTransactions productTransactions = new ProductTransactions();
                productTransactions.IdProduct   = model.IdProduct;
                productTransactions.DateChecked = DateTime.Now.Date;
                productTransactions.IdLocation  = model.IdLocation;

                Products products = new Products();
                products.IdProduct        = model.IdProduct;
                products.NameProduct      = model.NameProduct;
                products.ManufacturedDate = model.ManufacturedDate;
                products.ExpiredDate      = model.ExpiredDate;
                products.Manufactured     = model.Manufactured;
                products.Details          = model.Details;

                if (CheckExistProduct(model.IdProduct))
                {
                    await _productDb.AddProduct(products);

                    await _productTransactionsDb.AddProductTransactions(productTransactions);
                }
                else
                {
                    await _productDb.UpdateProduct(products);
                }

                return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAll", _productDb.GetAllProducts) }));
            }
            return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "CreateProduct", model) }));
            //return RedirectToAction("index");
        }
        public void AddProduct_With_Not_Null_Product()
        {
            var product = new Product()
            {
                Category               = "Computer Accessaries",
                Discount               = 10,
                Name                   = "Wireless Mouse",
                ProductId              = 1,
                OriginalPrice          = 300,
                HasAnyPromotionalOffer = true,
                PromotionalOffer       = PromotionalOffer.ByTwoGetOneFree
            };

            _productRepo.AddProduct(product);
            Assert.IsTrue(_productRepo.GetAllProducts().Count > 0);
        }
Пример #6
0
        public async Task <IActionResult> AddProductAsync([FromBody] Products model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var postId = await _db.AddProduct(model);

                    if (postId > 0)
                    {
                        return(Ok(postId));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                catch (Exception e)
                {
                    return(BadRequest());
                }
            }
            else
            {
                return(BadRequest());
            }
        }
Пример #7
0
        public ProductMutation(IProduct productService)
        {
            Field <ProductType>("createProduct", arguments: new QueryArguments(new QueryArgument <ProductInputType> {
                Name = "product"
            }),
                                resolve: context =>
            {
                var productObj = context.GetArgument <Product>("product");
                return(productService.AddProduct(productObj));
            });

            Field <ProductType>("updateProduct", arguments: new QueryArguments(new QueryArgument <IntGraphType> {
                Name = "id"
            }, new QueryArgument <ProductInputType> {
                Name = "product"
            }),
                                resolve: context =>
            {
                var productId  = context.GetArgument <int>("id");
                var productObj = context.GetArgument <Product>("product");
                return(productService.UpdateProduct(productId, productObj));
            });

            Field <StringGraphType>("deleteProduct", arguments: new QueryArguments(new QueryArgument <IntGraphType> {
                Name = "id"
            }),
                                    resolve: context =>
            {
                var productId = context.GetArgument <int>("id");
                productService.DeleteProduct(productId);
                return($"The product against the {productId} has been deleted");
            });
        }
Пример #8
0
        public static Product AddProduct(IProduct _product, ResolveFieldContext <object> context)
        {
            Product productToAdd = context.GetArgument <Product>("product");
            Product product      = _product.AddProduct(productToAdd);

            return(product);
        }
        public JsonResult AddProduct(Product product)
        {
            var concernId = Convert.ToInt32(Session["ConcernId"]);
            var userId    = Convert.ToInt32(Session["UserId"]);

            _product.AddProduct(product, concernId, userId);
            return(Json("", JsonRequestBehavior.AllowGet));
        }
Пример #10
0
 public IActionResult Post([FromBody] Product product)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     productRepository.AddProduct(product);
     return(CreatedAtAction("Get", product));
 }
 public IActionResult AddProduct(Product p)
 {
     if (!ModelState.IsValid)
     {
         throw new Exception("Product data is inavlid");
     }
     product.AddProduct(p);
     return(Ok("Product Added"));
 }
Пример #12
0
 public IActionResult Post([FromBody] Product product)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     productRepository.AddProduct(product);
     return(StatusCode(StatusCodes.Status201Created));
 }
Пример #13
0
 public ActionResult AddProduct(Product model)
 {
     if (ModelState.IsValid)
     {
         product.AddProduct(model);
         return(RedirectToAction(nameof(Index)));
     }
     return(View());
 }
 public IActionResult Create([Bind] Product product)
 {
     if (ModelState.IsValid)
     {
         prod.AddProduct(product);
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
        public void RemoveDiscountFromProduct_With_AddProduct()
        {
            var product = new Product()
            {
                Category               = "Computer Accessaries",
                Discount               = 10,
                Name                   = "Wireless Mouse",
                ProductId              = 1,
                OriginalPrice          = 300,
                HasAnyPromotionalOffer = true,
                PromotionalOffer       = PromotionalOffer.ByTwoGetOneFree
            };

            _productRepo.AddProduct(product);
            _discountRepo.RemoveDiscountFromProduct(product.ProductId);
            var productList = _productRepo.GetAllProducts();

            Assert.IsTrue(productList[0].Discount == 0);
        }
Пример #16
0
        public void TestAddProductSuccess()
        {
            var product = new MODELS.Product {
                Id = 0, Name = "GoPro", Description = "Camera", Price = 35000.00, Count = 5
            };

            MockRepository.GenerateMock <IProduct>().Expect(x => x.AddProduct(new MODELS.Product())).Return(1);
            var result = _productbdl.AddProduct(product);

            Assert.True(result > 0);
        }
Пример #17
0
        public HttpResponseMessage insertProduct(ProductBO product)
        {
            int produ   = iproducts.AddProduct(product);
            var session = HttpContext.Current.Session;

            if (session != null)
            {
                HttpContext.Current.Session["ProductID"] = produ;
            }
            return(Request.CreateResponse(HttpStatusCode.OK, "saved successfully"));
        }
Пример #18
0
        public void AddProduct()
        {
            DLModel.ProductName  = "testing tesing";
            DLModel.ProductDesc  = "testing tesing";
            DLModel.ProductFile  = "testing tesing";
            DLModel.ProductImage = "testing tesing";
            DLModel.ProductPrice = 11;

            int result = _productBL.AddProduct(DLModel);

            Assert.IsTrue(result > 0, "Unable to Add");
        }
Пример #19
0
 public IActionResult Create(Product product)
 {
     if (ModelState.IsValid)
     {
         repo.AddProduct(product);
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View());
     }
 }
Пример #20
0
        public async Task <IActionResult> AddProduct(AddProductModel addProductModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    BindDropdownForAddProduct(ref addProductModel);
                    return(View(addProductModel));
                }
                long customerId           = DBHelper.ParseInt64(Get(Constants.CustomerId));
                var  productModel         = ProductHelper.BindProductModel(addProductModel, customerId);
                var  productSizeModel     = ProductHelper.BindProductSizeModel(addProductModel);
                var  productColorModel    = ProductHelper.BindProductColorModel(addProductModel);
                var  productCategoryModel = ProductHelper.BindProductCategoryModel(addProductModel);
                var  productImageModel    = ProductHelper.BindProductImageModel(addProductModel);

                if (!addProductModel.ProductId.IsGreaterThenZero())
                {
                    long productId = iProduct.AddProduct(productModel, productCategoryModel, productColorModel, productImageModel, productSizeModel);
                    if (productId == RepositoryReturnCode.DataNotSaved.GetHashCode())
                    {
                        BindDropdownForAddProduct(ref addProductModel);
                        TempData[MessageConstant.ErrorMessage] = MessageConstant.ProductNotAdded;
                        return(View(addProductModel));
                    }
                    else if (productId.IsGreaterThenZero())
                    {
                        TempData[MessageConstant.SuccessMessage] = MessageConstant.ProductAdded;
                    }
                }
                else
                {
                    long productId = iProduct.UpdateProduct(productModel, productCategoryModel, productColorModel, productImageModel, productSizeModel);
                    if (productId == RepositoryReturnCode.DataNotSaved.GetHashCode())
                    {
                        BindDropdownForAddProduct(ref addProductModel);
                        TempData[MessageConstant.ErrorMessage] = MessageConstant.ProductNotUpdated;
                        return(View(addProductModel));
                    }
                    else if (productId.IsGreaterThenZero())
                    {
                        TempData[MessageConstant.SuccessMessage] = MessageConstant.ProductUpdated;
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                LogHelper.ExceptionLog(ex.Message + Constants.ExceptionSeprator + ex.StackTrace);
                throw ex;
            }
        }
Пример #21
0
        public void AddProductTest()
        {
            Product product = new Product(101, "Paint", 23.23);

            repository.AddProduct(product);
            Assert.AreEqual(1, repository.GetAllProduct().Count);
        }
        public async Task <IActionResult> AddProduct(ProductModel productmodel)
        {
            try
            {
                var result = await product.AddProduct(productmodel);

                return(this.Ok(new { result }));
            }
            catch (Exception ex)
            {
                return(this.BadRequest(ex.Message));
            }
        }
Пример #23
0
        public IActionResult AddProduct(MODELS.Product product)
        {
            var success = _bdlProduct.AddProduct(product);

            if (success == 1)
            {
                return(StatusCode((int)HttpStatusCode.Created, 1));
            }
            else
            {
                return(StatusCode((int)HttpStatusCode.BadRequest));
            }
        }
Пример #24
0
        public async Task <IActionResult> SaveProduct(AddOrUpdateProductVM model)
        {
            if (ModelState.IsValid)
            {
                string uniquefileName = null;
                if (model.Image != null)
                {
                    string uploadsFolder = Path.Combine(hosting.WebRootPath, "images");
                    uniquefileName = Guid.NewGuid().ToString() + "_" + model.Image.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniquefileName);
                    model.Image.CopyTo(new FileStream(filePath, FileMode.Create));
                }
                Product neki;
                if (model.ProductID == 0)
                {
                    neki = new Product();
                    _Iproduct.AddProduct(neki);
                }
                else
                {
                    neki = _database.product.Find(model.ProductID);
                }

                neki.ProductNumber  = model.ProductNumber;
                neki.SubCategoryID  = model.SubCategoryID;
                neki.ManufacturerID = model.ManufacturerID;
                neki.ProductName    = model.ProductName;
                neki.ImageUrl       = uniquefileName;
                neki.Description    = model.Description;
                neki.UnitPrice      = model.UnitPrice;
                neki.UnitsInStock   = model.UnitsInStock;

                await _database.SaveChangesAsync();

                if (model.ProductID != neki.ProductID)
                {
                    var st_pr = new StockProduct
                    {
                        StockID   = 1,
                        ProductID = neki.ProductID,
                        Quantity  = neki.UnitsInStock
                    };
                    _database.Add(st_pr);
                    await _database.SaveChangesAsync();
                }
            }
            await _notificationService.SendNotification($"Dodan je novi artikal ili je izmjenjen postojeći");

            return(Redirect("/Product/Show"));
        }
Пример #25
0
 public ActionResult PostProduct(Product product)
 {
     try
     {
         //Console.WriteLine(product);
         _product.AddProduct(product);
         //return new JsonResult(true);
         return(CreatedAtAction("GetProducts", new { id = product.ProductId }, product));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(new JsonResult(false));
     }
 }
        public async Task <IActionResult> AddProduct(ProductCreateModel model)
        {
            var product = new ProductModel
            {
                Id          = model.Id,
                Name        = model.Name,
                Description = model.Description,
                Category    = model.Category,
                Price       = model.Price,
                ImageUrl    = model.ImageUrl
            };

            await _productService.AddProduct(product);

            return(RedirectToAction("Index", "Product"));
        }
Пример #27
0
        public IActionResult AddProduct(Product product)
        {
            if (ModelState.IsValid)
            {
                if (Product.IsDuplicateName(product.Name))
                {
                    ModelState.AddModelError("", "This product already exists in the catalog.");
                    return(View(product));
                }

                Product newProduct = Product.AddProduct(product);
                CacheTryGetValueSet(newProduct.Id);
                return(RedirectToAction("Details", new { id = newProduct.Id }));
            }

            return(View());
        }
Пример #28
0
 public IActionResult Create(ProductDto customers, bool res)
 {
     try
     {
         _logger.LogWarning("اجرا متد ایجاد محصول جدید");
         _product.AddProduct(customers, res);
         if (res == false)
         {
             _logger.LogError("نام محصول تکراری است");
             return(BadRequest("product Name is Duplicate"));
         }
         _logger.LogInformation("محصول ایجاد شد");
         return(RedirectToAction("Index"));
     }
     catch (Exception)
     {
         throw;
     }
 }
Пример #29
0
        public ProductMutation(IProduct productService)
        {
            //Create product
            Field <ProductType>("createProduct", arguments: new QueryArguments(new QueryArgument <ProductInputType> {
                Name = "product"
            }),
                                resolve: context =>
            {
                return(productService.AddProduct(context.GetArgument <Product>("product")));
            });

            //Update product
            Field <ProductType>("updateProduct",
                                arguments:
                                new QueryArguments(
                                    new QueryArgument <IntGraphType> {
                Name = "id"
            },
                                    new QueryArgument <ProductInputType> {
                Name = "product"
            }),
                                resolve: context =>
            {
                return(productService.UpdateProduct(
                           context.GetArgument <int>("id"),
                           context.GetArgument <Product>("product")));
            });

            //Delete product. There is no void type and so return a string
            Field <StringGraphType>("deleteProduct",
                                    arguments:
                                    new QueryArguments(
                                        new QueryArgument <IntGraphType> {
                Name = "id"
            }),
                                    resolve: context =>
            {
                var productId = context.GetArgument <int>("id");
                productService.DeleteProduct(productId);
                return($"ProductId: {productId} has been deleted");
            });
        }
 public IActionResult AddProduct(ProductInputVM vm)
 {
     if (ModelState.IsValid)
     {
         string uniqueFileName = null;
         if (vm.Photo != null)
         {
             string UploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images");
             uniqueFileName = Path.GetFileName(vm.Photo.FileName);
             string filePath = Path.Combine(UploadsFolder, uniqueFileName);
             using (var fileStream = new FileStream(filePath, FileMode.Create))
             {
                 vm.Photo.CopyTo(fileStream);
             }
         }
         Product product = new Product
         {
             Name             = vm.Name,
             Price            = vm.Price,
             Quantity         = vm.Quantity,
             BrandId          = vm.BrandId.Value,
             CategoryId       = vm.CategoryId.Value,
             ProductImagePath = uniqueFileName
         };
         _reposProduct.AddProduct(product);
         var listOfSize = _reposSize.GetSizes();
         for (var s = 0; s < listOfSize.Count(); s++)
         {
             ProductSize productSize = new ProductSize
             {
                 ProductId = product.Id,
                 SizeId    = listOfSize[s].Id
             };
             _reposProductSize.Add(productSize);
         }
         return(RedirectToAction("ProductList", "Home"));
     }
     return(View(vm));
     //return RedirectToAction("AddProduct", "Admin");
 }