Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("ID,Title,Price")] Album album)
        {
            if (ModelState.IsValid)
            {
                _context.Add(album);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(album));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,BioInfo,WebsiteUrl")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("ID,Title,BPM,Key,Price")] Beat beat)
        {
            if (ModelState.IsValid)
            {
                var imgExtensions   = new[] { ".png", ".jpg", ".gif" };
                var musicExtensions = new[] { ".mp3", ".wav", ".mp4" };
                var files           = HttpContext.Request.Form.Files;
                foreach (var BeatFile in files)
                {
                    if (BeatFile != null && BeatFile.Length > 0)
                    {
                        var file = BeatFile;

                        if (file.Length > 0)
                        {
                            var fileName = Guid.NewGuid().ToString() +
                                           System.IO.Path.GetExtension(file.FileName);

                            var uploads = "";
                            if (imgExtensions.Contains(Path.GetExtension(file.FileName)))
                            {
                                uploads = Path.Combine(_hostingEnvironment.WebRootPath, "images/songs/");
                                System.Console.WriteLine(fileName);
                                using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create))
                                {
                                    await file.CopyToAsync(fileStream);

                                    beat.ArtFilePath = $"/images/songs/{fileName}";
                                }
                            }
                            else if (musicExtensions.Contains(Path.GetExtension(file.FileName)))
                            {
                                uploads = Path.Combine(_hostingEnvironment.WebRootPath, "media/beats/");
                                System.Console.WriteLine(fileName);
                                using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create))
                                {
                                    await file.CopyToAsync(fileStream);

                                    beat.BeatFilePath = $"/media/beats/{fileName}";
                                }
                            }
                        }
                    }
                }
                beat.ArtistID = new Random().Next(1, 5);
                _context.Add(beat);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Details), new { id = beat.ID }));
            }
            return(View(beat));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("ID,Name,UserName")] User user)
        {
            if (ModelState.IsValid)
            {
                var files = HttpContext.Request.Form.Files;
                foreach (var Image in files)
                {
                    if (Image != null && Image.Length > 0)
                    {
                        var file    = Image;
                        var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "images/users/profile");

                        if (file.Length > 0)
                        {
                            var fileName = Guid.NewGuid().ToString() +
                                           System.IO.Path.GetExtension(file.FileName);

                            System.Console.WriteLine(fileName);
                            using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create))
                            {
                                await file.CopyToAsync(fileStream);

                                if (Image.Name.Equals("headerPic"))
                                {
                                    user.HeaderImagePath = $"/images/users/profile/{fileName}";
                                }
                                else
                                {
                                    user.ProfileImagePath = $"/images/users/profile/{fileName}";
                                }
                            }
                        }
                    }
                }



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

                return(RedirectToAction(nameof(Details), new { id = user.ID }));
            }
            return(View(user));
        }