Esempio n. 1
0
        /// <summary>
        /// Returns a specified document by its model properties.
        /// The following model properties must be supplied:
        /// model.CompanyId
        /// model.UploadedBy
        /// model.Name
        /// </summary>
        /// <param name="email"></param>
        /// <param name="rooturl"></param>
        /// <param name="encodedId"></param>
        /// <param name="document"></param>
        /// <returns></returns>
        public async Task <DocumentsModel> GetDocumentByModel(string email, string rooturl, string encodedId, DocumentsModel document)
        {
            DocumentsModel result = null;

            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(rooturl) || string.IsNullOrEmpty(encodedId) ||
                document == null || document.CompanyId <= 0 || string.IsNullOrEmpty(document.Name) || document.UploadedBy <= 0)
            {
                return(null);
            }

            string payload = new SerializerServices().SerializeObject(document);
            string url     = $"{rooturl}api/documents?postdata={payload}";

            LoggingService service   = new LoggingService();
            var            stopwatch = new Stopwatch();

            try
            {
                string response = await new WebApiServices().GetData(url, encodedId);

                if (!string.IsNullOrEmpty(response))
                {
                    result = new SerializerServices()
                             .DeserializeObject <DocumentsModel>(response.NormalizeJsonString());
                }
            }
            catch (Exception ex)
            {
                service.TrackException(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                var properties = new Dictionary <string, string>
                {
                    { "UserEmail", email },
                    { "WebServicesEndpoint", rooturl },
                    { "EncodedId", encodedId },
                    { "DocumentName", document.Name }
                };
                service.TrackEvent(LoggingServiceConstants.GetDocumentById, stopwatch.Elapsed, properties);
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Update the parent for a specified document
        /// </summary>
        /// <param name="sourceId"></param>
        /// <param name="rooturl"></param>
        /// <param name="encodedId"></param>
        /// <param name="destinationId"></param>
        /// <returns></returns>
        public async Task <bool> UpdateDocumentTreeParent(int destinationId, int sourceId, string rooturl, string encodedId)
        {
            if (string.IsNullOrEmpty(rooturl) || string.IsNullOrEmpty(encodedId) || destinationId < 0 || sourceId < 0)
            {
                return(false);
            }

            string url = $"{rooturl}api/webtasks?formname={RoutingTasksTypeConstants.DocumentDragDrop}&useRoutingController=true";
            DocumentDragDropModel model = new DocumentDragDropModel
            {
                DestinationId = destinationId,
                SourceId      = sourceId
            };
            string      payload = new SerializerServices().SerializeObject(model);
            HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");
            bool        result  = false;

            LoggingService service   = new LoggingService();
            var            stopwatch = new Stopwatch();

            try
            {
                var response = await new WebApiServices().PutData(url, content, encodedId);
                result = response.IsSuccessStatusCode;
            }
            catch (Exception ex)
            {
                service.TrackException(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                var properties = new Dictionary <string, string>
                {
                    { "DestinationId", destinationId.ToString() },
                    { "SourceId", sourceId.ToString() },
                    { "WebServicesEndpoint", rooturl },
                    { "EncodedId", encodedId }
                };
                service.TrackEvent(LoggingServiceConstants.UpdateDocumentTreeParent, stopwatch.Elapsed, properties);
            }
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Retrieves a list of document events for the specified company, user or document.
        /// Pass a null as an argument where the argument should be ignored.
        /// </summary>
        /// <param name="documentId"></param>
        /// <param name="rooturl"></param>
        /// <param name="encodedId"></param>
        /// <param name="companyId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task <DocumentEventModels> GetDocumentEvents(string companyId, string userId, string documentId, string rooturl, string encodedId)
        {
            if (string.IsNullOrEmpty(rooturl) || string.IsNullOrEmpty(encodedId))
            {
                return(null);
            }

            string queryname           = WebTasksTypeConstants.GetDocumentEvents;
            string queryterms          = WebApiServices.GeDocumentEventsJsonQuerySearchTerms(companyId, userId, documentId);
            string url                 = $"{rooturl}api/webtasks?queryname={queryname}&queryterms={queryterms}";
            DocumentEventModels result = null;

            LoggingService service   = new LoggingService();
            var            stopwatch = new Stopwatch();

            try
            {
                var response = await new WebApiServices().GetData(url, encodedId);
                if (!string.IsNullOrEmpty(response))
                {
                    result = new SerializerServices()
                             .DeserializeObject <DocumentEventModels>(response.NormalizeJsonString());
                }
            }
            catch (Exception ex)
            {
                service.TrackException(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                var properties = new Dictionary <string, string>
                {
                    { "CompanyId", companyId },
                    { "UserId", userId },
                    { "DocumentId", documentId },
                    { "WebServicesEndpoint", rooturl },
                    { "EncodedId", encodedId }
                };
                service.TrackEvent(LoggingServiceConstants.GetDocumentEvents, stopwatch.Elapsed, properties);
            }
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Retrieve the specified toolbar by its name
        /// </summary>
        /// <param name="useremail"></param>
        /// <param name="rooturl"></param>
        /// <param name="encodedId"></param>
        /// <param name="toolbarname"></param>
        public async Task <ToolbarModel> GetToolbar(string useremail, string rooturl, string encodedId, string toolbarname)
        {
            ToolbarModel result = null;

            if (string.IsNullOrEmpty(useremail) || string.IsNullOrEmpty(rooturl) || string.IsNullOrEmpty(encodedId) ||
                string.IsNullOrEmpty(toolbarname))
            {
                return(null);
            }

            string queryname  = WebTasksTypeConstants.GetToolbarByName;
            string queryterms = WebApiServices.GetJsonQuerySearchTermsToolbarname(useremail, toolbarname);
            string url        = $"{rooturl}api/webtasks?queryname={queryname}&queryterms={queryterms}";

            LoggingService service   = new LoggingService();
            var            stopwatch = new Stopwatch();

            try
            {
                var response = await new WebApiServices().GetData(url, encodedId);
                if (!string.IsNullOrEmpty(response) && response.Length > 0)
                {
                    result = new SerializerServices().DeserializeObject <ToolbarModel>(response.NormalizeJsonString());
                }
            }
            catch (Exception ex)
            {
                service.TrackException(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                var properties = new Dictionary <string, string>
                {
                    { "UserEmail", useremail },
                    { "WebServicesEndpoint", rooturl },
                    { "EncodedId", encodedId },
                    { "ToolbarName", toolbarname }
                };
                service.TrackEvent(LoggingServiceConstants.GetToolbar, stopwatch.Elapsed, properties);
            }
            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Return company address(es)
        /// </summary>
        /// <param name="email"></param>
        /// <param name="rooturl"></param>
        /// <param name="encodedId"></param>
        /// <param name="companyId"></param>
        /// <param name="returnAll"></param>
        /// <returns></returns>
        public async Task <CompanyAddressModels> GetCompanyAddresses(string email, string rooturl, string encodedId, int companyId, bool returnAll)
        {
            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(rooturl) || string.IsNullOrEmpty(encodedId) || companyId <= 0)
            {
                return(null);
            }

            string queryname            = WebTasksTypeConstants.GetCompanyAddresses;
            string queryterms           = WebApiServices.GetJsonQuerySearchTermsCompanyAddresses(companyId, returnAll);
            string url                  = $"{rooturl}api/webtasks?queryname={queryname}&queryterms={queryterms}";
            CompanyAddressModels result = null;

            LoggingService service   = new LoggingService();
            var            stopwatch = new Stopwatch();

            try
            {
                var response = await new WebApiServices().GetData(url, encodedId);
                if (!string.IsNullOrEmpty(response))
                {
                    result = new SerializerServices()
                             .DeserializeObject <CompanyAddressModels>(response.NormalizeJsonString());
                }
            }
            catch (Exception ex)
            {
                service.TrackException(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                var properties = new Dictionary <string, string>
                {
                    { "UserEmail", email },
                    { "WebServicesEndpoint", rooturl },
                    { "EncodedId", encodedId },
                    { "CompanyId", companyId.ToString() },
                    { "ReturnAll", returnAll.ToString() }
                };
                service.TrackEvent(LoggingServiceConstants.GetCompanyAddresses, stopwatch.Elapsed, properties);
            }
            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// Fetch the menu items for the specified user and menu level
        /// </summary>
        /// <param name="useremail"></param>
        /// <param name="parentId"></param>
        /// <param name="rooturl"></param>
        /// <param name="encodedId"></param>
        /// <returns></returns>
        public async Task <MainMenuModels> GetModulesItemsForUser(string useremail, int parentId, string rooturl, string encodedId)
        {
            MainMenuModels result = null;

            if (string.IsNullOrEmpty(useremail) || string.IsNullOrEmpty(rooturl) || string.IsNullOrEmpty(encodedId) ||
                parentId < 0)
            {
                return(null);
            }

            string queryname  = WebTasksTypeConstants.GetMenuItemsForModuleByUser;
            string queryterms = WebApiServices.GetMenuItemsJsonQuerySearchTerms(useremail, parentId);
            string url        = $"{rooturl}api/webtasks?queryname={queryname}&queryterms={queryterms}";

            LoggingService service   = new LoggingService();
            var            stopwatch = new Stopwatch();

            try
            {
                var response = await new WebApiServices().GetData(url, encodedId);
                if (!string.IsNullOrEmpty(response) && response.Length > 0)
                {
                    result = new SerializerServices().DeserializeObject <MainMenuModels>(response.NormalizeJsonString());
                }
            }
            catch (Exception ex)
            {
                service.TrackException(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                var properties = new Dictionary <string, string>
                {
                    { "UserEmail", useremail },
                    { "WebServicesEndpoint", rooturl },
                    { "EncodedId", encodedId },
                    { "ParentId", parentId.ToString() }
                };
                service.TrackEvent(LoggingServiceConstants.GetModulesItemsForUserForParentId, stopwatch.Elapsed, properties);
            }
            return(result);
        }
Esempio n. 7
0
        /// <summary>
        /// Update a document
        /// </summary>
        /// <param name="email"></param>
        /// <param name="rooturl"></param>
        /// <param name="encodedId"></param>
        /// <param name="document"></param>
        /// <returns></returns>
        public async Task <bool> UpdateDocument(string email, string rooturl, string encodedId,
                                                DocumentsModel document)
        {
            bool result = false;

            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(rooturl) || string.IsNullOrEmpty(encodedId) ||
                document?.Name == null || document.CompanyId <= 0 || document.UploadedBy <= 0)
            {
                return(false);
            }

            string      payload = new SerializerServices().SerializeObject(document);
            string      url     = $"{rooturl}api/documents?action={DocumentActionTypeConstants.DocumentActionUpsert}";
            HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");

            LoggingService service   = new LoggingService();
            var            stopwatch = new Stopwatch();

            try
            {
                var response = await new WebApiServices().PostData(url, content, encodedId);
                result = response.IsSuccessStatusCode;
            }
            catch (Exception ex)
            {
                service.TrackException(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                var properties = new Dictionary <string, string>
                {
                    { "UserEmail", email },
                    { "WebServicesEndpoint", rooturl },
                    { "EncodedId", encodedId },
                    { "DocumentId", document.Id.ToString() }
                };
                service.TrackEvent(LoggingServiceConstants.UpdateDocument, stopwatch.Elapsed, properties);
            }
            return(result);
        }
Esempio n. 8
0
        /// <summary>
        /// Return the documents for the specified user and document level
        /// </summary>
        /// <param name="email"></param>
        /// <param name="rooturl"></param>
        /// <param name="encodedId"></param>
        /// <param name="parentId"></param>
        /// <returns></returns>
        public async Task <DocumentsModels> GetDocumentForParentUser(string email, string rooturl, string encodedId, int parentId)
        {
            DocumentsModels result = null;
            string          url    = $"{rooturl}api/documents?parentId={parentId}&useremail={email}";

            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(url) || string.IsNullOrEmpty(encodedId) ||
                parentId < 0)
            {
                return(null);
            }

            LoggingService service   = new LoggingService();
            var            stopwatch = new Stopwatch();

            try
            {
                string response = await new WebApiServices().GetData(url, encodedId);
                if (!string.IsNullOrEmpty(response))
                {
                    result = new SerializerServices()
                             .DeserializeObject <DocumentsModels>(response.NormalizeJsonString());
                }
            }
            catch (Exception ex)
            {
                service.TrackException(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                var properties = new Dictionary <string, string>
                {
                    { "UserEmail", email },
                    { "WebServicesEndpoint", rooturl },
                    { "EncodedId", encodedId },
                    { "ParentId", parentId.ToString() }
                };
                service.TrackEvent(LoggingServiceConstants.GetDocumentForParentUser, stopwatch.Elapsed, properties);
            }
            return(result);
        }
        /// <summary>
        /// Delete a role
        /// </summary>
        /// <param name="role"></param>
        /// <param name="encodedId"></param>
        /// <param name="rooturl"></param>
        /// <returns></returns>
        public async Task <bool> DeleteRole(RoleModel role, string encodedId, string rooturl)
        {
            if (string.IsNullOrEmpty(role?.Name) || role.Id < 0 || string.IsNullOrEmpty(encodedId) || string.IsNullOrEmpty(rooturl))
            {
                return(false);
            }

            bool   result;
            string queryterms = WebApiServices.GetRoleIdJsonQuerySearchTerms(role.Id.ToString());

            string url = $"{rooturl}api/webtasks?formname={RoutingTasksTypeConstants.DeleteRole}&queryterms={queryterms}";

            LoggingService service   = new LoggingService();
            var            stopwatch = new Stopwatch();

            try
            {
                string      payload  = new SerializerServices().SerializeObject(role);
                HttpContent content  = new StringContent(payload, Encoding.UTF8, "application/json");
                var         response = await new WebApiServices().DeleteData(url, encodedId);
                result = response.IsSuccessStatusCode;
            }
            catch (Exception ex)
            {
                service.TrackException(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                var properties = new Dictionary <string, string>
                {
                    { "Rolename", role.Name },
                    { "RoleId", role.Id.ToString() },
                    { "EncodedId", encodedId },
                    { "WebServicesEndpoint", rooturl }
                };
                service.TrackEvent(LoggingServiceConstants.DeleteRole, stopwatch.Elapsed, properties);
            }
            return(result);
        }
Esempio n. 10
0
        /// <summary>
        /// Send an email document subscription notification
        /// </summary>
        /// <param name="notification"></param>
        /// <param name="rooturl"></param>
        /// <returns></returns>
        public async Task <bool> SendDocumentNotification(DocumentSubscriberNotificationModel notification, string rooturl)
        {
            bool result = false;

            if (notification == null || string.IsNullOrEmpty(notification.UserName) || string.IsNullOrEmpty(notification.DocumentName) || string.IsNullOrEmpty(rooturl))
            {
                return(false);
            }

            string url     = $"{rooturl}api/sendemail?emailname={RoutingTasksTypeConstants.DocumentNotification}";
            string payload = new SerializerServices().SerializeObject(notification);

            HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");

            LoggingService service   = new LoggingService();
            var            stopwatch = new Stopwatch();

            try
            {
                var response = await new WebApiServices().PostData(url, content);
                result = response.IsSuccessStatusCode;
            }
            catch (Exception ex)
            {
                service.TrackException(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                var properties = new Dictionary <string, string>
                {
                    { "UserName", notification.UserName },
                    { "WebServicesEndpoint", rooturl },
                    { "DocumentName", notification.DocumentName }
                };
                service.TrackEvent(LoggingServiceConstants.SendDocumentNotification, stopwatch.Elapsed, properties);
            }
            return(result);
        }
        /// <summary>
        /// Update the specified user
        /// </summary>
        /// <param name="user"></param>
        /// <param name="encodedId"></param>
        /// <param name="rooturl"></param>
        /// <returns></returns>
        public async Task <bool> UpdateUserDetails(UserModel user, string encodedId, string rooturl)
        {
            if (string.IsNullOrEmpty(user?.Email) || string.IsNullOrEmpty(user.UserName) || string.IsNullOrEmpty(encodedId) || string.IsNullOrEmpty(rooturl))
            {
                return(false);
            }

            bool   result;
            string url = $"{rooturl}api/webtasks?formname={RoutingTasksTypeConstants.UpdateUser}&useRoutingController=true";

            LoggingService service   = new LoggingService();
            var            stopwatch = new Stopwatch();

            try
            {
                string      payload  = new SerializerServices().SerializeObject(user);
                HttpContent content  = new StringContent(payload, Encoding.UTF8, "application/json");
                var         response = await new WebApiServices().PutData(url, content, encodedId);
                result = response.IsSuccessStatusCode;
            }

            catch (Exception ex)
            {
                service.TrackException(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                var properties = new Dictionary <string, string>
                {
                    { "UserEmail", user.Email },
                    { "EncodedId", encodedId },
                    { "WebServicesEndpoint", rooturl }
                };
                service.TrackEvent(LoggingServiceConstants.UpdateUserDetails, stopwatch.Elapsed, properties);
            }
            return(result);
        }
Esempio n. 12
0
        /// <summary>
        /// Retrieve the document as a data stream
        /// </summary>
        /// <param name="rooturl"></param>
        /// <param name="encodedId"></param>
        /// <param name="documentId"></param>
        /// <returns></returns>
        public async Task <DocumentDownloadModel> GetDocumentDownload(string rooturl, string encodedId, int documentId)
        {
            if (documentId <= 0 || string.IsNullOrEmpty(rooturl) || string.IsNullOrEmpty(encodedId))
            {
                return(null);
            }
            string url = $"{rooturl}api/documentimages?documentId={documentId}";
            DocumentDownloadModel result = null;

            LoggingService service   = new LoggingService();
            var            stopwatch = new Stopwatch();

            try
            {
                var response = await new WebApiServices().GetData(url, encodedId);
                if (!string.IsNullOrEmpty(response))
                {
                    result = new SerializerServices()
                             .DeserializeObject <DocumentDownloadModel>(response.NormalizeJsonString());
                }
            }
            catch (Exception ex)
            {
                service.TrackException(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                var properties = new Dictionary <string, string>
                {
                    { "WebServicesEndpoint", rooturl },
                    { "EncodedId", encodedId },
                    { "DocumentId", documentId.ToString() }
                };
                service.TrackEvent(LoggingServiceConstants.GetDocumentDownload, stopwatch.Elapsed, properties);
            }
            return(result);
        }
Esempio n. 13
0
        /// <summary>
        /// Retrieve the specified user
        /// </summary>
        /// <param name="useremail"></param>
        /// <param name="rooturl"></param>
        /// <returns></returns>
        public async Task <UserModel> GetUserDetails(string useremail, string rooturl)
        {
            if (string.IsNullOrEmpty(useremail) || string.IsNullOrEmpty(rooturl))
            {
                return(null);
            }

            UserModel result = null;
            string    url    = $"{rooturl}api/webtasks?username={useremail}";

            LoggingService service   = new LoggingService();
            var            stopwatch = new Stopwatch();

            try
            {
                var response = await new WebApiServices().GetData(url);
                if (!string.IsNullOrEmpty(response) && response.Length > 0)
                {
                    result = new SerializerServices().DeserializeObject <UserModel>(response);
                }
            }
            catch (Exception ex)
            {
                service.TrackException(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                var properties = new Dictionary <string, string>
                {
                    { "UserEmail", useremail },
                    { "WebServicesEndpoint", rooturl }
                };
                service.TrackEvent(LoggingServiceConstants.GetUserDetailsService, stopwatch.Elapsed, properties);
            }
            return(result);
        }
Esempio n. 14
0
        /// <summary>
        /// Create a new company address
        /// </summary>
        /// <param name="address"></param>
        /// <param name="encodedId"></param>
        /// <param name="rooturl"></param>
        /// <returns></returns>
        public async Task <bool> CreateCompanyAddress(CompanyAddressModel address, string encodedId, string rooturl)
        {
            if (string.IsNullOrEmpty(address?.Postcode) || string.IsNullOrEmpty(address.AddressLine1) || string.IsNullOrEmpty(encodedId) || string.IsNullOrEmpty(rooturl))
            {
                return(false);
            }

            bool   result;
            string url = $"{rooturl}api/webtasks?formname={RoutingTasksTypeConstants.AddCompanyAddress}&useRoutingController=true";

            LoggingService service   = new LoggingService();
            var            stopwatch = new Stopwatch();

            try
            {
                string      payload  = new SerializerServices().SerializeObject(address);
                HttpContent content  = new StringContent(payload, Encoding.UTF8, "application/json");
                var         response = await new WebApiServices().PostData(url, content, encodedId);
                result = response.IsSuccessStatusCode;
            }
            catch (Exception ex)
            {
                service.TrackException(ex);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                var properties = new Dictionary <string, string>
                {
                    { "CompanyAddress", $"{address.Postcode} {address.AddressLine1}" },
                    { "EncodedId", encodedId },
                    { "WebServicesEndpoint", rooturl }
                };
                service.TrackEvent(LoggingServiceConstants.CreateCompanyAddress, stopwatch.Elapsed, properties);
            }
            return(result);
        }