public async Task <IHttpActionResult> Update(AlbumResultModel model)
        {
            var serviceResult = new ServiceResult <AlbumModel>();

            if (!ModelState.IsValid)
            {
                serviceResult.Success           = false;
                serviceResult.Error.Description = "Model is not valid.";
                serviceResult.Error.Code        = ErrorStatusCode.BudRequest;
                return(ServiceResult(serviceResult));
            }

            var result = await _albumService.Update(model);

            serviceResult.Success = result.Success;
            if (result.Success)
            {
                serviceResult.Result = model;
            }
            else
            {
                serviceResult.Error = result.Error;
            }

            return(ServiceResult(serviceResult));
        }
        public async Task <ServiceResult> Add(AlbumResultModel model)
        {
            var serviceResult = new ServiceResult();

            var songsResult = model.Songs == null || model.Songs.Count == 0 ? new DatabaseManyResult <SongModel>()
            {
                Success = true, Entities = null
            } : await _songRepository.GetMany(model.Songs, 0, 50);

            if (!songsResult.Success)
            {
                serviceResult.Error.Code        = ErrorStatusCode.BudRequest;
                serviceResult.Error.Description = songsResult.Message;
                return(serviceResult);
            }
            var artistsResult = model.Artists == null || model.Artists.Count == 0 ? new DatabaseManyResult <ArtistModel>()
            {
                Success = true, Entities = null
            } : await _artistRepository.GetMany(model.Artists, 0, 50);

            if (!artistsResult.Success)
            {
                serviceResult.Error.Code        = ErrorStatusCode.BudRequest;
                serviceResult.Error.Description = artistsResult.Message;
                return(serviceResult);
            }
            var genresResult = model.Genres == null || model.Genres.Count == 0 ? new DatabaseManyResult <GenreModel>()
            {
                Success = true, Entities = null
            } : await _genreRepository.GetMany(model.Genres, 0, 50);

            if (!genresResult.Success)
            {
                serviceResult.Error.Code        = ErrorStatusCode.BudRequest;
                serviceResult.Error.Description = genresResult.Message;
                return(serviceResult);
            }


            var modelObject = new AlbumModel()
            {
                Id      = model.Id,
                Name    = model.Name,
                ArtId   = model.ArtId,
                Songs   = songsResult.Entities,
                Artists = artistsResult.Entities,
                Genres  = genresResult.Entities
            };

            var result = await _albumRepository.Add(modelObject);

            serviceResult.Success = result.Success;
            if (!result.Success)
            {
                serviceResult.Error.Code        = ErrorStatusCode.BudRequest;
                serviceResult.Error.Description = result.Message;
            }

            return(serviceResult);
        }
        public async Task <IHttpActionResult> Add(AlbumResultModel model)
        {
            var serviceResult = new ServiceResult <AlbumModel>();

            ModelState.Remove("model.Id");

            if (!ModelState.IsValid)
            {
                serviceResult.Success           = false;
                serviceResult.Error.Description = "Model is not valid.";
                serviceResult.Error.Code        = ErrorStatusCode.BudRequest;
                return(ServiceResult(serviceResult));
            }

            model.Id = System.Guid.NewGuid().ToString("N").Substring(0, 24);

            var result = await _albumService.Add(model);

            serviceResult.Success = result.Success;
            if (result.Success)
            {
                serviceResult.Result = model;
            }
            else
            {
                serviceResult.Error = result.Error;
            }
            return(ServiceResult(serviceResult));
        }
        public async Task <ServiceResult <AlbumResultModel> > Update(AlbumResultModel model)
        {
            var serviceResult = new ServiceResult <AlbumResultModel>();

            var getAuthorizedUserServiceResult = await _authorizedUserService.Get();

            if (getAuthorizedUserServiceResult.Success)
            {
                var authorizedUser = getAuthorizedUserServiceResult.Result;

                var restUrl = $"{_ipServerPort}{_apiControllerRoutePrefix}/Update";

                var restServiceResult = await _restClient.MakeApiCall <AlbumResultModel>
                                        (
                    restUrl,
                    HttpMethod.Post,
                    data : model,
                    accessToken : authorizedUser.AccessToken
                                        );

                if (!restServiceResult.Success)
                {
                    serviceResult.Error = restServiceResult.Error;
                }
                else
                {
                    serviceResult.Success = true;
                    serviceResult.Result  = restServiceResult.Result;
                }
            }
            else
            {
                serviceResult.Error = getAuthorizedUserServiceResult.Error;
            }

            return(serviceResult);
        }