/// <summary>
        /// Initializes program entity using request data. Saves entities in database.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="programCreateDto">The program create dto.</param>
        /// <returns></returns>
        public async Task <OperationResultDto <ProgramBriefResponseDto, CreateUpdateProgramStatus> > CreateProgram(
            int customerId,
            ProgramRequestDto programCreateDto
            )
        {
            var newProgram = await BuildProgram(customerId, programCreateDto);

            if (newProgram.Status != CreateUpdateProgramStatus.Success)
            {
                return(new OperationResultDto <ProgramBriefResponseDto, CreateUpdateProgramStatus>()
                {
                    Status = newProgram.Status
                });
            }

            var createProgramResponse = await programService.Create(newProgram.Content);

            var respoDto = Mapper.Map <ProgramBriefResponseDto>(createProgramResponse.Content);

            await globalSearchCacheHelper.AddOrUpdateEntry(customerId, Mapper.Map <Program, SearchProgramResponseDto>(createProgramResponse.Content));

            await tagsSearchCacheHelper.AddOrUpdateTags(customerId, createProgramResponse.Content.Tags.Select(t => t.Name).ToList());

            var unusedTags = await tagsService.RemoveUnusedTags(customerId);

            await tagsSearchCacheHelper.RemoveTags(customerId, unusedTags);

            return(new OperationResultDto <ProgramBriefResponseDto, CreateUpdateProgramStatus>()
            {
                Status = newProgram.Status,
                Content = respoDto
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates new question element.
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <ServiceActionResult <QuestionElementActionStatus, Guid> > Create(
            int customerId,
            CreateQuestionElementRequestDto dto
            )
        {
            var entity = Mapper.Map <QuestionElement>(dto);

            entity.CustomerId = customerId;
            entity.LocalizedStrings.Add(await this.MapAnswerString(dto.QuestionElementString));
            entity.Tags = await this.tagsService.BuildTagsList(customerId, dto.Tags);

            if (dto.AnswerChoiceIds != null)
            {
                MapAnswerChoiceIds(entity, dto.AnswerChoiceIds);
            }

            var result = await this.questionElementService.Create(entity);

            if (result.Status != QuestionElementActionStatus.Success)
            {
                return(result.Clone <Guid>());
            }

            await globalSearchCacheHelper.AddOrUpdateEntry(customerId, Mapper.Map <QuestionElement, SearchEntryDto>(result.Content));

            await tagsSearchCacheHelper.AddOrUpdateTags(customerId, result.Content.Tags.Select(t => t.Name).ToList());

            var unusedTags = await tagsService.RemoveUnusedTags(customerId);

            await tagsSearchCacheHelper.RemoveTags(customerId, unusedTags);

            return(result.Clone(result.Content.Id));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates the specified model.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public async Task <OperationResultDto <Guid, CreateScaleAnswerSetStatus> > Create(int customerId, CreateScaleAnswerSetRequestDto model)
        {
            var status = ValidateLabels(model);

            if (status > 0)
            {
                return(new OperationResultDto <Guid, CreateScaleAnswerSetStatus>()
                {
                    Status = status
                });
            }

            var answerSet = Mapper.Map <ScaleAnswerSet>(model);

            answerSet.CustomerId = customerId;
            answerSet.Tags       = await tagsService.BuildTagsList(customerId, model.Tags);

            var lowLabel = await MapLabelToLocalizedString <LowLabelScaleAnswerSetString>(
                model.Labels.LowLabel, careElementContext.DefaultLanguage);

            answerSet.LowLabelScaleAnswerSetStrings.Add(lowLabel);

            // Mid is optional field.
            if (model.Labels.MidLabel != null)
            {
                var midLabel = await MapLabelToLocalizedString <MidLabelScaleAnswerSetString>
                                   (model.Labels.MidLabel, careElementContext.DefaultLanguage);

                answerSet.MidLabelScaleAnswerSetStrings.Add(midLabel);
            }

            var highLabel = await MapLabelToLocalizedString <
                HighLabelScaleAnswerSetString>(model.Labels.HighLabel,
                                               careElementContext.DefaultLanguage);

            answerSet.HighLabelScaleAnswerSetStrings.Add(highLabel);

            var result = await scaleAnswerSetService.Create(answerSet);

            await globalSearchCacheHelper.AddOrUpdateEntry(customerId, Mapper.Map <ScaleAnswerSet, SearchEntryDto>(result));

            await tagsSearchCacheHelper.AddOrUpdateTags(customerId, result.Tags.Select(t => t.Name).ToList());

            var unusedTags = await tagsService.RemoveUnusedTags(customerId);

            await tagsSearchCacheHelper.RemoveTags(customerId, unusedTags);

            return(new OperationResultDto <Guid, CreateScaleAnswerSetStatus>()
            {
                Content = result.Id,
                Status = CreateScaleAnswerSetStatus.Success
            });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates the protocol.
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public async Task <OperationResultDto <Guid, CreateUpdateProtocolStatus> > CreateProtocol(
            int customerId,
            CreateProtocolRequestDto request
            )
        {
            #region Step 1 - Client IDs validation

            var validationResult = PerformValidationStep1(request);

            if (!validationResult.HasFlag(CreateUpdateProtocolStatus.Success))
            {
                return(new OperationResultDto <Guid, CreateUpdateProtocolStatus>()
                {
                    Status = validationResult
                });
            }

            #endregion

            #region Step 2 - Remaining Validation which can be made only after successfuly passed step 1

            validationResult = await PerformValidationStep2(request);

            if (!validationResult.HasFlag(CreateUpdateProtocolStatus.Success))
            {
                return(new OperationResultDto <Guid, CreateUpdateProtocolStatus>()
                {
                    Status = validationResult
                });
            }

            #endregion

            var protocol = await BuildProtocol(customerId, request);

            var createdProtocol = await protocolService.CreateProtocol(protocol);

            await globalSearchCacheHelper.AddOrUpdateEntry(customerId, Mapper.Map <Protocol, SearchEntryDto>(protocol));

            await tagsSearchCacheHelper.AddOrUpdateTags(customerId, createdProtocol.Tags.Select(t => t.Name).ToList());

            var unusedTags = await tagsService.RemoveUnusedTags(customerId);

            await tagsSearchCacheHelper.RemoveTags(customerId, unusedTags);

            return(new OperationResultDto <Guid, CreateUpdateProtocolStatus>()
            {
                Content = createdProtocol.Id,
                Status = validationResult
            });
        }
        /// <summary>
        /// Deletes Answerset with specified id.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="selectionAnswerSetId">The selection answer set identifier.</param>
        /// <returns></returns>
        public async Task <DeleteStatus> Delete(int customerId, Guid selectionAnswerSetId)
        {
            var result = await selectionAnswerSetService.Delete(customerId, selectionAnswerSetId);

            if (result == DeleteStatus.Success)
            {
                await globalSearchCacheHelper.RemoveEntry(customerId, selectionAnswerSetId);

                var unusedTags = await tagsService.RemoveUnusedTags(customerId);

                await tagsSearchCacheHelper.RemoveTags(customerId, unusedTags);
            }

            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates the specified media dto.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="mediaDto">The media dto.</param>
        /// <returns></returns>
        public async Task <OperationResultDto <Guid, CreateMediaStatus> > CreateMedia(int customerId, CreateMediaRequestDto mediaDto)
        {
            var contentModel = Mapper.Map <CreateMediaRequestDto, ContentModel>(mediaDto);

            var uploadResult = await contentStorage.UploadContent(contentModel);

            if (uploadResult == null)
            {
                return(new OperationResultDto <Guid, CreateMediaStatus>()
                {
                    Status = CreateMediaStatus.InvalidContentOrSourceContentUrlProvided
                });
            }

            var media = new Media()
            {
                CustomerId          = customerId,
                Name                = mediaDto.Name,
                Description         = mediaDto.Description,
                ContentType         = mediaDto.ContentType,
                ContentLength       = uploadResult.OriginalContentLength,
                Tags                = await tagsService.BuildTagsList(customerId, mediaDto.Tags),
                OriginalStorageKey  = uploadResult.OriginalStorageKey,
                ThumbnailStorageKey = uploadResult.ThumbnailStorageKey,
                OriginalFileName    = uploadResult.OriginalFileName
            };

            var createdMedia = await mediaService.Create(media);

            await tagsSearchCacheHelper.AddOrUpdateTags(customerId, createdMedia.Tags.Select(t => t.Name).ToList());

            var unusedTags = await tagsService.RemoveUnusedTags(customerId);

            await tagsSearchCacheHelper.RemoveTags(customerId, unusedTags);

            return(new OperationResultDto <Guid, CreateMediaStatus>()
            {
                Content = createdMedia.Id,
                Status = CreateMediaStatus.Success
            });
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates the specified new text media element dto.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="newTextMediaElementDto">The new text media element dto.</param>
        /// <returns></returns>
        public async Task <OperationResultDto <Guid, CreateTextMediaElementStatus> > Create(
            int customerId,
            CreateTextMediaElementRequestDto newTextMediaElementDto
            )
        {
            var validationResult = await ValidateCreateTextMediaElement(customerId, newTextMediaElementDto);

            if (!validationResult.HasFlag(CreateTextMediaElementStatus.Success))
            {
                return(new OperationResultDto <Guid, CreateTextMediaElementStatus>()
                {
                    Status = validationResult
                });
            }

            var elementTags = await tagsService.BuildTagsList(customerId, newTextMediaElementDto.Tags);

            var mappedTextMediaElement = Mapper.Map <CreateTextMediaElementRequestDto, TextMediaElement>(newTextMediaElementDto);

            mappedTextMediaElement.CustomerId = customerId;
            mappedTextMediaElement.Tags       = elementTags;

            var elementString = Mapper.Map <CreateLocalizedStringRequestDto, TextMediaElementString>(newTextMediaElementDto.Text);

            if (elementString != null)
            {
                elementString.Language = CareElementRequestContext.Current.DefaultLanguage;

                mappedTextMediaElement.TextLocalizedStrings = new List <TextMediaElementString>()
                {
                    elementString
                };

                if (newTextMediaElementDto.Text.AudioFileMedia != null)
                {
                    elementString.AudioFileMedia = await mediaFileHelper.CreateMediaFile(newTextMediaElementDto.Text.AudioFileMedia);
                }
            }

            if (newTextMediaElementDto.MediaId.HasValue)
            {
                mappedTextMediaElement.TextMediaElementsToMedias = new List <TextMediaElementToMedia>()
                {
                    new TextMediaElementToMedia()
                    {
                        MediaId  = newTextMediaElementDto.MediaId.Value,
                        Language = CareElementRequestContext.Current.DefaultLanguage
                    }
                };
            }
            else if (newTextMediaElementDto.Media != null)
            {
                var media = await mediaFileHelper.CreateMediaFile(newTextMediaElementDto.Media);

                if (media != null)
                {
                    mappedTextMediaElement.TextMediaElementsToMedias = new List <TextMediaElementToMedia>()
                    {
                        new TextMediaElementToMedia()
                        {
                            Media    = media,
                            Language = CareElementRequestContext.Current.DefaultLanguage
                        }
                    };
                }
            }

            var result = await textMediaElementsService.Create(mappedTextMediaElement);

            await globalSearchCacheHelper.AddOrUpdateEntry(customerId, Mapper.Map <TextMediaElement, SearchTextAndMediaDto>(result));

            await tagsSearchCacheHelper.AddOrUpdateTags(customerId, result.Tags.Select(t => t.Name).ToList());

            var unusedTags = await tagsService.RemoveUnusedTags(customerId);

            await tagsSearchCacheHelper.RemoveTags(customerId, unusedTags);

            return(new OperationResultDto <Guid, CreateTextMediaElementStatus>()
            {
                Status = CreateTextMediaElementStatus.Success,
                Content = mappedTextMediaElement.Id
            });
        }