Пример #1
0
        public async Task <IHttpActionResult> Add(ArtistModel model)
        {
            var serviceResult = new ServiceResult <ArtistModel>();

            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 _artistService.Add(model);

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

            return(ServiceResult(serviceResult));
        }
Пример #2
0
        public ActionResult <Artist> PostArtist(ArtistDto artistDto)
        {
            var result = _artistService.Add(artistDto);

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

            return(CreatedAtAction("GetArtist", new { id = result.ResultData.Id }, artistDto));
        }
Пример #3
0
        public ValidationResult Create(Artist artist)
        {
            BeginTransaction();
            ValidationResult.Add(_service.Add(artist));
            if (ValidationResult.IsValid)
            {
                Commit();
            }

            return(ValidationResult);
        }
        // Private methods

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

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

                var serviceResult = new ServiceResult <ArtistModel>();

                if (string.IsNullOrWhiteSpace(Id.Value))
                {
                    serviceResult = await _artistService.Add(new ArtistModel()
                    {
                        Id = Id.Value, Name = Name.Value
                    });
                }
                else
                {
                    serviceResult = await _artistService.Update(new ArtistModel()
                    {
                        Id = Id.Value, Name = Name.Value
                    });
                }

                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);
                }
            }
        }
Пример #5
0
 public IHttpActionResult New(ArtistDTO artist)
 {
     artistService.Add(artist);
     return(Ok());
 }
Пример #6
0
 public void Post([FromBody] ArtistModel artist)
 {
     _artistService.Add(artist);
 }