Esempio n. 1
0
 public async Task Generate(PublishPlanTemplateDTO publishPlanTemplateDto)
 {
     var pageName = publishPlanTemplateDto.Name + ".html";
     await _templateGenerator.Generate(new PlanTemplateDetailsTemplate(), pageName, new Dictionary <string, object>
     {
         ["planTemplate"] = publishPlanTemplateDto
     });
 }
Esempio n. 2
0
        public async Task <IHttpActionResult> Post(PublishPlanTemplateDTO dto)
        {
            var fr8AccountId   = User.Identity.GetUserId();
            var planTemplateCM = await _planTemplate.CreateOrUpdate(fr8AccountId, dto);

            await _searchProvider.CreateOrUpdate(planTemplateCM);

            await _webservicesPageGenerator.Generate(planTemplateCM, fr8AccountId);

            await _planTemplateDetailsGenerator.Generate(dto);

            return(Ok());
        }
 private PlanTemplateCM CreatePlanTemplateCM(PublishPlanTemplateDTO dto,
                                             PlanTemplateCM existing, Fr8AccountDO account)
 {
     return(new PlanTemplateCM()
     {
         Name = dto.Name,
         Description = dto.Description,
         ParentPlanId = dto.ParentPlanId.ToString(),
         PlanContents = dto.PlanContents,
         Version = existing?.Version ?? 1,
         OwnerId = account.Id,
         OwnerName = account.UserName
     });
 }
Esempio n. 4
0
        public async Task Generate(PublishPlanTemplateDTO publishPlanTemplateDto)
        {
            var pageName = publishPlanTemplateDto.Name + "-" + publishPlanTemplateDto.ParentPlanId + ".html";

            if (publishPlanTemplateDto.Description == null)
            {
                publishPlanTemplateDto.Description = "";
            }

            await _templateGenerator.Generate(new PlanTemplateDetailsTemplate(), pageName, new Dictionary <string, object>
            {
                ["planTemplate"]  = publishPlanTemplateDto,
                ["planCreateUrl"] = CloudConfigurationManager.GetSetting("HubApiUrl") +
                                    "plan_templates/createplan/?id=" + publishPlanTemplateDto.ParentPlanId
            });
        }
Esempio n. 5
0
        public async Task Share(Guid planId, string userId)
        {
            try
            {
                var planDto = CrateTemplate(planId, userId);

                var dto = new PublishPlanTemplateDTO
                {
                    Name         = planDto.Name,
                    Description  = planDto.Description,
                    ParentPlanId = planId,
                    PlanContents = planDto
                };

                var planTemplateCM = await _planTemplate.CreateOrUpdate(userId, dto);

                await _searchProvider.CreateOrUpdate(planTemplateCM);

                await _webservicesPageGenerator.Generate(planTemplateCM, userId);

                await _planTemplateDetailsGenerator.Generate(dto);

                // Notify user with directing him to PlanDirectory with related search query
                var url = CloudConfigurationManager.GetSetting("PlanDirectoryUrl") + "/plan_directory#?planSearch=" + HttpUtility.UrlEncode(dto.Name);

                _pusherNotifier.NotifyUser(new NotificationMessageDTO
                {
                    NotificationType = NotificationType.GenericSuccess,
                    Subject          = "Success",
                    Message          = $"Plan Shared. To view, click on " + url,
                    Collapsed        = false
                }, userId);
            }
            catch
            {
                _pusherNotifier.NotifyUser(new NotificationMessageDTO
                {
                    NotificationType = NotificationType.GenericSuccess,
                    Subject          = "Success",
                    Message          = $"Plan sharing failed",
                    Collapsed        = false
                }, userId);
            }
        }
        public Task <PlanTemplateCM> CreateOrUpdate(string fr8AccountId, PublishPlanTemplateDTO planTemplate)
        {
            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                var fr8Account = uow.UserRepository.GetByKey(fr8AccountId);
                if (fr8Account == null)
                {
                    throw new ApplicationException("Invalid Fr8AccountId.");
                }

                var planIdString = planTemplate.ParentPlanId.ToString();

                var existingPlanTemplateCM = uow.MultiTenantObjectRepository
                                             .Query <PlanTemplateCM>(
                    fr8AccountId,
                    x => x.ParentPlanId == planIdString
                    )
                                             .FirstOrDefault();

                var planTemplateCM = CreatePlanTemplateCM(
                    planTemplate,
                    existingPlanTemplateCM,
                    fr8Account
                    );

                uow.MultiTenantObjectRepository.AddOrUpdate(
                    fr8AccountId,
                    planTemplateCM,
                    x => x.ParentPlanId == planIdString
                    );

                uow.SaveChanges();

                var objectId = uow.MultiTenantObjectRepository
                               .GetObjectId <PlanTemplateCM>(fr8AccountId, x => x.ParentPlanId == planIdString);

                if (existingPlanTemplateCM == null && objectId.HasValue)
                {
                    ObjectFactory.GetInstance <ISecurityServices>().SetDefaultRecordBasedSecurityForObject(Roles.OwnerOfCurrentObject, objectId.Value, "Plan Template");
                }

                return(Task.FromResult(planTemplateCM));
            }
        }
Esempio n. 7
0
        public Task <bool> HasGeneratedPage(PublishPlanTemplateDTO planTemplate)
        {
            var pageName = $"{planTemplate.Name}-{planTemplate.ParentPlanId.ToString()}.html";

            return(Task.FromResult(File.Exists(Path.Combine(_templateGenerator.OutputFolder, pageName))));
        }