public ActionResult Create(ProductCreateViewModel model)
        {
            //var product = Mapper.Map<Product>(model);
            Product product = new Product()
            {
                Name       = model.Name,
                Code       = model.Code,
                CategoryId = model.CategoryId
            };

            try
            {
                if (ModelState.IsValid)
                {
                    productManager.Add(product);
                    //return RedirectToAction("Index");
                    ViewBag.message = "Product Added Sucessfully";
                }
            }
            catch (Exception ex)
            {
                ViewBag.message = ex.Message;
            }
            model.ProductCategoryLookUp = new SelectList(GetProductCategories(), "Id", "Name");
            model.Products = productManager.GetAll();
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult AddProduct(Product product)
        {
            var listItems = new CategoryListViewModel().GetCategoriesListItems();

            ViewBag.listItems = listItems;
            if (!ModelState.IsValid)
            {
                return(View("AddProduct"));
            }
            if (Request.Files.Count > 0)
            {
                string fileName  = $"{Guid.NewGuid()}{Path.GetFileName(Request.Files[0].FileName)}";
                string extension = Path.GetExtension(Request.Files[0].FileName);
                string filePath  = "~/Images/" + fileName + extension;
                Request.Files[0].SaveAs(Server.MapPath(filePath));
                if (extension == "")
                {
                    product.ProductImage = "~/Icons/no-image-icon-4.png";
                }
                else
                {
                    product.ProductImage = filePath;
                }
            }

            _productManager.Add(product);
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(ProductCreateViewModel entity, IFormFile Image)
        {
            if (ModelState.IsValid)
            {
                Product product = new Product()
                {
                    Name       = entity.Name,
                    Quantity   = entity.Quantity,
                    Code       = entity.Code,
                    Price      = entity.Price,
                    CategoryId = entity.CategoryId
                };

                if (Image.Length > 0)
                {
                    using (MemoryStream stream = new MemoryStream())
                    {
                        await Image.CopyToAsync(stream);

                        product.Image = stream.ToArray();
                    }
                }

                bool isSave = _productManager.Add(product);
                if (isSave)
                {
                    return(RedirectToAction("List"));
                }
            }
            return(View());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,Name,Price,ExpireDate,CategoryId,CategoryList,CategoryName,IsActive,Orders,ImagePath")] ProductVM model, IFormFile Image)
        {
            if (ModelState.IsValid)
            {
                var Product = _mapper.Map <Product>(model);

                using (var ms = new MemoryStream())
                {
                    Image.CopyTo(ms);
                    Product.Image = ms.ToArray();
                    // ImageConverter converter = new ImageConverter();
                    // model.Image = (byte[])converter.ConvertTo(Image, typeof(byte[]));
                }
                //test
                var files = HttpContext.Request.Form.Files;
                foreach (var image in files)
                {
                    if (image != null && image.Length > 0)
                    {
                        var file = Image;
                        // var root = _appEnvironment.WebRootPath;
                        var root    = "wwwroot\\";
                        var uploads = "uploads\\img";
                        if (file.Length > 0)
                        {
                            // you can change the Guid.NewGuid().ToString().Replace("-", "")
                            // to Guid.NewGuid().ToString("N") it will produce the same result
                            var fileName = Guid.NewGuid().ToString("N") + Path.GetExtension(file.FileName);

                            using (var fileStream = new FileStream(Path.Combine(root, uploads, fileName), FileMode.Create))
                            {
                                await file.CopyToAsync(fileStream);

                                // This will produce uploads\img\fileName.ext
                                Product.ImagePath = Path.Combine(uploads, fileName);
                            }
                        }
                    }
                }
                //test end
                bool isAdded = _productManager.Add(Product);
                if (isAdded)
                {
                    ViewBag.SuccessMessage = "Saved Successfully!";
                    //model.ProductList = _productManager.GetAll().ToList();
                    //VwBg();
                    return(RedirectToAction(nameof(Index), model.ProductList));
                }
            }
            else
            {
                ViewBag.ErrorMessage = "Operation Failed!";
            }

            model.ProductList  = _productManager.GetAll().ToList();
            model.CategoryList = _productManager.list().ToList();
            //VwBg();
            return(View(model));
        }
 public void Post([FromBody] Product product)
 {
     _productManager.Add(new Product
     {
         Name  = product.Name,
         Value = product.Value
     });
 }
        public Product PostProduct(Product product)
        {
            bool isSaved = _productManager.Add(product);

            if (isSaved)
            {
                return(product);
            }
            return(null);
        }
        public IActionResult AddProduct(Product item)
        {
            var result = _productManager.Add(item);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result.Message));
        }
Ejemplo n.º 8
0
        public IActionResult Post([FromBody] Product product)
        {
            if (ModelState.IsValid)
            {
                bool isAdded = _productManager.Add(product);
                return(Ok(product));
            }

            return(BadRequest());
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> PostProduct([FromBody] Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var resutl = _productManager.Add(product);

            return(Ok());
        }
 public IActionResult Post(Product product)
 {
     if (ModelState.IsValid)
     {
         var isAdded = _productManager.Add(product);
         if (isAdded)
         {
             return(Created("/api/products/" + product.Id, product));
         }
     }
     return(BadRequest(ModelState));
 }
Ejemplo n.º 11
0
 public IActionResult Add([FromBody] ProductDTO productDto)
 {
     try
     {
         _productManager.Add(productDto);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Ejemplo n.º 12
0
        public async Task <ProductResponse> Add(ProductRequest request)
        {
            var response   = new ProductResponse();
            var methodInfo = nameof(Add).MethodInfo(MethodBase.GetCurrentMethod());

            await RunCodeAsync(methodInfo, request, response, async (uow) =>
            {
                await _manager.Add(request, response);
            });

            return(response);
        }
Ejemplo n.º 13
0
        public ActionResult Create(Product entity)
        {
            try
            {
                _productManager.Add(entity);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
 public IActionResult Create(ProductCreateVM model)
 {
     if (ModelState.IsValid)
     {
         Product product = _mapper.Map <Product>(model);
         bool    isSaved = _productManager.Add(product);
         if (isSaved)
         {
             return(RedirectToAction(nameof(Index)));
         }
     }
     return(View());
 }
Ejemplo n.º 15
0
        private void Handle(AddMessage message)
        {
            //Debugger.Launch();
            string result  = "";
            var    _sender = Sender;

            result = _productManager.Add((Product)message.Value);
            if (!string.IsNullOrEmpty(result))
            {//Ard arda  3 tane worker actor gönderildiğinde actor çalışmakta , 4. actor de ise kuyrukta beklemekte.
                Thread.Sleep(3 * 1000);
            }
            _sender.Tell(result);
        }
        public ActionResult Create(Product product)
        {
            try
            {
                ViewBag.Categories = new SelectList(_categoryManager.GetAll().ToList(), "Id", "Name");
                _productManager.Add(product);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> Post(Product product)
        {
            if (ModelState.IsValid)
            {
                bool isAdded = await _productManager.Add(product);

                if (isAdded)
                {
                    return(Created("/api/products" + product.Id, product));
                }
            }

            return(BadRequest(ModelState));
        }
Ejemplo n.º 18
0
        public IActionResult Post([FromBody] ProductDto model)
        {
            if (ModelState.IsValid)
            {
                var  product = _mapper.Map <Product>(model);
                bool isAdded = _productManager.Add(product);
                if (isAdded)
                {
                    return(Ok(product));
                }

                return(BadRequest(new { error = "Failed to Add!" }));
            }

            return(BadRequest(new { error = "Model Sate is Not Valid! " }));
        }
Ejemplo n.º 19
0
        public ActionResult Create([Bind(include: "Id,Name,Price,Size,ProductModel," +
                                         "Image,Description,CatagoriesId,Catagories,SubCategoriesId,SubCategories")] ProductViewModel model)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    var product = new Product();
                    product.Id           = model.Id;
                    product.Name         = model.Name;
                    product.Price        = model.Price;
                    product.Size         = model.Size;
                    product.ProductModel = model.ProductModel;

                    product.Description     = model.Description;
                    product.CatagoriesId    = model.CatagoriesId;
                    product.Catagories      = model.Catagories;
                    product.SubCategoriesId = model.SubCategoriesId;
                    product.SubCategories   = model.SubCategories;
                    string uniquefileName = null;
                    if (model.Image != null)
                    {
                        string uploadsfolder = Path.Combine(_hostingEnvironment.WebRootPath, "img");
                        uniquefileName = Guid.NewGuid().ToString() + "_" + model.Image.FileName;
                        string filePath = Path.Combine(uploadsfolder, uniquefileName);
                        model.Image.CopyTo(new FileStream(filePath, FileMode.Create));
                    }

                    product.Image = uniquefileName;
                    var success = _productManager.Add(product);
                    if (success)
                    {
                        return(RedirectToAction(nameof(Index)));
                    }

                    return(View(model));
                }

                return(View(model));
            }
            catch
            {
                return(View());
            }
        }
 private void SaveExecute()
 {
     //_products.Add(_product);
     try
     {
         _product.Id         = null;
         _product.CreateTime = DateTime.Now;
         _productManager.Add(_product);
         //XmlHelper.XmlSerializeToFile(_products, Utils.DateFilePath, System.Text.Encoding.UTF8);
         OnSaveCompleted(_product, new EventArgs());
     }
     catch (Exception e)
     {
         Utils.LogError(e.Message, e);
         //throw;
     }
 }
Ejemplo n.º 21
0
        public IActionResult Create(Product aProduct)
        {
            if (ModelState.IsValid)
            {
                bool isCreate = _iProductManager.Add(aProduct);

                if (isCreate)
                {
                    return(RedirectToActionPermanent("Index"));
                }
                else
                {
                    ViewBag.ErrorMessage = "Product has been saved failed! Try again.";
                }
            }

            ViewBag.CategoryList = CategoryList();
            return(View(aProduct));
        }
Ejemplo n.º 22
0
        public IActionResult Add(ViewModel_Product model)
        {
            try
            {
                var product = _mapper.Map <Product>(model);
                if (ModelState.IsValid)
                {
                    bool isAdded = _productManager.Add(product);
                    if (isAdded)
                    {
                        return(RedirectToAction(nameof(ViewProducts)));
                    }
                }

                return(View());
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 23
0
        public ActionResult Create(ProductCreateViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var product = _mapper.Map <Product>(model);

                    bool isAdded = _productManager.Add(product);
                    if (isAdded)
                    {
                        return(RedirectToAction(nameof(Index)));
                    }
                }

                return(View());
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> Create(Product product, List <IFormFile> file)
        {
            if (ModelState.IsValid)
            {
                foreach (var item in file)
                {
                    if (item.Length > 0)
                    {
                        using (var stream = new MemoryStream())
                        {
                            await item.CopyToAsync(stream);

                            product.Image = stream.ToArray();
                        }
                    }
                }

                await _productRepository.Add(product);
            }

            PopulateCategory(product.CategoryId);
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Create(ProductCreateViewModel model, List <IFormFile> ImageUrl)
        {
            if (ModelState.IsValid)
            {
                var product = _mapper.Map <Product>(model); //AutoMapper

                /*Save Images start*/
                foreach (var item in ImageUrl)
                {
                    if (item.Length > 0)
                    {
                        using (var ms = new MemoryStream())
                        {
                            await item.CopyToAsync(ms);

                            product.ImageUrl = ms.ToArray();

                            bool isAdded = _productManager.Add(product);
                            if (isAdded)
                            {
                                ViewBag.SuccessMessage = "Saved Successfully!";
                            }
                        }
                    }
                }
                /*Image save End*/
            }
            else
            {
                ViewBag.ErrorMessage = "Operation Failed!";
            }

            model.ProductList = _productManager.GetAll().ToList();
            PopulateDropdownList(model.CategoryId); /*Dropdown List Binding*/
            return(View(model));
        }
Ejemplo n.º 26
0
 public IActionResult Create(Product product)
 {
     _productManager.Add(product);
     return(RedirectToAction("List"));
 }
Ejemplo n.º 27
0
 public void Post(Product product)
 {
     _productManger.Add(product);
 }
Ejemplo n.º 28
0
 public Product AddProduct(Product product)
 {
     product = prodManager.Add(product);
     return(product);
 }
Ejemplo n.º 29
0
        public async Task <IActionResult> Create(ProductCreateViewModel model, IFormFile ImageUrl /*List<IFormFile> ImageUrl*/)
        {
            if (ModelState.IsValid)
            {
                var product = _mapper.Map <Product>(model); //AutoMapper

                /*Save Images start*/


                using (var ms = new MemoryStream())
                {
                    ImageUrl.CopyTo(ms);
                    product.ImageUrl = ms.ToArray();
                    // ImageConverter converter = new ImageConverter();
                    // model.Image = (byte[])converter.ConvertTo(Image, typeof(byte[]));
                }
                //test
                var files = HttpContext.Request.Form.Files;
                foreach (var image in files)
                {
                    if (image != null && image.Length > 0)
                    {
                        var file = ImageUrl;
                        // var root = _appEnvironment.WebRootPath;
                        var root    = "wwwroot\\";
                        var uploads = "uploads\\img";
                        if (file.Length > 0)
                        {
                            // you can change the Guid.NewGuid().ToString().Replace("-", "")
                            // to Guid.NewGuid().ToString("N") it will produce the same result
                            var fileName = Guid.NewGuid().ToString("N") + Path.GetExtension(file.FileName);

                            using (var fileStream = new FileStream(Path.Combine(root, uploads, fileName), FileMode.Create))
                            {
                                await file.CopyToAsync(fileStream);

                                // This will produce uploads\img\fileName.ext
                                product.ImagePath = Path.Combine(uploads, fileName);
                            }
                        }
                    }
                }
                bool isAdded = _productManager.Add(product);
                if (isAdded)
                {
                    ViewBag.SuccessMessage = "Saved Successfully!";
                }
                //foreach (var item in ImageUrl)
                //{
                //    if(item.Length>0)
                //    {
                //        using (var ms = new MemoryStream())
                //        {
                //            await item.CopyToAsync(ms);
                //            product.ImageUrl = ms.ToArray();

                //            bool isAdded = _productManager.Add(product);
                //            if (isAdded)
                //            {
                //                ViewBag.SuccessMessage = "Saved Successfully!";
                //            }
                //        }
                //    }

                //}
                /*Image save End*/
            }
            else
            {
                ViewBag.ErrorMessage = "Operation Failed!";
            }

            model.ProductList = _productManager.GetAll().ToList();
            PopulateDropdownList(model.CategoryId); /*Dropdown List Binding*/
            return(View(model));
        }