Esempio n. 1
0
        public void ChangeState([FromBody] ChangeStateRequestModel changeStateRequestModel)
        {
            var sessionContext = SessionHelper.GetSessionContext();
            var objectContext  = sessionContext.CreateObjectContext();

            DoAction(() =>
            {
                DocumentService.ChangeState(sessionContext, objectContext, changeStateRequestModel);
            });
        }
Esempio n. 2
0
        static async Task <HttpResponseMessage> ChangeCardStateAsync(ChangeStateRequestModel changeStateRequestModel)
        {
            HttpResponseMessage response = await client.PostAsJsonAsync($"api/Documents/Changestate", changeStateRequestModel);

            return(response);
        }
Esempio n. 3
0
        static async Task RunAsync()
        {
            client.BaseAddress = new Uri(Properties.Settings.Default.WebServiceUrl);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = null;

            try
            {
                // Создание новой карточки документа
                Console.WriteLine("############ CREATE CARD ############");
                Console.WriteLine();
                DocumentModel document = new DocumentModel
                {
                    Name   = "CardWebClientTest",
                    KindId = new Guid("8e40f327-9517-4a43-998d-bf2bd619588d")
                };

                response = await CreateCardAsync(document);

                Guid cardId = Guid.Parse(response.Content.ReadAsStringAsync().Result.Trim('\"'));
                document.Id = cardId;
                Console.WriteLine($"URL: {response.RequestMessage.RequestUri}");
                Console.WriteLine($"Query parameters: document: {document}");
                Console.WriteLine($"Created document card id: {cardId}");
                Console.WriteLine();

                //Получение созданной карточки документа
                Console.WriteLine("############ GET CARD ############");
                Console.WriteLine();
                response = await GetCardAsync(cardId);

                Console.WriteLine($"URL:  {response.RequestMessage.RequestUri}");
                Console.WriteLine($"Query parameters: cardId: {cardId}");
                Console.WriteLine($"Document data: {response.Content.ReadAsStringAsync().Result}");
                Console.WriteLine();

                //Обновление данных карточки документа
                Console.WriteLine("############ UPDATE CARD ############");
                Console.WriteLine();
                document.Name = "NewDocumentName";
                response      = await UpdateCardAsync(document);

                Console.WriteLine($"URL:  {response.RequestMessage.RequestUri}");
                Console.WriteLine($"Query parameters: document: {document}");
                Console.WriteLine($"Document data: {response.StatusCode}");
                Console.WriteLine();

                //Загрузка файла в карточку документа
                Console.WriteLine("############ UPLOAD FILE ############");
                Console.WriteLine();

                var applicationDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                var uploadFileName       = Path.Combine(applicationDirectory, "testfile.txt");

                response = await UploadFileAsync(uploadFileName, cardId);

                Console.WriteLine($"URL:  {response.RequestMessage.RequestUri}");
                Console.WriteLine($"Query parameters: uploadFileName: {uploadFileName}, cardId: {cardId}");
                Guid fileId = Guid.Parse(response.Content.ReadAsStringAsync().Result.Trim('\"'));
                Console.WriteLine($"Response: newFileId: {fileId}");
                Console.WriteLine();

                //Изменение состояния карточки документа
                Console.WriteLine("############ CHANGE CARD STATE ############");
                Console.WriteLine();

                ChangeStateRequestModel changeStateRequestModel = new ChangeStateRequestModel
                {
                    CardId      = cardId,
                    OperationId = new Guid("68c039da-d2e4-4c01-975a-eed6ca0b17a7")
                };
                response = await ChangeCardStateAsync(changeStateRequestModel);

                Console.WriteLine($"URL:  {response.RequestMessage.RequestUri}");
                Console.WriteLine(
                    $"Query parameters: cardId: {cardId}, operationId:{changeStateRequestModel.OperationId}");
                Console.WriteLine($"Document data: {response.StatusCode}");
                Console.WriteLine();

                //Скачивание файла из карточки документа
                Console.WriteLine("############ DOWNLOAD FILE ############");
                Console.WriteLine();
                response = await DownloadFileAsync(fileId);

                Console.WriteLine($"URL:  {response.RequestMessage.RequestUri}");
                Console.WriteLine($"Query parameters: fileId: {fileId}");
                Console.WriteLine($"Response: {response.StatusCode}");
                Console.WriteLine();

                //Получение отчета карточки
                Console.WriteLine("############ CARD REPORT ############");
                Console.WriteLine();
                response = await GetTestReportDataAsync(cardId);

                Console.WriteLine($"URL:  {response.RequestMessage.RequestUri}");
                Console.WriteLine($"Query parameters: cardId: {cardId}");
                Console.WriteLine($"Response: {response.Content.ReadAsStringAsync().Result}");
                Console.WriteLine();

                //Удаление карточки документа
                Console.WriteLine("############ DELETE CARD ############");
                Console.WriteLine();
                response = await DeleteCardAsync(cardId);

                Console.WriteLine($"URL:  {response.RequestMessage.RequestUri}");
                Console.WriteLine($"Query parameters: cardId: {cardId}");
                Console.WriteLine($"Response: {response.StatusCode}");
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine();
            Console.WriteLine($"Press any key to exit");

            Console.ReadKey();
        }
        /// <summary>
        /// Изменить состояние карточки документа
        /// </summary>
        /// <param name="sessionContext">Контекст сессии</param>
        /// <param name="objectContext">Контекст объекта</param>
        /// <param name="changeStaterequestModel">Модель смены состояния карточки документа</param>
        public void ChangeState(SessionContext sessionContext, ObjectContext objectContext, [FromBody] ChangeStateRequestModel changeStateRequestModel)
        {
            string bpErrors = null;

            var cardDocument    = objectContext.GetObject <Document>(changeStateRequestModel.CardId);
            var statesOperation = objectContext.GetObject <StatesOperation>(changeStateRequestModel.OperationId);
            var stateService    = objectContext.GetService <DocsVision.BackOffice.ObjectModel.Services.IStateService>();

            if (stateService.IsOperationAllowedFull(statesOperation, cardDocument))
            {
                var state = cardDocument.SystemInfo.State;
                var stateMachineBranches = stateService.GetStateMachineBranches(cardDocument.SystemInfo.CardKind);
                var stateMachineBranche  = stateMachineBranches
                                           .Single(l =>
                                                   l.Operation.GetObjectId() == changeStateRequestModel.OperationId &&
                                                   l.StartState == state);

                stateService.ChangeState(cardDocument, stateMachineBranche, true, out bpErrors);
            }

            if (!string.IsNullOrEmpty(bpErrors))
            {
                throw new InvalidOperationException(bpErrors);
            }
        }