public ActionResult <CustomResponseModel> CreateAlbum([FromForm] AlbumCreateModel albumCreateModel) { albumCreateModel.LabelId = new AlbumDataAccess().JwtTokenValidation(albumCreateModel.JwtToken); if (albumCreateModel.LabelId == "") { return(Unauthorized(new CustomResponseModel() { Code = "401", Phrase = "Unauthorized", Message = "Invalid Jwt Token" })); } if (new AlbumDataAccess().IsLabel(albumCreateModel.LabelId)) { AlbumGlobalModel albumGlobalModel = new AlbumGlobalModel(); albumGlobalModel.Id = GenerateUserId(); albumGlobalModel.AlbumName = albumCreateModel.AlbumName; albumGlobalModel.CoverImage = albumCreateModel.CoverImage; albumGlobalModel.CoverImageUrl = new AlbumDataAccess().UploadAlbumCoverImage(albumCreateModel.CoverImage, albumGlobalModel.Id); albumGlobalModel.LabelId = albumCreateModel.LabelId; albumGlobalModel.ArtistId = albumCreateModel.ArtistId; albumGlobalModel.Year = albumCreateModel.Year; albumGlobalModel.Genre = albumCreateModel.Genre; if (new AlbumDataAccess().CreateAlbum(albumGlobalModel)) { return(Ok(new CustomResponseModel() { Code = "200", Phrase = "OK", Message = "Album Created" })); } } else { return(Unauthorized(new CustomResponseModel() { Code = "401", Phrase = "Unauthorized", Message = "Album Creator Must be a Label" })); } return(BadRequest(new CustomResponseModel() { Code = "400", Phrase = "BadRequest", Message = "Album Creation Failed" })); }
//INSERT ALBUM public bool CreateAlbum(AlbumGlobalModel albumGlobalModel) { try { var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("albums"); var document = new BsonDocument { { "AlbumId", albumGlobalModel.Id }, { "AlbumName", albumGlobalModel.AlbumName }, { "CoverImageUrl", albumGlobalModel.CoverImageUrl }, { "LabelId", albumGlobalModel.LabelId }, { "ArtistId", albumGlobalModel.ArtistId }, { "Year", albumGlobalModel.Year }, { "Genre", albumGlobalModel.Genre } }; collection.InsertOne(document); return(true); } catch (Exception) { return(false); } }