コード例 #1
0
ファイル: DocumentController.cs プロジェクト: adkl/nsi
        /// <summary>
        /// Deletes Document
        /// </summary>
        /// <returns><see cref="IHttpActionResult"/></returns>
        public IHttpActionResult Delete(int id)
        {
            try
            {
                if (id <= 0)
                {
                    throw new NsiArgumentException(DocumentMessages.DocumentInvalidArgument);
                }
                var document = new DocumentDomain();
                if (this._azureActive.Equals("true"))
                {
                    document = _documentManipulation.GetDocumentById(id, 1);
                }
                else if (this._azureActive.Equals("false"))
                {
                    document = _documentManipulation.GetDocumentById(id, 2);
                }
                var fileType     = _fileTypeManipulation.GetFileExtensionById(document.FileTypeId);
                var documentName = document.Name + '.' + fileType;
                if (document.StorageTypeId == 1)
                {
                    DeleteHelper.DeleteFileFromAzure(documentName);
                }
                else if (document.StorageTypeId == 2)
                {
                    FileInfo fi = new FileInfo(document.Path);
                    fi.Delete();
                }

                var result = _documentManipulation.DeleteDocument(id);

                if (!result)
                {
                    throw new NsiBaseException(string.Format(DocumentMessages.DocumentDeleteFailed));
                }

                return(Ok(result));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #2
0
ファイル: FileTypeController.cs プロジェクト: adkl/nsi
        /// <summary>
        /// Get File Extension By FileType Id
        /// </summary>
        /// <returns><see cref="IHttpActionResult"/></returns>
        public IHttpActionResult GetFileExtensionById(int id)
        {
            try
            {
                if (id <= 0)
                {
                    throw new NsiArgumentException(FileTypeMessages.FileTypeInvalidArgument);
                }

                var result = _fileTypeManipulation.GetFileExtensionById(id);

                if (result == null)
                {
                    throw new NsiBaseException(string.Format(FileTypeMessages.FileTypeUpdateFailed));
                }

                return(Ok(result));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }