コード例 #1
0
        public IActionResult Post(PhotoGallery data)
        {
            data.isActive = true;
            var createdAbout = service.Add(data);

            return(CreatedAtAction("Get", new { id = createdAbout.Data.Id }, createdAbout));
        }
コード例 #2
0
        public async Task <IActionResult> ImageUpload(PhotoGallery photoGallery, IFormFile file)
        {
            GalleryViewModel mymodel = new GalleryViewModel();

            if (file is null)
            {
                mymodel.PhotoCategories = photoCategoryService.GetAll().Data;
                mymodel.PhotoGalleries  = photoGalleryService.GetAll().Data;
                return(View(mymodel));
            }
            string rootPath = env.WebRootPath;

            if (!Directory.Exists(rootPath))//Dosya Klasörü Daha Önce Oluşturulmamışsa
            {
                System.IO.Directory.CreateDirectory(rootPath);
            }
            string uzanti   = file.FileName.Split(".")[1];
            string dosyaAdi = Guid.NewGuid().ToString() + "." + uzanti;
            var    filePath = rootPath + "/Images/" + dosyaAdi;

            if (file.Length > 0)
            {
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await file.CopyToAsync(stream);
                }
            }
            photoGallery.imageUrl = "/Images/" + dosyaAdi;
            var result = photoGalleryService.Add(photoGallery);

            TempData["Mesaj"] = result.BasariliMi ? "Kayıt Eklendi." : result.Mesaj;

            mymodel.PhotoCategories = photoCategoryService.GetAll().Data;
            mymodel.PhotoGalleries  = photoGalleryService.GetAll().Data;
            return(View(mymodel));
        }