public async Task <IActionResult> Post([FromBody] SayingVM saying)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.ToValidationMessages()));
            }

            if (saying.SageId == 0)
            {
                return(Ok(SaveResult.Fail(
                              new ValidationMessages(
                                  new ValidationMessage(
                                      name: ValidationHelpers.GetFieldName(saying, x => x.SageId), // eg "saying.sageId"
                                      message: "Please select a sage."
                                      )
                                  )
                              )));
            }

            if (saying.Id > 0)
            {
                var sayingToUpdate = await _sayingQuery.GetByIdAsync(saying.Id);

                saying.UpdateSaying(sayingToUpdate);
                await _sayingCommand.UpdateAsync(sayingToUpdate);

                return(Ok(SaveResult.Success(saying.Id)));
            }

            var sayingToAdd = new Saying();
            var sayingId    = await _sayingCommand.CreateAsync(sayingToAdd);

            return(Ok(SaveResult.Success(sayingId)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] SageVM sage)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(SaveResult.Fail(ModelState.ToValidationMessages())));
            }

            var user = await _sageQuery.GetByIdAsync(sage.Id);

            sage.UpdateUser(user);

            await _sageCommand.UpdateAsync(user);

            _logger.LogInformation("Sage " + sage.Name + " [id: " + sage.Id + "] updated by " /* + _userHelper.UserName*/);

            return(Ok(SaveResult.Success(user.Id)));
        }