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

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

            var result = await _songService.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(SongResultModel model)
        {
            var serviceResult = new ServiceResult();

            var linksResult = model.Links == null || model.Links.Count == 0 ? new DatabaseManyResult <LinkModel>()
            {
                Success = true, Entities = null
            } : await _linkRepository.GetMany(model.Links, 0, 50);

            if (!linksResult.Success)
            {
                serviceResult.Error.Code        = ErrorStatusCode.BudRequest;
                serviceResult.Error.Description = linksResult.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 SongModel()
            {
                Id      = model.Id,
                Name    = model.Name,
                ArtId   = model.ArtId,
                Links   = linksResult.Entities,
                Artists = artistsResult.Entities,
                Genres  = genresResult.Entities
            };

            var result = await _songRepository.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(SongResultModel model)
        {
            var serviceResult = new ServiceResult <SongModel>();

            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));
            }

            string link = model.Links?.FirstOrDefault();

            //if (link != null)
            //{
            //    UploadSong upload = new UploadSong();

            //    string inputPath = UploadSongProperties.TemporaryFolder + link.Id + UploadSongProperties.GetType(link.MimeType);
            //    string sourcePath = string.Empty;
            //    var moveSongResult = upload.MoveFile(inputPath, sourcePath);

            //    if (!String.IsNullOrEmpty(moveSongResult.Error))
            //    {
            //        ModelState.AddModelError("Move", moveSongResult.Error);
            //        return BadRequest(ModelState);
            //    }

            //    model.Links = new List<LinkModel>()
            //    {
            //        link
            //    };
            //}

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

            var result = await _songService.Add(model);

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

            var getAuthorizedUserServiceResult = await _authorizedUserService.Get();

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

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

                var restServiceResult = await _restClient.MakeApiCall <SongResultModel>
                                        (
                    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);
        }
        public async Task <ServiceResult> Update(SongResultModel model)
        {
            var serviceResult = new ServiceResult();

            var songResult = await this.Get(model.Id);

            if (!songResult.Success)
            {
                serviceResult.Error = songResult.Error;
                return(serviceResult);
            }

            var linksResult = model.Links == null || model.Links.Count == 0 ? new DatabaseManyResult <LinkModel>()
            {
                Success = true, Entities = null
            } : await _linkRepository.GetMany(model.Links, 0, 50);

            if (!linksResult.Success)
            {
                serviceResult.Error.Code        = ErrorStatusCode.BudRequest;
                serviceResult.Error.Description = linksResult.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);
            }

            songResult.Result.Name    = model.Name;
            songResult.Result.ArtId   = model.ArtId;
            songResult.Result.Links   = linksResult.Entities;
            songResult.Result.Artists = artistsResult.Entities;
            songResult.Result.Genres  = genresResult.Entities;

            var result = await _songRepository.Update(songResult.Result);

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