Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("ID,Artist,Name,Genre,ReleaseDate,Price,Rank")] Album album)
        {
            if (ModelState.IsValid)
            {
                _context.Add(album);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(album));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Email,PhotoName,ShareName")] Shared shared)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shared);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(shared));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,PhotoName,ImageFile,Date")] MyPhotos myPhotos)
        {
            if (ModelState.IsValid)
            {
                String wwwRootPath  = _hostEnvironment.WebRootPath;
                string fileName     = Path.GetFileNameWithoutExtension(myPhotos.ImageFile.FileName);
                string extensioName = Path.GetExtension(myPhotos.ImageFile.FileName);
                myPhotos.PhotoName = fileName = fileName + extensioName;
                string path = Path.Combine(wwwRootPath + "/Image/", fileName);
                myPhotos.Url   = path;
                myPhotos.Email = @User.Identity.Name;
                using (var fileStream = new FileStream(path, FileMode.Create)) {
                    await myPhotos.ImageFile.CopyToAsync(fileStream);
                }



                _context.Add(myPhotos);
                await _context.SaveChangesAsync();

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