コード例 #1
0
        public IActionResult Add(AddCatalogModel catalog)
        {
            if (ModelState.IsValid)
            {
                CatalogModel catalogModel = new CatalogModel();

                if (catalog.ImageURL != null)
                {
                    var type         = Path.GetExtension(catalog.ImageURL.FileName);
                    var newImageName = Guid.NewGuid() + type;

                    var NewImagePath = Path.Combine(Directory.GetCurrentDirectory(),
                                                    "wwwroot/images/product/" + newImageName);
                    var stream = new FileStream(NewImagePath, FileMode.Create);

                    //resmi NewImagePath adresine kopyaladık
                    catalog.ImageURL.CopyTo(stream);
                    catalogModel.ImageFile = newImageName;
                }

                catalogModel.Name        = catalog.Name;
                catalogModel.Description = catalog.Description;
                catalogModel.Price       = catalog.Price;
                catalogModel.Category    = catalog.Category;
                catalogModel.Summary     = catalog.Summary;

                _catalogApi.CreateCatalog(catalogModel);
                return(RedirectToAction("Index", "Home", new { area = "Admin" }));
            }
            return(View(catalog));
        }