Exemplo n.º 1
0
        public async Task <IActionResult> Create([FromBody] PeopleMarkViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var errorMessage = string.Empty;

                foreach (var error in ModelState)
                {
                    foreach (var message in error.Value.Errors)
                    {
                        errorMessage += $"{message.ErrorMessage}\n";
                    }
                }

                return(StatusCode(500, ApiResult.FailResult(errorMessage)));
            }

            try
            {
                await _crudService.Create(model);
            }
            catch (DbUpdateException)
            {
                return(StatusCode(500,
                                  ApiResult.FailResult("Something went wrong while inserting data to database. Notice that \"Full Name\" should be unique.")));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ApiResult.FailResult(ex.Message)));
            }

            return(Ok(ApiResult.SuccessResult()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Uses CRUD service for getting paged and sorted items.
        /// </summary>
        /// <param name="input">Paging and sorting</param>
        /// <returns>Response object with status description and items as result if success</returns>
        public async Task <IActionResult> GetAll(PagedAndSortedInput input)
        {
            input.ValidateAndSetDefaults();

            PagedOutput <PeopleMarkViewModel> model = null;

            try
            {
                model = await _crudService.GetAll(input, p => p.Mark);
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ApiResult.FailResult(ex.Message)));
            }


            return(Json(ApiResult.SuccessResult(model)));
        }