Example #1
0
        public async Task <IActionResult> Create([Bind("Id,Date,FirstName,LastName,Patronymic,Email,Salary,PicturePathId")] Workers workers)
        {
            if (ModelState.IsValid)
            {
                _context.Add(workers);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PicturePathId"] = new SelectList(_context.Picture, "Id", "Id", workers.PicturePathId);
            return(View(workers));
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("Id,PicturePath")] Picture picture, IFormFile uploadedFile)
        {
            //"C:\\Users\\VITALIY\\source\repos\\EmployeeRegistration\\EmployeeRegistration\\wwwroot\\img\\"s
            string pathCloud = "";

            if (uploadedFile != null)
            {
                // путь к папке Files
                string path = "/files/" + uploadedFile.FileName;
                pathCloud = path;
                // сохраняем файл в папку Files в каталоге wwwroot
                using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                {
                    await uploadedFile.CopyToAsync(fileStream);
                }
                FileModel file = new FileModel {
                    Name = uploadedFile.FileName, Path = path
                };
            }
            pathCloud = _appEnvironment.WebRootPath + pathCloud;
            Account account = new Account(cloud_name, api_key, api_secret);

            cloudinary = new Cloudinary(account);
            var uploadResult = uploadIMG(pathCloud);

            //Console.WriteLine("asdasd " + picture.PicturePath);

            /*
             * var uploadParams = new VideoUploadParams()
             * {
             *  File = new FileDescription(@"C:\Users\VITALIY\source\repos\EmployeeRegistration\EmployeeRegistration\wwwroot\img\" + picture.PicturePath),
             *  PublicId = "Home/workers/" + picture.PicturePath,
             *  Overwrite = true,
             *  NotificationUrl = "https://mysite/my_notification_endpoint"
             * };
             * var uploadResult = cloudinary.Upload(uploadParams);
             */

            picture.PicturePath = uploadResult.Uri.ToString();
            if (ModelState.IsValid)
            {
                _context.Add(picture);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(picture));
        }