public HttpResponse Create(TrackCreateInputModel 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.")); } if (!inputModel.Link.StartsWith("http")) { return(this.Error("Invalid link.")); } if (inputModel.Price < 0) { return(this.Error("Price should be a positive number.")); } this.tracksService.Create(inputModel.AlbumId, inputModel.Name, inputModel.Link, inputModel.Price); return(this.Redirect("/Albums/Details?id=" + inputModel.AlbumId)); }
public HttpResponse Create(TrackCreateInputModel model) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (model.Name.Length < 4 || model.Name.Length > 20) { return(this.Error("Password must be at least 4 characters and at most 20")); } if (string.IsNullOrWhiteSpace(model.Link)) { return(this.Error("Cover cannot be empty!")); } if (model.Price < 0) { return(this.Error("Price must be more than zero")); } this.tracksService.CreateTrack(model.Name, model.Link, model.Price, model.AlbumId); return(this.Redirect($"/Albums/Details?id={model.AlbumId}")); }
public IActionResult Create(TrackCreateInputModel model) { if (!this.ModelState.IsValid) { return(this.Redirect("/Albums/All")); } var track = ModelMapper.ProjectTo <Track>(model); if (!this.albumService.AddTrackToAlbum(model.AlbumId, track)) { return(this.Redirect("/Albums/All")); } return(this.Redirect($"/Albums/Details?id={model.AlbumId}")); }
public HttpResponse Create(TrackCreateInputModel input) { if (!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 symbols!")); } if (input.Price < 0) { return(this.Error("Price should be positivie number!")); } this.trackService.Create(input.AlbumId, input.Name, input.Link, input.Price); return(this.Redirect("/Albums/Details?id=" + input.AlbumId)); }
public IActionResult Create(TrackCreateInputModel model) { if (!ModelState.IsValid) { return(Redirect("/Tracks/Create?albumId=" + model.AlbumId)); } Album album = albumService.GetById(model.AlbumId); if (album == null) { return(Redirect("/Tracks/Create?albumId=" + model.AlbumId)); } Track track = model.MapTo <Track>(); album.Price += model.Price * GlobalConstants.PriceDiscountConeficient; trackService.CreateTrack(track); albumService.UpdateAlbum(album); return(Redirect("/Albums/Details?id=" + model.AlbumId)); }