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)); } }
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)); }
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)); } }