public Integration CreateEntityFromRequest(IntegrationEditRequest request, Integration entity) { entity.Name = request.Name; entity.Description = request.Description; return(entity); }
public static IntegrationEditRequest GetIntegrationEditRequest() { var request = new IntegrationEditRequest(CurrentUserId, OrganizationOneIntegrationOneUid, StringOne, StringOne); return(request); }
public async Task <IntegrationEditResponse> EditIntegration(IntegrationEditRequest request) { var response = new IntegrationEditResponse(); var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId); if (!currentUser.IsAdmin) { response.SetInvalid(); return(response); } if (await _organizationRepository.Any(x => x.Id == currentUser.OrganizationId && !x.IsActive)) { response.SetInvalid(); return(response); } var integration = await _integrationRepository.Select(x => x.Uid == request.IntegrationUid); if (integration.IsNotExist()) { response.SetInvalidBecauseEntityNotFound(); return(response); } if (integration.OrganizationId != currentUser.OrganizationId) { response.SetInvalid(); return(response); } var trimName = request.Name.Trim(); if (await _integrationRepository.Any(x => x.Name == trimName && x.OrganizationId == currentUser.OrganizationId && x.Uid != request.IntegrationUid)) { response.Status = ResponseStatus.Failed; response.ErrorMessages.Add("integration_name_must_be_unique"); return(response); } var updatedEntity = _integrationFactory.CreateEntityFromRequest(request, integration); var result = await _integrationRepository.Update(request.CurrentUserId, updatedEntity); if (result) { response.Item = _integrationFactory.CreateDtoFromEntity(updatedEntity); response.Status = ResponseStatus.Success; return(response); } response.SetFailed(); return(response); }
public async Task <IActionResult> Edit(IntegrationEditModel model) { if (model.IsNotValid()) { model.SetInputModelValues(); return(View(model)); } var request = new IntegrationEditRequest(CurrentUser.Id, model.IntegrationUid, model.Name, model.Description); var response = await _integrationService.EditIntegration(request); if (response.Status.IsNotSuccess) { model.MapMessages(response); model.SetInputModelValues(); return(View(model)); } CurrentUser.IsActionSucceed = true; return(Redirect($"/Integration/Detail/{response.Item.Uid}")); }