Пример #1
0
        public ActionResult <Song> PostSong(SongDto songDto)
        {
            var result = _songService.Add(songDto);

            if (!result.Success)
            {
                return(BadRequest(result));
            }

            return(CreatedAtAction("GetSong", new { id = result.ResultData.Id }, songDto));
        }
Пример #2
0
        // Private methods

        private async Task AttemptChangeAsync()
        {
            Name.Value = Name.Value?.Trim();

            if (_validationHelper.Validate())
            {
                _userDialogs.ShowLoading((string.IsNullOrWhiteSpace(Id.Value) ? "Add" : "Update") + " song");

                var serviceResult = new ServiceResult <SongResultModel>();

                if (string.IsNullOrWhiteSpace(Id.Value))
                {
                    serviceResult = await _songService.Add(new SongResultModel()
                    {
                        Id = Id.Value, Name = Name.Value, Artists = Artists.Value.Select(_ => _.Object.Id).ToList(), Genres = Genres.Value.Select(_ => _.Object.Id).ToList()
                    });
                }
                else
                {
                    serviceResult = await _songService.Update(new SongResultModel()
                    {
                        Id = Id.Value, Name = Name.Value, Artists = Artists.Value.Select(_ => _.Object.Id).ToList(), Genres = Genres.Value.Select(_ => _.Object.Id).ToList()
                    });
                }

                if (serviceResult.Success)
                {
                    await _navigationService.Close(this);

                    _userDialogs.HideLoading();
                    await _userDialogs.AlertAsync(new AlertConfig
                    {
                        Title   = "Success!",
                        Message = serviceResult.Error.Description,
                        OkText  = "OK"
                    });
                }
                else
                {
                    _userDialogs.HideLoading();

                    await _userDialogs.AlertAsync(new AlertConfig
                    {
                        Title   = (string.IsNullOrWhiteSpace(Id.Value) ? "Add" : "Update") + " failed",
                        Message = serviceResult.Error.Description,
                        OkText  = "OK"
                    });

                    InitValidationCommand.Execute(null);
                }
            }
        }
        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));
        }
Пример #4
0
 public Song SaveSong(Song song)
 {
     return(this.WrapInUnitOfWork(() => songService.Add(song)));
 }
Пример #5
0
 public void Post([FromBody] AddUpdateSongModel model)
 {
     _songService.Add(model);
 }