コード例 #1
0
ファイル: ServicesController.cs プロジェクト: propil5/Scedulo
        public async Task <IActionResult> AddService([FromBody] ServiceViewModel newService)
        {
            if (!ModelState.IsValid)
            {
                var modelErrors = new List <string>();
                foreach (var modelState in ModelState.Values)
                {
                    foreach (var modelError in modelState.Errors)
                    {
                        modelErrors.Add(modelError.ErrorMessage);
                    }
                }
                return(BadRequest(new AddingResult {
                    Successful = false, Errors = modelErrors
                }));
            }

            var successful = await _servicesService
                             .AddServiceAsync(newService);

            if (!successful)
            {
                return(BadRequest("Could not add service."));
            }

            return(Ok("Added service: " + newService.Name.ToUpper()));
        }