Example #1
0
        public IActionResult Add(Album album)
        {
            _logger.LogInformation("Iniciado fluxo de adição de álbum");
            var insertedAlbum = _albumService.Add(album);

            return(Ok(insertedAlbum));
        }
        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 <ImportResponse> ImportAlbumsAsync(AlbumImportRequest request)
        {
            ImportResponse response = await CheckRequest(request.UserID, request.Albums.Count);

            if (!response.Successful)
            {
                return(response);
            }

            var user = await _userManager.FindByIdAsync(request.UserID);

            foreach (var album in request.Albums)
            {
                try
                {
                    album.UserID  = request.UserID;
                    album.UserNum = user.UserNum;
                    album.ID      = 0;
                    _albumService.Add(album);
                    response.Imported++;
                }
                catch (Exception ex)
                {
                    response.Failed++;
                    response.Message += $"{album.Title}- {ex.Message} : {ex.InnerException?.Message} ,";
                }
            }

            response.Successful = true;

            return(response);
        }
 public IActionResult CreateAlbum(AlbumViewModel model)
 {
     if (ModelState.IsValid)
     {
         _albumService.Add(model);
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Example #5
0
        public ValidationResult Create(Album orderDetail)
        {
            BeginTransaction();
            ValidationResult.Add(_service.Add(orderDetail));
            if (ValidationResult.IsValid)
            {
                Commit();
            }

            return(ValidationResult);
        }
        public ActionResult AddAlbum(string albumTitle)
        {
            var album = new AlbumDto()
            {
                Id = Guid.NewGuid().ToString(), Title = albumTitle
            };

            _albumService.Add(album);

            return(RedirectToAction("UserAlbum"));
        }
Example #7
0
        // Private methods

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

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

                var serviceResult = new ServiceResult <AlbumResultModel>();

                if (string.IsNullOrWhiteSpace(Id.Value))
                {
                    serviceResult = await _albumService.Add(new AlbumResultModel()
                    {
                        Id = Id.Value, Name = Name.Value, Artists = Artists.Value.Select(_ => _.Object.Id).ToList(), Genres = Genres.Value.Select(_ => _.Object.Id).ToList(), Songs = Songs.Value.Select(_ => _.Object.Id).ToList()
                    });
                }
                else
                {
                    serviceResult = await _albumService.Update(new AlbumResultModel()
                    {
                        Id = Id.Value, Name = Name.Value, Artists = Artists.Value.Select(_ => _.Object.Id).ToList(), Genres = Genres.Value.Select(_ => _.Object.Id).ToList(), 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);
                }
            }
        }
Example #8
0
        public IActionResult Add([FromBody] AlbumViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Album properties are not valid."));
            }

            if (!IsCurrentUser(viewModel.UserId))
            {
                return(BadRequest("User credentials are not valid."));
            }

            var album = GetMappedAlbum(viewModel);

            _albumService.Add(album);

            return(Ok(album.UserId));
        }
Example #9
0
 public Album SaveAlbum(Album album)
 {
     return(this.WrapInUnitOfWork(() => albumService.Add(album)));
 }
Example #10
0
 public ActionResult AddAlbum(Album album)
 {
     album.AlbumID = _albumService.Query().Count + 1;
     _albumService.Add(album);
     return(Content("OK"));
 }