public HttpResponse Create(CreateTrackInputModel input)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (input.Name.Length < 4 || input.Name.Length > 20)
            {
                return(this.Error("Track name should be between 4 and 20 characters."));
            }

            if (!input.Link.StartsWith("http"))
            {
                return(this.Error("Invalid link."));
            }

            if (input.Price < 0)
            {
                return(this.Error("Price should be a positive number."));
            }

            this.tracksService.Create(input.AlbumId, input.Name, input.Link, input.Price);
            return(this.Redirect("/Albums/Details?id=" + input.AlbumId));
        }
Exemplo n.º 2
0
        public HttpResponse Create(CreateTrackInputModel input)
        {
            if (!IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (input.Name.Length <= 4 || input.Name.Length > 10)
            {
                return(this.Redirect("/Tracks/Create"));
            }

            if (string.IsNullOrWhiteSpace(input.Link))
            {
                return(this.Redirect("/Tracks/Create"));
            }

            if (input.Price < 0.00M)
            {
                return(this.Redirect("/Tracks/Create"));
            }

            this.tracksService.Create(input.Name, input.Link, input.Price);

            return(this.View());
        }
Exemplo n.º 3
0
        public HttpResponse Create(CreateTrackInputModel inputModel)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (inputModel.Name.Length < 4 || inputModel.Name.Length > 20)
            {
                return(this.Error("Track name should be between 4 and 20 characters."));
                //return this.View();
            }

            if (!inputModel.Link.StartsWith("http"))
            {
                return(this.Error("Invalid link."));
                //return this.View();
            }

            if (inputModel.Price < 0.0M || inputModel.Price > decimal.MaxValue)
            {
                return(this.Error("Price should be a positive number."));
                //return this.View();
            }

            this.tracksService.CreateTrack(inputModel.AlbumId, inputModel.Name, inputModel.Link, inputModel.Price);
            return(this.Redirect($"/Albums/Details?id={inputModel.AlbumId}"));
        }
Exemplo n.º 4
0
        public HttpResponse Create(CreateTrackInputModel model)
        {
            if (!this.IsUserSignedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (model.Name.Length < 4 || model.Name.Length > 20)
            {
                return(this.Error("Track name should be between 4 and 20characters."));
            }

            if (!model.Link.StartsWith("http"))
            {
                return(this.Error("This is not valid link."));
            }

            if (model.Price < 0)
            {
                return(this.Error("Price should be a positive number."));
            }

            this.tracksService.Create(model);
            return(this.Redirect("/Albums/Details?id=" + model.AlbumId));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Create(CreateTrackInputModel trackInputModel)
        {
            var trackForDb = await this.trackService.CreateTrackAsync(trackInputModel);

            var isTrackAddedSuccessfuly = await this.albumService.AddTrackToAlbumAsync(trackInputModel.AlbumId, trackForDb);

            if (!isTrackAddedSuccessfuly)
            {
                return(this.Redirect("/Albums/All"));
            }

            return(this.Redirect($"/Albums/Details?id={trackInputModel.AlbumId}"));
        }
Exemplo n.º 6
0
        public HttpResponse Create(string albumId)
        {
            if (!this.IsUserSignedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            var createTrackInputModel = new CreateTrackInputModel()
            {
                AlbumId = albumId,
            };

            return(this.View(createTrackInputModel));
        }
Exemplo n.º 7
0
        public HttpResponse Create(CreateTrackInputModel input)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (input.Name.Length < 4 || input.Name.Length > 20)
            {
                return(this.Redirect($"/Tracks/Create?albumId={input.AlbumId}"));
            }

            this.tracksService.Create(input.Name, input.Link, input.Price, input.AlbumId);

            return(this.Redirect("/Home/Index"));
        }
Exemplo n.º 8
0
        public async Task <Track> CreateTrackAsync(CreateTrackInputModel trackInputModel)
        {
            Track trackForDb = new Track
            {
                Id      = Guid.NewGuid().ToString(),
                Name    = trackInputModel.Name,
                Link    = trackInputModel.Link,
                Price   = trackInputModel.Price,
                AlbumId = trackInputModel.AlbumId,
            };

            await this.trackRepository.AddAsync(trackForDb);

            await this.trackRepository.SaveChangesAsync();

            return(trackForDb);
        }
Exemplo n.º 9
0
        public void Create(CreateTrackInputModel model)
        {
            var track = new Track()
            {
                Link  = model.Link,
                Name  = model.Name,
                Price = model.Price
            };

            var album = this.data.Albums.FirstOrDefault(x => x.Id == model.AlbumId);

            album.Tracks.Add(track);
            album.Price = album.Tracks.Sum(x => x.Price) * 0.87m;

            this.data.Tracks.Add(track);
            this.data.SaveChanges();
        }
Exemplo n.º 10
0
        public void Create(CreateTrackInputModel model)
        {
            var track = new Track
            {
                AlbumId = model.AlbumId,
                Name    = model.Name,
                Link    = model.Link,
                Price   = model.Price
            };

            this.dbContext.Tracks.Add(track);
            var allTrackPricesSum = this.dbContext.Tracks
                                    .Where(x => x.AlbumId == model.AlbumId)
                                    .Sum(x => x.Price) + model.Price;
            var album = this.dbContext.Albums.Find(model.AlbumId);

            album.Price = allTrackPricesSum * 0.87M;

            this.dbContext.SaveChanges();
        }
Exemplo n.º 11
0
        public HttpResponse Create(CreateTrackInputModel input)
        {
            if (!this.IsUserSignedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (string.IsNullOrWhiteSpace(input.Name) || input.Name.Length < 4 || input.Name.Length > 20)
            {
                return(this.Redirect($"/Tracks/Create?albumId={input.AlbumId}"));
            }

            if (string.IsNullOrWhiteSpace(input.Link))
            {
                return(this.Redirect($"/Tracks/Create?albumId={input.AlbumId}"));
            }

            this.tracksService.CreateTrack(input.Name, input.Price, input.Link, input.AlbumId);

            return(this.Redirect($"/Albums/Details?id={input.AlbumId}"));
        }
Exemplo n.º 12
0
        public HttpResponse Create(CreateTrackInputModel model)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (model.Name.Length < 4 || model.Name.Length > 20)
            {
                return(this.Error("Track name should be between 4 and 20 characters."));
            }

            if (string.IsNullOrEmpty(model.Name) || string.IsNullOrWhiteSpace(model.Name) ||
                string.IsNullOrWhiteSpace(model.Link) || string.IsNullOrEmpty(model.Link) ||
                model.Price < 0)
            {
                return(this.Redirect($"/Tracks/Create?albumId={model.AlbumId}"));
            }


            this.tracksService.Create(model);

            return(this.Redirect("/"));
        }