コード例 #1
0
        public async Task <IActionResult> Create(ServiceType serviceType)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _serviceTypeRepository.CreateServiceTypeAsync(serviceType);

                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateException dbUpdateException)
                {
                    if (dbUpdateException.InnerException.Message.Contains("duplicate"))
                    {
                        ModelState.AddModelError(string.Empty, "There are a record with the same name.");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message);
                    }
                }
                catch (Exception exception)
                {
                    ModelState.AddModelError(string.Empty, exception.Message);
                }
            }
            return(View(serviceType));
        }
コード例 #2
0
        public async Task <IActionResult> CreateServiceType(CreateServiceTypeDto serviceTypeDto, ApiVersion version)
        {
            var result = await _repository.CreateServiceTypeAsync(serviceTypeDto);

            return(CreatedAtRoute(new { id = result.Id, version = $"{version}" }, result));
        }