public async Task <IActionResult> Create([Bind("ID,name,image,image_desc,desc,skills,phone,email,place,map")] Personal personal)
        {
            if (ModelState.IsValid)
            {
                var files = HttpContext.Request.Form.Files;
                foreach (var Image in files)
                {
                    if (Image != null && Image.Length > 0)
                    {
                        var file = Image;
                        //There is an error here
                        var uploads = Path.Combine(_appEnvironment.WebRootPath, "img");
                        if (file.Length > 0)
                        {
                            var fileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(file.FileName);
                            using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create))
                            {
                                await file.CopyToAsync(fileStream);

                                personal.image = fileName;
                            }
                        }
                    }
                }
                _context.Add(personal);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            TempData["Changed"] = 1;
            return(View(personal));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("ID,name,desc,status,end")] Jobs jobs)
        {
            if (ModelState.IsValid)
            {
                _context.Add(jobs);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            TempData["Message"] = 1;
            return(View(jobs));
        }