Exemplo n.º 1
0
 public static void UpdateTemplateText(this TemplateText tempText, TemplateTextViewModel tempTextVm)
 {
     tempText.ID    = tempTextVm.ID;
     tempText.Type  = tempTextVm.Type;
     tempText.Text  = tempTextVm.Text;
     tempText.Index = tempTextVm.Index;
 }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([FromBody] TemplateCreateDto template)
        {
            if (template == null)
            {
                return(BadRequest());
            }

            int    attemptsCount    = 0;
            int    maxAttemptsCount = 100;
            string slug;
            bool   isSlugUnique = false;

            do
            {
                slug         = template.Title.GenerateSlug();
                isSlugUnique = (await _db.Templates.SingleOrDefaultAsync(d => d.Slug == slug)) == null;
            } while (!isSlugUnique && attemptsCount < maxAttemptsCount);

            if (!isSlugUnique)
            {
                return(BadRequest(new { message = "Cannot generate unique slug" }));
            }

            var newTemplate = new Templates
            {
                ProjectId        = template.ProjectId,
                TemplateTypeSlug = template.TemplateType,
                CreatorId        = UserId,
                Slug             = slug,
                Title            = template.Title,
                Description      = template.Description,
                DateCreated      = DateTime.UtcNow
            };

            _db.Templates.Add(newTemplate);
            await _db.SaveChangesAsync();

            await _db.Entry(newTemplate).Reference(d => d.Creator).LoadAsync();

            var newTemplateText = new TemplateText
            {
                TemplateId  = newTemplate.TemplateId,
                EditorId    = UserId,
                Content     = template.Content,
                QuillDelta  = template.QuillDelta,
                TimeUpdated = DateTime.UtcNow
            };

            _db.TemplateText.Add(newTemplateText);
            await _db.SaveChangesAsync();

            return(Ok(new TemplateDto(newTemplate, template.Content)));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> SaveChanges([FromRoute] int?id, [FromRoute] string slug, [FromBody] TemplateTextSaveDto changes)
        {
            var template = await GetTemplate(id, slug);

            if (template == null)
            {
                return(NotFound());
            }

            var newText = new TemplateText {
                TemplateId  = template.TemplateId,
                EditorId    = UserId,
                Content     = changes.Content,
                QuillDelta  = changes.QuillDelta,
                TimeUpdated = DateTime.UtcNow
            };

            _db.TemplateText.Add(newText);
            await _db.SaveChangesAsync();

            return(Ok());
        }
Exemplo n.º 4
0
        private static async Task SeedTemplates(KMSDBContext db, string dirname, JsonSerializerSettings serializerSettings)
        {
            var templatesJson = await File.ReadAllTextAsync(Path.Combine(dirname, "templates.json"));

            var templates = JsonConvert.DeserializeObject <List <TemplateSerializer> >(templatesJson, serializerSettings);

            foreach (var item in templates)
            {
                var existingType = await db.TemplateTypes.SingleOrDefaultAsync(t => t.TemplateTypeSlug == item.TemplateTypeSlug);

                if (existingType == null)
                {
                    throw new Exception("Template type not found");
                }

                var existingTemplate = await db.Templates.SingleOrDefaultAsync(t => t.TemplateTypeSlug == item.TemplateTypeSlug && t.ProjectId == null);

                if (existingTemplate == null)
                {
                    var newTemplate = new Templates {
                        TemplateTypeSlug = item.TemplateTypeSlug,
                        Slug             = item.Title.GenerateSlug(),
                        Title            = item.Title,
                        Description      = item.Description,
                        DateCreated      = DateTime.UtcNow
                    };
                    db.Templates.Add(newTemplate);
                    await db.SaveChangesAsync();

                    var newTemplateText = new TemplateText {
                        TemplateId  = newTemplate.TemplateId,
                        Content     = item.Content,
                        TimeUpdated = DateTime.UtcNow
                    };
                    db.TemplateText.Add(newTemplateText);
                    await db.SaveChangesAsync();
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// An extension method to draw the given <see cref="TemplateText"/> onto the
        /// <see cref="IImageProcessingContext"/> that we're working with.
        /// <para>Usage: <code>SixLabors.ImageSharp.SomeImage.Mutate(x => x.DrawKaguyaText(...))</code></para>
        /// </summary>
        /// <param name="ctx">The <see cref="IImageProcessingContext"/> we are working with.</param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static IImageProcessingContext DrawKaguyaText(this IImageProcessingContext ctx, TemplateText text)
        {
            if (text.Show)
            {
                var brush  = new SolidBrush(text.Color);
                var stroke = new Pen(text.StrokeColor, text.StrokeWidth);

                return(text.HasStroke
                    ? ctx.DrawText(text.Text, text.Font, brush, stroke, new PointF(text.Loc.X, text.Loc.Y))
                    : ctx.DrawText(text.Text, text.Font, text.Color, new PointF(text.Loc.X, text.Loc.Y)));
            }

            return(null);
        }
 public override int GetHashCode()
 {
     return(TemplateText.GetHashCode());
 }
Exemplo n.º 7
0
        public async Task <IActionResult> Create([FromBody] ProjectCreateDto project)
        {
            if (project == null)
            {
                return(BadRequest());
            }

            int    attemptsCount    = 0;
            int    maxAttemptsCount = 100;
            string slug;
            bool   isSlugUnique = false;

            do
            {
                slug         = project.Name.GenerateSlug();
                isSlugUnique = (await _db.Projects.SingleOrDefaultAsync(p => p.Slug == slug)) == null;
            } while (!isSlugUnique && attemptsCount < maxAttemptsCount);

            if (!isSlugUnique)
            {
                return(BadRequest(new { message = "Cannot generate unique slug" }));
            }

            // Creating new project
            var newProject = new Projects
            {
                Slug        = slug,
                Name        = project.Name,
                Description = project.Description,
                Goal        = project.Goal,
                DateStart   = project.DateStart,
                DateEnd     = project.DateEnd,
                Avatar      = project.Avatar,
                IsOpen      = project.IsOpen,
                IsActive    = project.IsActive
            };

            _db.Projects.Add(newProject);
            await _db.SaveChangesAsync();


            // Assigning team to project
            foreach (var member in project.Team)
            {
                if (member == null)
                {
                    continue;
                }

                if (member.ProjectRole == null)
                {
                    continue;
                }

                var role = await _db.ProjectRoles.SingleOrDefaultAsync(r => r.ProjectRoleId == member.ProjectRole.ProjectRoleId);

                if (role == null)
                {
                    continue;
                }

                var existingMember = await _db.ProjectTeam.SingleOrDefaultAsync(t => t.UserId == member.UserId && t.ProjectId == newProject.ProjectId);

                if (existingMember != null)
                {
                    continue;
                }

                var newMember = new ProjectTeam
                {
                    UserId        = member.UserId,
                    ProjectId     = newProject.ProjectId,
                    ProjectRoleId = member.ProjectRole.ProjectRoleId,
                    DateJoined    = DateTime.UtcNow,
                    Position      = member.Position
                };
                _db.ProjectTeam.Add(newMember);
            }
            await _db.SaveChangesAsync();


            // Copying template for project
            var projectIntroTemplate = await _db.Templates.SingleOrDefaultAsync(t => t.TemplateTypeSlug == "project_intro" && t.ProjectId == null);

            if (projectIntroTemplate != null)
            {
                var newTemplate = new Templates {
                    TemplateTypeSlug = projectIntroTemplate.TemplateTypeSlug,
                    ProjectId        = newProject.ProjectId,
                    CreatorId        = UserId,
                    Slug             = newProject.Name.GenerateSlug(),
                    Title            = projectIntroTemplate.Title,
                    Description      = projectIntroTemplate.Description,
                    DateCreated      = DateTime.UtcNow
                };
                _db.Templates.Add(newTemplate);
                await _db.SaveChangesAsync();

                var templateText = await _db.TemplateText.SingleOrDefaultAsync(t => t.TemplateId == projectIntroTemplate.TemplateId && t.IsActual);

                if (templateText != null)
                {
                    var newTemplateText = new TemplateText {
                        TemplateId  = newTemplate.TemplateId,
                        EditorId    = UserId,
                        Content     = templateText.Content,
                        QuillDelta  = templateText.QuillDelta,
                        TimeUpdated = DateTime.UtcNow
                    };
                    _db.TemplateText.Add(newTemplateText);
                    await _db.SaveChangesAsync();
                }
            }

            await _db.Entry(newProject).Collection(b => b.QuickLinksHousingProject).LoadAsync();

            var membersCount = await _db.ProjectTeam.Where(pt => pt.ProjectId == newProject.ProjectId).CountAsync();

            var permissions = await _dbconnection.QueryAsync <string>(
                @"select pp.project_permission_slug from project_permissions as pp
                left join project_role_permissions as prp on prp.project_permission_slug = pp.project_permission_slug
                left join project_team as pt on pt.project_role_id = prp.project_role_id
                where pt.user_id = @user_id and pt.project_id = @project_id
                group by pp.project_permission_slug", new { user_id = UserId, project_id = newProject.ProjectId });

            return(Ok(new ProjectDto(newProject, membersCount, permissions)));
        }
 public TemplateText AddTempText(TemplateText tempText)
 {
     return(_templateTextRepository.Add(tempText));
 }