using Neo.LegitimateLicences.Api.Helpers; using Neo.LegitimateLicences.Common; using Neo.LegitimateLicences.Data.Models; using Newtonsoft.Json.Linq; using Neo.Afx.Services.Documents; using Neo.Afx.Services.Documents.Entities; using Neo.Afx.Services.Security; using Neo.Afx.Services.Workflows; using Neo.Afx.Utilities; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Security.Claims; using System.Threading; using System.Web.Http; using System.Web.Http.Cors; using DPUruNet; namespace Neo.LegitimateLicences.Api { public partial class LegitimateLicencesApiController { #region GetScanningData [Route("~/1.0/Scanning/GetScanningData")] [HttpGet] public JsonBaseResult GetScanningData(string scanToken) { var response = new JsonBaseResult(); if (!IsValidClaim) { string error = Error_ClaimDetailsNotFound.Replace("#EXPOSE_ERROR#", ""); throw new Exception(error); } var documentDB = new DocumentsDatabase(); var db = new LegitimateDatabase(); var scanSession = documentDB.GetScanSession(scanToken); var desktopAppVersion = db.GetSystemSetting("DesktopAppVersion"); if (scanSession != null) { response.Result = new { scanSession = scanSession, desktopAppVersion = desktopAppVersion }; response.Success = true; } else { response.Success = false; } return response; } #endregion #region UploadScannedDocument [Route("~/1.0/Scanning/UploadScannedDocument")] [HttpPost] public JsonBaseResult UploadScannedDocument([FromBody] JObject documentObject) { var response = new JsonBaseResult(); string error = null; var documentDb = new DocumentsDatabase(); Document document = null; DocumentUtilities _utilities = new DocumentUtilities(); var fileBytes = DocumentUtilities.HexStringToByteArray(documentObject["fileHexString"].ToString()); if (fileBytes == null) { return response; } try { document = _utilities.Upload( UserID, UserEmail, (documentObject["documentID"] != null) ? Convert.ToInt64(documentObject["documentID"]) : -1, Convert.ToInt32(documentObject["entityID"]), Convert.ToInt64(documentObject["itemID"]), Convert.ToInt16(documentObject["documentTypeID"]), Convert.ToInt64(documentObject["documentStoreLocationID"]), documentObject["fileName"].ToString().Replace("&", "and"), "application/pdf", fileBytes); documentDb.UpdateDocumentIDOnEntity(document.DocumentID, Convert.ToInt32(documentObject["entityID"]), Convert.ToInt64(documentObject["itemID"]), documentObject["relatedFieldKey"].ToString(), UserID); response.Success = true; response.Result = document; } catch (Exception ex) { error = ex.Message; } return response; } #endregion } }