public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Age,Gender,Sexuality,ImageFile,Presentation,IsActive")] ProfileModel profileModel)
        {
            if (ModelState.IsValid)
            {
                //Vi sparar vår bild till foldern Image i wwwroot
                string wwwPath   = _hostEnvironment.WebRootPath;
                string file      = Path.GetFileNameWithoutExtension(profileModel.ImageFile.FileName);
                string extension = Path.GetExtension(profileModel.ImageFile.FileName);
                profileModel.ImageFilepath = file = file + DateTime.Now.ToString("yymmddss") + extension;
                string path = Path.Combine(wwwPath + "/Image/", file);
                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    await profileModel.ImageFile.CopyToAsync(fileStream);
                }

                //Lägger till det vi sparat
                _context.Add(profileModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(profileModel));
        }
Esempio n. 2
0
 public void Add <T>(T entity) where T : class
 {
     _datingDbContext.Add(entity);
 }