Exemplo n.º 1
0
        public async Task <ResultOrHttpError <string, Error> > CreateJournalNoteInMomentumCoreAsync(string path, string momentumCitizenId, JournalNoteRequestModel requestModel)
        {
            List <JournalNoteAttachmentModel> attachmentList = new List <JournalNoteAttachmentModel>();

            if (requestModel.Documents != null)
            {
                foreach (var doc in requestModel.Documents)
                {
                    if (!isValidDocument(doc))
                    {
                        var error = new Error(_correlationId, new string[] { "Invalid document type" }, "Mea");
                        return(new ResultOrHttpError <string, Error>(error, HttpStatusCode.BadRequest));
                    }

                    var attachemnt = new JournalNoteAttachmentModel()
                    {
                        ContentType = doc.ContentType,
                        Document    = doc.Content,
                        Title       = doc.Name
                    };
                    attachmentList.Add(attachemnt);
                }
            }

            JournalNoteModel mcaRequestModel = new JournalNoteModel()
            {
                Id            = requestModel.Cpr,
                OccurredAt    = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss.ff'Z'"),
                Title         = requestModel.Title,
                Body          = requestModel.Body,
                Source        = "Mea",
                ReferenceId   = momentumCitizenId,
                JournalTypeId = requestModel.Type == JournalNoteType.SMS ? "022.247.000" : "022.420.000",
                Attachments   = attachmentList
            };

            string        serializedRequest = JsonConvert.SerializeObject(mcaRequestModel);
            StringContent stringContent     = new StringContent(serializedRequest, Encoding.UTF8, "application/json");

            var response = await _meaClient.PostAsync(path, stringContent).ConfigureAwait(false);

            if (response.IsError)
            {
                return(new ResultOrHttpError <string, Error>(response.Error, response.StatusCode.Value));
            }

            var content = response.Result;

            return(new ResultOrHttpError <string, Error>(content));
        }
Exemplo n.º 2
0
        public async Task <ResultOrHttpError <TaskList, Error> > GetAllTasksByCaseworkerIdFromMomentumCoreAsync(string path, int pageNumber, string caseworkerId)
        {
            var pageSize = 100;

            pageNumber = pageNumber == 0 ? 1 : pageNumber;
            List <TaskDataResponseModel> totalRecords = new List <TaskDataResponseModel>();
            var Result = new TaskSearchQuery()
            {
                AssignedActors = new List <string>()
                {
                    caseworkerId
                },
                Types = new List <TaskType>()
                {
                },
            };
            string        serializedRequest = JsonConvert.SerializeObject(Result);
            StringContent stringContent     = new StringContent(serializedRequest, Encoding.UTF8, "application/json");

            var queryStringParams = $"pagingInfo.pageNumber={pageNumber}&pagingInfo.pageSize={pageSize}";

            var response = await _meaClient.PostAsync(path + "?" + queryStringParams, stringContent).ConfigureAwait(false);

            if (response.IsError)
            {
                return(new ResultOrHttpError <TaskList, Error>(response.Error, response.StatusCode.Value));
            }

            var content           = response.Result;
            var caseworkerDataObj = JsonConvert.DeserializeObject <TaskPagedData>(content);
            var records           = caseworkerDataObj.Data;

            foreach (var item in records)
            {
                var dataToReturn = new TaskDataResponseModel(item.Id, item.Title, item.Description, item.Deadline, item.CreatedAt,
                                                             item.StateChangedAt, item.State, (IReadOnlyList <AssignedActors>)item.AssignedActors, item.Reference);
                totalRecords.Add(dataToReturn);
            }

            var responseData = new TaskList()
            {
                PageNo           = pageNumber,
                TotalNoOfPages   = caseworkerDataObj.TotalPages,
                TotalSearchCount = caseworkerDataObj.TotalSearchCount,
                Result           = totalRecords
            };

            return(new ResultOrHttpError <TaskList, Error>(responseData));
        }