示例#1
0
        public IActionResult AddProduct(Product product)
        {
            _productRepo.AddProduct(product);
            _productRepo.CommitChanges();

            return(Accepted(product));
        }
示例#2
0
        public Response <string> AddProductAsync <T>(ProductModel model, T t)
        {
            string  imageName = UploadImageAsync(model.proImageStream);
            Product product   = _mapper.Map <Product>(model);

            product.DateCreated = DateTime.Now;
            product.ProStatus   = false;
            product.ProImage    = imageName;
            int proId = _repo.AddProduct(product);

            Type type = typeof(T);

            PropertyInfo[] properties = type.GetProperties();
            foreach (PropertyInfo property in properties)
            {
                string[]         _specInfo = FileManager.StringSeparator(property.GetValue(t, null).ToString(), "//");
                ProSpecification spec      = new ProSpecification()
                {
                    ProId     = proId,
                    SpecId    = Int16.Parse(_specInfo[0]),
                    SpecValue = _specInfo[1]
                };
                _repo.AddProductSpec(spec);
                _repo.SaveChanges();
            }
            Response <string> res = new Response <string>()
            {
                IsSuccess = true,
                Code      = "200",
                Message   = "Thêm sản phẩm thành công",
                Data      = "/admin/addvariant?pid=" + proId
            };

            return(res);
        }
示例#3
0
 public IActionResult Post([FromBody] ProductItem obj)
 {
     if (iproduct.AddProduct(obj))
     {
         return(Ok());
     }
     return(BadRequest());
 }
 //To Add new Product record
 public async Task AddProduct(ProductModel Product)
 {
     try
     {
         await _iProductRepo.AddProduct(Product);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
        public IActionResult AddProduct(ProductCreateVM model)
        {
            //string uniqFileName = null;

            if (model.photo != null)
            {
                productRepo.AddProduct(model);
                return(RedirectToAction("AddProduct"));
            }

            return(RedirectToAction("ManageProducts"));
        }
示例#6
0
        public async Task <ProductModel> AddProduct(ProductModel product)
        {
            product.Validate();
            var products = await _productRepo.GetProduct(product.ProductId);

            if (products.ProductId != 0)
            {
                return(await _productRepo.UpdateProduct(product));
            }
            else
            {
                return(await _productRepo.AddProduct(product));
            }
        }
示例#7
0
        public IActionResult AddProduct([FromBody] ProductForCreationDto product)
        {
            if (product == null)
            {
                return(BadRequest());
            }

            var productForEntity = Mapper.Map <Products>(product);

            _product.AddProduct(productForEntity);
            if (!_product.Save())
            {
                throw new Exception($"Product Creation failed on save");
            }

            var productToReturn = Mapper.Map <Products>(productForEntity);

            return(CreatedAtRoute("GetProduct", new { id = productToReturn.Id }, productToReturn));
        }
示例#8
0
        public IActionResult AddProduct(ProductCreateVM model)

        {
            //string uniqFileName = null;



            if (model.photoOne != null)

            {
                productRepo.AddProduct(model);

                //return RedirectToAction("AddProduct");
                return(View());
            }



            return(RedirectToAction("index"));
        }
示例#9
0
 public void AddProduct(Product newProduct)
 {
     repo.AddProduct(newProduct);
 }
示例#10
0
 public bool Post(Products product)
 {
     productRepo.AddProduct(product);
     return(true);
 }
 public void AddProduct(Product product)
 {
     repo.AddProduct(product);
 }
 public void AddProduct(Product p)
 {
     repo.AddProduct(p);
 }
示例#13
0
        public void AddProduct(ProductDto product, string type)
        {
            // TODO replace this path with absolute path of your PC
            string path = @"E:\Project\VehicleManager\Project\website\Image";

            DirectoryInfo dir = new DirectoryInfo(path);

            if (dir.Exists)
            {
                string img1    = Path.GetFileName(product.Image1);
                string desImg1 = Path.Combine(path, img1);
                if (!File.Exists(desImg1))
                {
                    File.Copy(product.Image1, desImg1, true);
                }
                product.Image1 = desImg1;

                if (product.Image2 != null)
                {
                    string img2    = Path.GetFileName(product.Image2);
                    string desImg2 = Path.Combine(path, img2);
                    if (!File.Exists(desImg2))
                    {
                        File.Copy(product.Image2, desImg2, true);
                    }
                    product.Image2 = desImg2;
                }
                if (product.Image3 != null)
                {
                    string img3    = Path.GetFileName(product.Image3);
                    string desImg3 = Path.Combine(path, img3);
                    if (!File.Exists(desImg3))
                    {
                        File.Copy(product.Image3, desImg3, true);
                    }
                    product.Image3 = desImg3;
                }
                if (product.Image4 != null)
                {
                    string img4    = Path.GetFileName(product.Image4);
                    string desImg4 = Path.Combine(path, img4);
                    if (!File.Exists(desImg4))
                    {
                        File.Copy(product.Image4, desImg4, true);
                    }
                    product.Image4 = desImg4;
                }
                if (product.Image5 != null)
                {
                    string img5    = Path.GetFileName(product.Image5);
                    string desImg5 = Path.Combine(path, img5);
                    if (!File.Exists(desImg5))
                    {
                        File.Copy(product.Image5, desImg5, true);
                    }
                    product.Image5 = desImg5;
                }
            }

            _repository.AddProduct(product, type);
        }
示例#14
0
 public HttpResponseMessage AddProduct(Product product)
 {
     _productRepo.AddProduct(product);
     return(Request.CreateResponse(HttpStatusCode.Created, new { Response = "Product Added" }));
 }