public async Task <ActionResult <CertificateTypeViewModel> > SaveCertificateTypeAsync(CertificateTypeViewModel vm) { if (vm == null) { return(BadRequest("No valid CertificateType received")); } if (string.IsNullOrEmpty(vm.Name)) { return(BadRequest("Name of a CertificateType cannot be empty")); } try { CertificateType certificateType = CertificateTypeViewModel.CreateCertificateType(vm); if (certificateType == null) { return(BadRequest("Unable to convert CertificateTypeViewModel to CertificateType")); } string oid = IdentityHelper.GetOid(HttpContext.User.Identity as ClaimsIdentity); certificateType.LastEditBy = oid; TaskResult <CertificateType> result; if (vm.Id == Guid.Empty) { result = await certificateService.CreateCertificateTypeAsync(certificateType); } else { return(BadRequest("Cannot update existing CertificateType with post method")); } if (!result.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = result.Message })); } return(Ok(CertificateTypeViewModel.CreateVm(result.Data))); } catch (Exception ex) { string message = GetType().Name + "Error in " + nameof(SaveCertificateTypeAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }