コード例 #1
0
        public async Task <ResultModel> AddApplication(AddApplicationRequestModel requestModel)
        {
            try
            {
                var model = _mapper.Map <AddApplicationModel>(requestModel);
                await _applicationService.AddApplicationAsync(model);

                return(ResultModel.Success("添加成功"));
            }
            catch (InvalidOperationException ex)
            {
                return(ResultModel.Fail(ex.Message));
            }
        }
コード例 #2
0
        public async Task <IActionResult> NewApplication(PutApplicationViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _applicationService.AddApplicationAsync(model.Name, model.Description, model.Url);

                    return(RedirectToAction(nameof(ApplicationController.Index)));
                }
                catch (Exception e)
                {
                    ModelState.AddModelError(string.Empty, "Internal server error");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #3
0
        public async Task <IHttpActionResult> RegisterAsync(ApplicationCreateModel applicationCreateModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                ApplicationCreateDto applicationCreateDto = applicationCreateModel.ToApplicationCreateDto();

                int applicationId = await _applicationService.AddApplicationAsync(applicationCreateDto);

                return(Ok(applicationId));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }