Exemple #1
0
        public async Task <ActionResult <DocumentViewModel> > UpdateDocument(DocumentViewModel documentViewModel)
        {
            if (documentViewModel?.Name == null || documentViewModel.DocumentUri == null ||
                documentViewModel.Id == Guid.Empty)
            {
                return(BadRequest("No valid document received"));
            }
            try
            {
                string oid = IdentityHelper.GetOid(HttpContext.User.Identity as ClaimsIdentity);

                if (documentViewModel.Name == "TOS" && !PersonsController.UserHasRole(UserRole.Boardmember,
                                                                                      (ClaimsIdentity)HttpContext.User.Identity))
                {
                    return(Unauthorized());
                }

                Document updatedDocument = DocumentViewModel.CreateDocument(documentViewModel);
                if (updatedDocument == null)
                {
                    return(BadRequest("Unable to convert DocumentViewModel to Document"));
                }

                Document oldDocument = (await documentService.GetDocumentAsync(updatedDocument.Id)).Data;
                if (oldDocument == null)
                {
                    return(NotFound("Document not found"));
                }
                if (!oldDocument.RowVersion.SequenceEqual(documentViewModel.RowVersion))
                {
                    return(BadRequest("Outdated entity received"));
                }

                oldDocument.Name        = updatedDocument.Name;
                oldDocument.DocumentUri = updatedDocument.DocumentUri;

                oldDocument.LastEditBy = oid;

                TaskResult <Document> result = await documentService.UpdateDocumentAsync(oldDocument);

                if (!result.Succeeded)
                {
                    return(UnprocessableEntity(new ErrorViewModel {
                        Type = Type.Error, Message = result.Message
                    }));
                }
                return(Ok(DocumentViewModel.CreateVm(result.Data)));
            }
            catch (Exception ex)
            {
                string message = GetType().Name + "Error in " + nameof(CreateDocument);
                logger.LogError(ex, message);
                return(UnprocessableEntity(new ErrorViewModel {
                    Type = Type.Error, Message = message
                }));
            }
        }
Exemple #2
0
        public async Task <ActionResult <DocumentViewModel> > CreateDocument(DocumentViewModel documentViewModel)
        {
            if (documentViewModel?.Name == null || documentViewModel.DocumentUri == null)
            {
                return(BadRequest("No valid document received"));
            }
            try
            {
                string oid = IdentityHelper.GetOid(HttpContext.User.Identity as ClaimsIdentity);

                if (documentViewModel.Name == "Privacy Policy" && !PersonsController.UserHasRole(UserRole.Boardmember,
                                                                                                 (ClaimsIdentity)HttpContext.User.Identity))
                {
                    return(Unauthorized());
                }

                Document document = DocumentViewModel.CreateDocument(documentViewModel);
                if (document == null)
                {
                    return(BadRequest("Unable to convert DocumentViewModel to Document"));
                }

                document.LastEditBy = oid;
                TaskResult <Document> result;
                if (document.Id == Guid.Empty)
                {
                    result = await documentService.CreateDocumentAsync(document);
                }
                else
                {
                    return(BadRequest("Cannot update existing document with post method"));
                }
                if (!result.Succeeded)
                {
                    return(UnprocessableEntity(new ErrorViewModel {
                        Type = Type.Error, Message = result.Message
                    }));
                }
                return(Ok(DocumentViewModel.CreateVm(result.Data)));
            }
            catch (Exception ex)
            {
                string message = GetType().Name + "Error in " + nameof(CreateDocument);
                logger.LogError(ex, message);
                return(UnprocessableEntity(new ErrorViewModel {
                    Type = Type.Error, Message = message
                }));
            }
        }
 private void Add_Button_Click(object sender, RoutedEventArgs e)
 {
     SaveFile(UploadFilePath, FileName);
     _viewModel.CreateDocument();
     DestinationDialog.IsOpen = false;
 }