public ActionResult Create([Bind(Include = "ProductID,ProductName,Image,BaoHanh,MauSac,Price,UnitPrice,Description,Quantity,CategoryID")] Product product)
 {
     try
     {
         //if (ModelState.IsValid)
         //{
         product.Image = "";
         var f = Request.Files["ImageFile"];
         if (f != null && f.ContentLength > 0)
         {
             string FileName   = System.IO.Path.GetFileName(f.FileName);
             string UploadPath = Server.MapPath("~/wwwroot/Image/" + FileName);
             f.SaveAs(UploadPath);
             product.Image = FileName;
         }
         _product.Create(product);
         //}
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         ViewBag.Error      = "Lỗi nhập dữ liệu" + ex.Message;
         ViewBag.CategoryID = new SelectList(_category.GetAll(), "CategoryID", "CategoryName");
         return(View(product));
     }
 }
Example #2
0
        public bool CreateProduct(ProductCreateDto productDto)
        {
            if (productDto == null)
            {
                return(false);
            }
            var productEntity = _mapper.Map <Product>(productDto);

            _productServices.Create(productEntity);
            return(true);
        }
Example #3
0
 public IActionResult Post([FromForm] ProductEntity newProduct)
 {
     try
     {
         _services.Create(newProduct);
         return(Ok());
     }
     catch
     {
         throw;
     }
 }
Example #4
0
        public void Create(ProductCreateDTO productCreateDTO)
        {
            productServices.Create(productCreateDTO);

            var entry = new Activity
            {
                Id        = Guid.NewGuid(),
                CreatedOn = DateTime.Now,
                Operation = "CreateProduct",
                Data      = JsonConvert.SerializeObject(productCreateDTO)
            };

            //Persist the Activity
        }
Example #5
0
        public IActionResult ProductCreate(ProductModel model)
        {
            var entity = new Product()
            {
                Name        = model.Name,
                Url         = model.Url,
                Author      = model.Author,
                Pages       = model.Pages,
                Description = model.Description,
                ImageUrl    = model.ImageUrl,
            };

            _productServices.Create(entity);
            return(RedirectToAction("ProductList"));
        }
Example #6
0
        public IActionResult Create(CreateProductBindingModel createProduct)
        {
            if (!ModelState.IsValid)
            {
                return(Redirect("/"));
            }
            string pictureUrl = this._cloudinaryService.UploadPictureAsync(
                createProduct.Picture,
                createProduct.Title);

            productServices.Create(createProduct.Title, createProduct.ProductTypes, createProduct.Price,
                                   createProduct.Quantity, createProduct.Description, createProduct.Author, createProduct.Publishing,
                                   createProduct.YearOfPublishing, pictureUrl, createProduct.YouTubeLink, createProduct.GenreId);
            return(this.Redirect("/"));
        }
Example #7
0
 public IActionResult Post([FromBody] ProductEntity model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest("Modelo no válido."));
         }
         _services.Create(model);
         return(Ok(model));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, "Ocurrio un error al crear el producto. " + ex.Message));
     }
     finally
     {
         model = null;
     }
 }
Example #8
0
        public async Task <IActionResult> Post([FromBody] PriceCreateDto priceDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            Location location = await _locationServices.GetByName(priceDto.Location).ConfigureAwait(false);

            if (location == null)
            {
                location            = _mapper.Map <Location>(priceDto);
                location.LocationId = await this._locationServices.Create(location).ConfigureAwait(false);
            }

            Product product = this._productServices.GetById(priceDto.PluCode);

            if (product == null)
            {
                product = _mapper.Map <Product>(priceDto);
                await _productServices.Create(product).ConfigureAwait(false);
            }

            Price price = null;

            if (await _priceServices.CheckIfExists(product.ProductId, location.LocationId).ConfigureAwait(false) == null)
            {
                price            = _mapper.Map <Price>(priceDto);
                price.LocationId = location.LocationId;
                price.ProductId  = product.ProductId;
                price.UserId     = User.Identity.Name;
                price.PriceId    = await _priceServices.Create(price).ConfigureAwait(false);
            }

            if (price != null)
            {
                return(Ok(price));
            }

            return(Conflict(new { message = "Price already exists" }));
        }
        public IActionResult ProductCreate(ProductModel model)
        {
            var entity = new Product()
            {
                Name        = model.Name,
                Url         = model.Url,
                Author      = model.Author,
                Pages       = model.Pages,
                Description = model.Description,
                ImageUrl    = model.ImageUrl,
            };

            _productServices.Create(entity);
            var msg = new AlertMessage()
            {
                Message   = $"{entity.Name} isimli ürün eklendi",
                AlertType = "success"
            };

            TempData["message"] = JsonConvert.SerializeObject(msg);
            return(RedirectToAction("ProductList"));
        }
Example #10
0
        public async Task <IActionResult> ProductCreate(ProductModel productModel, int[] categories, IFormFile formFile)
        {
            var entity = new Product()
            {
                Title       = productModel.Title,
                Description = productModel.Description,
            };

            if (formFile != null)
            {
                var extention  = Path.GetExtension(formFile.FileName);
                var randomName = string.Format($"{Guid.NewGuid()}{extention}");
                entity.Image = randomName;
                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\img", randomName);

                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await formFile.CopyToAsync(stream);
                }
            }
            _productServices.Create(entity, categories);
            return(RedirectToAction("ProductList"));
        }
Example #11
0
 public ProductDTO Post([FromBody] ProductDTO productEntity)
 {
     return(_productServices.Create(productEntity));
 }