コード例 #1
0
        public IActionResult Create(TrackCreateViewModel model)
        {
            string name = model.Name;
            string link = model.Link;

            if (link.Contains("watch?v="))
            {
                link = model.Link.Replace("watch?v=", "embed/");
            }

            decimal price   = model.Price;
            string  albumId = model.AlbumId;

            if (!this.albumService.ExistsById(albumId))
            {
                var errorViewContent = File.ReadAllText(GlobalConstants.ErrorViewPath);
                errorViewContent = errorViewContent.Replace(GlobalConstants.ErrorModel, NonexistingAlbumErrorMessage);
                return(this.ThrowError(errorViewContent));
            }

            try
            {
                this.trackService.CreateTrack(name, link, price, albumId);
            }
            catch (System.Exception e)
            {
                var errorViewContent = File.ReadAllText(GlobalConstants.ErrorViewPath);
                errorViewContent = errorViewContent.Replace(GlobalConstants.ErrorModel, e.Message);
                return(this.ThrowError(errorViewContent));
            }

            return(this.Redirect($"/Albums/Details?id={albumId}"));
        }
コード例 #2
0
        public IActionResult Create(string albumId)
        {
            var trackCreateViewModel = new TrackCreateViewModel {
                AlbumId = albumId
            };

            return(this.View(trackCreateViewModel));
        }
コード例 #3
0
        public HttpResponse Create(string albumId)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            var trackCreateViewModel = new TrackCreateViewModel
            {
                AlbumId = albumId
            };

            return(this.View(trackCreateViewModel));
        }
コード例 #4
0
        public ActionResult Create()
        {
            var date         = DateTime.Now;
            var testTraining = new TrainingCreateViewModel()
            {
                Title     = "Test Training 1",
                StartDate = date,
                EndDate   = date.AddHours(5),
            };

            var testTrack = new TrackCreateViewModel()
            {
                Title        = "Test track 1",
                Ascent       = 2500,
                Length       = 80,
                AscentLength = 45,
            };

            testTraining.Track = testTrack;

            return(this.View(testTraining));
        }
コード例 #5
0
        public async Task <IActionResult> UploadTrack(TrackCreateViewModel viewmodel)
        {
            var user = await GetCurrentUserAsync();

            var fileName = Path.GetFileName(viewmodel.AudioFile.FileName);

            Path.GetTempFileName();
            var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\audio", fileName);

            using (var stream = new FileStream(filePath, FileMode.Create))
            {
                await viewmodel.AudioFile.CopyToAsync(stream);
            }

            viewmodel.Track.FilePath = viewmodel.AudioFile.FileName;

            viewmodel.Track.UserId = user.Id;
            _context.Add(viewmodel.Track);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Tracks", new { id = viewmodel.Track.ProjectId }));
        }
コード例 #6
0
        public async Task <IActionResult> UploadTrack(int id)
        {
            var user = await GetCurrentUserAsync();

            var project = await _context.Project.Include(p => p.ProjectUsers)
                          .FirstOrDefaultAsync(p => p.ProjectId == id);

            bool isAuth = false;

            foreach (ProjectUser projectUser in project.ProjectUsers)
            {
                if (projectUser.UserId == user.Id)
                {
                    isAuth = true;
                }
            }

            if (isAuth == false)
            {
                return(RedirectToAction("Index"));
            }

            ViewBag.ProjectId      = id;
            ViewBag.ArtistName     = project.ArtistName;
            ViewBag.ProjectTitle   = project.Title;
            ViewBag.ImagePath      = project.ImagePath;
            ViewBag.IsProjectOwner = await IsProjectOwnerAsync(id);

            var viewmodel = new TrackCreateViewModel
            {
                Track = new Track
                {
                    ProjectId = id
                }
            };

            return(View(viewmodel));
        }
コード例 #7
0
        public IActionResult Create(TrackCreateViewModel model)
        {
            if (!this.Request.QueryData.ContainsKey("albumId"))
            {
                return(new RedirectResult("/Album/All"));
            }

            var albumId = int.Parse(this.Request.QueryData["albumId"].ToString());
            var album   = this.albumService.GetAlbum(albumId);

            if (album == null)
            {
                return(new RedirectResult("/Album/All"));
            }

            var name  = model.Name.UrlDecode();
            var link  = model.Link.UrlDecode();
            var price = model.Price;

            if (this.trackService.ContainsTrack(name))
            {
                //this.Model.Data["ErrorViewModel"] = new ErrorViewModel
                //{
                //    DisplayError = Inline,
                //    ErrorMessage = TrackAlreadyExists
                //};
                //TODO:


                return(this.View());
            }

            this.trackService.AddTrack(name, link, price, albumId);

            return(new RedirectResult($"/Album/Details?id={albumId}"));
        }
コード例 #8
0
        public ActionResult Create()
        {
            var date = DateTime.Now;
            var testTraining = new TrainingCreateViewModel()
            {
                Title = "Test Training 1",
                StartDate = date,
                EndDate = date.AddHours(5),
            };

            var testTrack = new TrackCreateViewModel()
            {
                Title = "Test track 1",
                Ascent = 2500,
                Length = 80,
                AscentLength = 45,
            };

            testTraining.Track = testTrack;

            return this.View(testTraining);
        }