コード例 #1
0
        public static DocumentFileViewModel ConvertToDocumentFileViewModel(this DocumentFile DocumentFile)
        {
            DocumentFileViewModel DocumentFileViewModel = new DocumentFileViewModel()
            {
                Id         = DocumentFile.Id,
                Identifier = DocumentFile.Identifier,

                Name = DocumentFile.Name,
                Path = DocumentFile.Path,
                Size = DocumentFile.Size,

                DocumentFolder = DocumentFile?.DocumentFolder?.ConvertToDocumentFolderViewModelLite(),

                IsActive = DocumentFile.Active,

                Company   = DocumentFile.Company?.ConvertToCompanyViewModelLite(),
                CreatedBy = DocumentFile.CreatedBy?.ConvertToUserViewModelLite(),
                UpdatedAt = DocumentFile.UpdatedAt,
                CreatedAt = DocumentFile.CreatedAt
            };



            return(DocumentFileViewModel);
        }
コード例 #2
0
        public async Task <IActionResult> UploadFile(IFormFile file, DocumentFileViewModel dvm)
        {
            if (file == null || file.Length == 0)
            {
                return(Content("file not selected"));
            }
            var uploads  = Path.Combine(_hostingEnvironment.WebRootPath, "files");
            var filePath = Path.Combine(uploads, file.FileName);

            using (var stream = new FileStream(filePath, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }

            if (ModelState.IsValid)
            {
                Document doc       = new Document();
                DateTime timestamp = DateTime.Now;
                doc.Name              = dvm.Name;
                doc.Description       = dvm.Description;
                doc.ApplicationUserId = dvm.ApplicationUserId;
                doc.FileName          = dvm.FileName;
                doc.Timestamp         = timestamp;
                doc.CourseId          = dvm.CourseId;
                doc.ModuleId          = dvm.ModuleId;
                doc.ActivityId        = dvm.ActivityId;
                _context.Add(doc);
                await _context.SaveChangesAsync();
            }
            return(RedirectToAction(nameof(Index)));
        }
コード例 #3
0
        public DocumentFileResponse Create(DocumentFileViewModel DocumentFile)
        {
            DocumentFileResponse response = new DocumentFileResponse();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                SqliteCommand insertCommand = db.CreateCommand();
                insertCommand.CommandText = SqlCommandInsertPart;

                try
                {
                    insertCommand = AddCreateParameters(insertCommand, DocumentFile);
                    insertCommand.ExecuteNonQuery();
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    return(response);
                }
                db.Close();

                response.Success = true;
                return(response);
            }
        }
コード例 #4
0
        public JsonResult Post([FromBody] DocumentFileViewModel data)
        {
            var response = new DocumentUploadResponse();


            if (data.TypeId != 0)
            {
                var docType = _unitOfWork.DocumentDataType.Get(data.TypeId);
                var newitem = new DocumentFile
                {
                    BuildingFloorId = data.BuildingFloorId,
                    BuildingId      = data.BuildingId,
                    Type            = docType,
                    Description     = data.Description,
                    DocumentId      = data.DocumentId,
                    Id      = data.Id,
                    Name    = data.Name,
                    WebPath = data.WebPath
                };

                _unitOfWork.Documentfiles.Add(newitem);
                _unitOfWork.SaveChanges();
            }
            else
            {
                response.AddError(0, "Моля Изберете Тип на документа");
            }

            return(new JsonResult(response));
        }
コード例 #5
0
        // GET: Documents/Create
        public async Task <IActionResult> Create()
        {
            DocumentFileViewModel doc = new DocumentFileViewModel();
            DateTime timestamp        = DateTime.Now;

            doc.Timestamp = timestamp;
            var currentUser = await _userManager.GetUserAsync(HttpContext.User);

            doc.ApplicationUserId = currentUser.Id.ToString();
            return(View(doc));
        }
コード例 #6
0
        public void GetDocumentAttributes(DocumentFileViewModel doc)
        {
            CloudFile file = GetFile(doc.Path);

            if (file != null && file.Exists())
            {
                Debug.WriteLine($"Fetching attributes for {doc.Path}");
                file.FetchAttributes();

                if (file.Properties != null)
                {
                    doc.Size      = file.Properties.Length / 1024;
                    doc.CreatedAt = file.Properties.LastModified.Value.DateTime;
                }
            }
        }
コード例 #7
0
        public DocumentFileResponse Delete(DocumentFileViewModel toDelete)
        {
            DocumentFileResponse response = new DocumentFileResponse();

            try
            {
                response = WpfApiHandler.SendToApi <DocumentFileViewModel, DocumentFileResponse>(toDelete, "Delete");
            }
            catch (Exception ex)
            {
                response.DocumentFile = new DocumentFileViewModel();
                response.Success      = false;
                response.Message      = ex.Message;
            }

            return(response);
        }
コード例 #8
0
        public DocumentFileResponse Create(DocumentFileViewModel viewModel)
        {
            DocumentFileResponse response = new DocumentFileResponse();

            try
            {
                response.DocumentFile = unitOfWork.GetDocumentFileRepository().Create(viewModel.ConvertToDocumentFile())
                                        ?.ConvertToDocumentFileViewModel();
                response.Success = true;
            } catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
コード例 #9
0
        public DocumentFileResponse Delete(DocumentFileViewModel toDelete)
        {
            DocumentFileResponse response = new DocumentFileResponse();

            try
            {
                response.DocumentFile = unitOfWork.GetDocumentFileRepository().Delete(toDelete?.Id ?? 0)
                                        ?.ConvertToDocumentFileViewModel();
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
コード例 #10
0
        private static DocumentFileViewModel Read(SqliteDataReader query)
        {
            int counter = 0;
            DocumentFileViewModel dbEntry = new DocumentFileViewModel();

            dbEntry.Id         = SQLiteHelper.GetInt(query, ref counter);
            dbEntry.Identifier = SQLiteHelper.GetGuid(query, ref counter);
            dbEntry.Name       = SQLiteHelper.GetString(query, ref counter);
            dbEntry.Path       = SQLiteHelper.GetString(query, ref counter);
            dbEntry.Size       = SQLiteHelper.GetDouble(query, ref counter);

            dbEntry.DocumentFolder = SQLiteHelper.GetDocumentFolder(query, ref counter);

            dbEntry.CreatedAt = SQLiteHelper.GetDateTime(query, ref counter);
            dbEntry.UpdatedAt = SQLiteHelper.GetDateTime(query, ref counter);
            dbEntry.CreatedBy = SQLiteHelper.GetCreatedBy(query, ref counter);
            dbEntry.Company   = SQLiteHelper.GetCompany(query, ref counter);
            return(dbEntry);
        }
コード例 #11
0
        public static DocumentFileViewModel ConvertToDocumentFileViewModelLite(this DocumentFile DocumentFile)
        {
            DocumentFileViewModel DocumentFileViewModel = new DocumentFileViewModel()
            {
                Id         = DocumentFile.Id,
                Identifier = DocumentFile.Identifier,

                Name = DocumentFile.Name,
                Path = DocumentFile.Path,
                Size = DocumentFile.Size,

                IsActive = DocumentFile.Active,

                UpdatedAt = DocumentFile.UpdatedAt,
                CreatedAt = DocumentFile.CreatedAt
            };


            return(DocumentFileViewModel);
        }
コード例 #12
0
        public JsonResult Delete([FromBody] DocumentFileViewModel c)
        {
            DocumentFileResponse response = new DocumentFileResponse();

            try
            {
                response = this.documentFileService.Delete(c);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
                Console.WriteLine(ex.Message);
            }

            return(Json(response, new Newtonsoft.Json.JsonSerializerSettings()
            {
                Formatting = Newtonsoft.Json.Formatting.Indented
            }));
        }
コード例 #13
0
        public static DocumentFile ConvertToDocumentFile(this DocumentFileViewModel DocumentFileViewModel)
        {
            DocumentFile DocumentFile = new DocumentFile()
            {
                Id         = DocumentFileViewModel.Id,
                Identifier = DocumentFileViewModel.Identifier,

                Name = DocumentFileViewModel.Name,
                Path = DocumentFileViewModel.Path,
                Size = DocumentFileViewModel.Size,

                DocumentFolderId = DocumentFileViewModel?.DocumentFolder?.Id ?? null,

                CompanyId   = DocumentFileViewModel.Company?.Id ?? null,
                CreatedById = DocumentFileViewModel.CreatedBy?.Id ?? null,

                CreatedAt = DocumentFileViewModel.CreatedAt,
                UpdatedAt = DocumentFileViewModel.UpdatedAt
            };

            return(DocumentFile);
        }
コード例 #14
0
        private SqliteCommand AddCreateParameters(SqliteCommand insertCommand, DocumentFileViewModel File)
        {
            insertCommand.Parameters.AddWithValue("@ServerId", File.Id);
            insertCommand.Parameters.AddWithValue("@Identifier", File.Identifier);
            insertCommand.Parameters.AddWithValue("@Name", ((object)File.Name) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@Path", ((object)File.Path) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@Size", ((object)File.Size) ?? DBNull.Value);

            insertCommand.Parameters.AddWithValue("@DocumentFolderId", ((object)File.DocumentFolder?.Id) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@DocumentFolderIdentifier", ((object)File.DocumentFolder?.Identifier) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@DocumentFolderName", ((object)File.DocumentFolder?.Name) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@DocumentFolderPath", ((object)File.DocumentFolder?.Path) ?? DBNull.Value);

            insertCommand.Parameters.AddWithValue("@CreatedAt", ((object)File.CreatedAt) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@UpdatedAt", ((object)File.UpdatedAt) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@CreatedById", MainWindow.CurrentUser.Id);
            insertCommand.Parameters.AddWithValue("@CreatedByName", MainWindow.CurrentUser.FirstName + " " + MainWindow.CurrentUser.LastName);
            insertCommand.Parameters.AddWithValue("@CompanyId", MainWindow.CurrentCompany.Id);
            insertCommand.Parameters.AddWithValue("@CompanyName", MainWindow.CurrentCompany.CompanyName);

            return(insertCommand);
        }
コード例 #15
0
 public void ParseToViewModel(DocumentFile entity)
 {
     SelectedDocument = Mapper.Map <DocumentFileViewModel>(entity);
 }
コード例 #16
0
        public DocumentFileListResponse GetDocumentFiles(int companyId, DocumentFileViewModel searchObject)
        {
            DocumentFileListResponse     response = new DocumentFileListResponse();
            List <DocumentFileViewModel> Files    = new List <DocumentFileViewModel>();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand;
                    if (!String.IsNullOrEmpty(searchObject?.Search_Name))
                    {
                        selectCommand = new SqliteCommand(
                            SqlCommandSelectPart +
                            "FROM DocumentFiles " +
                            "WHERE (@FileName IS NULL OR @FileName = '' OR Name LIKE @FileName) " +
                            "AND (@FilterDateFrom IS NULL OR @FilterDateFrom = '' OR DATE(CreatedAt) >= DATE(@FilterDateFrom))" +
                            "AND (@FilterDateTo IS NULL OR @FilterDateTo = '' OR DATE(CreatedAt) <= DATE(@FilterDateTo)) " +
                            "AND (DocumentFolderPath LIKE @ParentPath) " +
                            "AND CompanyId = @CompanyId " +
                            "ORDER BY Name ASC ", db);

                        selectCommand.Parameters.AddWithValue("@ParentPath", ((object)searchObject.Search_ParentPath) != null ? searchObject.Search_ParentPath + "%" : "");
                        selectCommand.Parameters.AddWithValue("@FileName", ((object)searchObject.Search_Name) != null ? "%" + searchObject.Search_Name + "%" : "");
                        selectCommand.Parameters.AddWithValue("@FilterDateFrom", ((object)searchObject?.Search_DateFrom ?? DBNull.Value));
                        selectCommand.Parameters.AddWithValue("@FilterDateTo", ((object)searchObject?.Search_DateTo ?? DBNull.Value));
                        selectCommand.Parameters.AddWithValue("@CompanyId", companyId);
                    }
                    else
                    {
                        selectCommand = new SqliteCommand(
                            SqlCommandSelectPart +
                            "FROM DocumentFiles " +
                            "WHERE (DocumentFolderPath = @ParentPath) " +
                            "AND (@FilterDateFrom IS NULL OR @FilterDateFrom = '' OR DATE(CreatedAt) >= DATE(@FilterDateFrom))" +
                            "AND (@FilterDateTo IS NULL OR @FilterDateTo = '' OR DATE(CreatedAt) <= DATE(@FilterDateTo)) " +
                            "AND CompanyId = @CompanyId " +
                            "ORDER BY Name ASC ", db);

                        selectCommand.Parameters.AddWithValue("@ParentPath", ((object)searchObject.Search_ParentPath) != null ? searchObject.Search_ParentPath : "");
                        selectCommand.Parameters.AddWithValue("@FilterDateFrom", ((object)searchObject?.Search_DateFrom ?? DBNull.Value));
                        selectCommand.Parameters.AddWithValue("@FilterDateTo", ((object)searchObject?.Search_DateTo ?? DBNull.Value));
                        selectCommand.Parameters.AddWithValue("@CompanyId", companyId);
                    }

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    while (query.Read())
                    {
                        DocumentFileViewModel dbEntry = Read(query);
                        Files.Add(dbEntry);
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    response.DocumentFiles  = new List <DocumentFileViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success       = true;
            response.DocumentFiles = Files;
            return(response);
        }
コード例 #17
0
        private void btnSavePdf_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(DocumentName))
            {
                MainWindow.ErrorMessage = (string)Application.Current.FindResource("MorasUnetiNazivDokumentaUzicnik");
                return;
            }
            if (Images == null || Images.Where(x => x.IsSelected).Count() < 1)
            {
                MainWindow.ErrorMessage = (string)Application.Current.FindResource("MorasSkeniratiNestoIOznacitiStavkeUzvicnik");
                return;
            }
            if (String.IsNullOrEmpty(SelectedPath))
            {
                MainWindow.ErrorMessage = (string)Application.Current.FindResource("MorasOdabratiFolderUzvicnik");
                return;
            }
            CanInteractWithForm = false;
            Thread td = new Thread(() =>
            {
                try
                {
                    var tempPath = System.IO.Path.GetTempPath();

                    var generator = new PDFGenerator(Images
                                                     .Where(x => x.IsSelected)
                                                     .OrderBy(x => x.CreatedAt)
                                                     .Select(x => x.ImagePath)
                                                     .ToList(),
                                                     tempPath, DocumentName,
                                                     MainWindow.CurrentUser.FirstName + " " + MainWindow.CurrentUser.LastName);

                    CurrentDocumentFullPath = generator.Generate();

                    if (DocumentSavePathOption.Value == true)
                    {
                        File.Copy(CurrentDocumentFullPath, $"{SelectedPath}\\{DocumentName}.pdf");
                        Dispatcher.BeginInvoke((Action)(() => {
                            DocumentSaved?.Invoke(CurrentDocumentFullPath);
                        }));
                    }
                    else
                    {
                        var documentFolderResp = new DocumentFolderSQLiteRepository().GetDirectoryByPath(MainWindow.CurrentCompanyId, SelectedPath);
                        var documentFolder     = documentFolderResp?.DocumentFolder ?? null;


                        var azureClient = new AzureDataClient();



                        var file = azureClient.GetFile($"{SelectedPath}/{DocumentName}.pdf");
                        file.UploadFromFile(CurrentDocumentFullPath);

                        file.FetchAttributes();

                        var documentFile = new DocumentFileViewModel()
                        {
                            Identifier     = Guid.NewGuid(),
                            Name           = $"{DocumentName}.pdf",
                            DocumentFolder = documentFolder,
                            Path           = file.Uri.LocalPath,
                            Size           = file.Properties.Length / 1024,
                            CreatedAt      = file.Properties.LastModified.Value.DateTime,
                            Company        = new CompanyViewModel()
                            {
                                Id = MainWindow.CurrentCompanyId
                            },
                            CreatedBy = new UserViewModel()
                            {
                                Id = MainWindow.CurrentUserId
                            }
                        };

                        var documentFileService = DependencyResolver.Kernel.Get <IDocumentFileService>();

                        var response = documentFileService.Create(documentFile);
                        if (response.Success)
                        {
                            Dispatcher.BeginInvoke((Action)(() => {
                                DocumentSaved?.Invoke(file.Uri.LocalPath);
                            }));
                        }
                        else
                        {
                            MainWindow.WarningMessage = "Dokument je sačuvan na serveru ali nije indeksiran, molimo kontaktirajte administraciju!";
                            Dispatcher.BeginInvoke((Action)(() => {
                                DocumentSaved?.Invoke(file.Uri.LocalPath);
                            }));
                        }
                    }


                    MainWindow.SuccessMessage = (string)Application.Current.FindResource("DokumentJeUspesnoSacuvanUzvicnik");
                } catch (Exception ex)
                {
                    MainWindow.ErrorMessage = ex.Message;
                } finally
                {
                    CanInteractWithForm = true;
                }
            });

            td.IsBackground = true;
            td.Start();
        }