示例#1
0
        public IActionResult AddUser(PlaylistModelView playlistModel)
        {
            var userId = _userManager.GetUserId(User);

            _playlistService.Add(playlistModel, userId);
            return(RedirectToAction("Index"));
        }
示例#2
0
        // Private methods

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

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

                var serviceResult = new ServiceResult <PlaylistResultModel>();

                if (string.IsNullOrWhiteSpace(Id.Value))
                {
                    serviceResult = await _playlistService.Add(new PlaylistResultModel()
                    {
                        Id = Id.Value, Name = Name.Value, OwnerId = OwnerId.Value, Songs = Songs.Value.Select(_ => _.Object.Id).ToList()
                    });
                }
                else
                {
                    serviceResult = await _playlistService.Update(new PlaylistResultModel()
                    {
                        Id = Id.Value, Name = Name.Value, OwnerId = OwnerId.Value, Songs = Songs.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);
                }
            }
        }
示例#3
0
        public async Task <IHttpActionResult> Add(PlaylistResultModel model)
        {
            var serviceResult = new ServiceResult <PlaylistModel>();

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

            if (model.OwnerId != User.Identity.GetUserId())
            {
                serviceResult.Success           = false;
                serviceResult.Error.Description = "Id of owner and id of current user not equals.";
                serviceResult.Error.Code        = ErrorStatusCode.BudRequest;
                return(ServiceResult(serviceResult));
            }

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

            var result = await _playlistService.Add(model);

            serviceResult.Success = result.Success;
            if (result.Success)
            {
                serviceResult.Result = model;
            }
            else
            {
                serviceResult.Error = result.Error;
            }
            return(ServiceResult(serviceResult));
        }
 public string Add(Playlist playlist)
 {
     return(_playlistService.Add(playlist));
 }