public async Task <bool> AddOrUpdate(PersonalIntroDto dto)
        {
            var intro = await Fsql.Select <PersonalIntro>().WhereCascade(x => x.IsDeleted == false)
                        .ToOneAsync();

            if (intro == null)
            {
                var result = await _personalIntro.InsertAsync(new PersonalIntro
                {
                    Summary       = dto.Summary,
                    CnDescription = dto.CnDescription,
                    CnHonors      = dto.CnHonors,
                    CnExperiences = dto.CnExperiences,
                    EnDescription = dto.EnDescription,
                    EnHonors      = dto.EnHonors,
                    EnExperiences = dto.EnExperiences,
                });

                return(result != default);
            }
            else
            {
                intro.Summary       = dto.Summary;
                intro.CnDescription = dto.CnDescription;
                intro.CnHonors      = dto.CnHonors;
                intro.CnExperiences = dto.CnExperiences;
                intro.EnDescription = dto.EnDescription;
                intro.EnHonors      = dto.EnHonors;
                intro.EnExperiences = dto.EnExperiences;

                var result = await _personalIntro.UpdateAsync(intro);

                return(result > 0);
            }
        }
示例#2
0
        public async Task <ArtworkDetailOutputDto> GetDetail(int id)
        {
            var artwork = await Fsql.Select <Artwork>()
                          .Where(i => i.Id == id)
                          .IncludeMany(a => a.Items)
                          .WhereCascade(x => x.IsDeleted == false).ToOneAsync();

            if (artwork == null)
            {
                return(null);
            }

            var list = await Fsql.Select <Artwork>()
                       .WhereCascade(x => x.IsDeleted == false)
                       .OrderByDescending(a => a.OnTop)
                       .OrderByDescending(a => a.CompletionTime)
                       .OrderByDescending(a => a.CreationTime)
                       .ToListAsync(i => i.Id);

            var index = list.IndexOf(id);
            int?prevId, nextId;

            if (index == 0)
            {
                (prevId, nextId) = (null, list.ElementAt(index + 1));
            }
            else if (index == list.Count - 1)
            {
                (prevId, nextId) = (list.ElementAt(index - 1), null);
            }
            else
            {
                (prevId, nextId) = (list.ElementAt(index - 1), list.ElementAt(index + 1));
            }

            var dto = new ArtworkDetailOutputDto
            {
                Id             = artwork.Id,
                Name           = artwork.Name,
                Description    = artwork.Description,
                CoverImage     = CombineDomainToRelatedUri(artwork.CoverImage),
                CompletionTime = artwork.CompletionTime,
                Items          = new ArtworkItemOutputDto[] { },
                PrevId         = prevId,
                NextId         = nextId,
            };

            if (artwork.Items != null && artwork.Items.Any())
            {
                dto.Items = artwork.Items.OrderBy(i => i.Seq).Select(i => new ArtworkItemOutputDto
                {
                    Id    = i.Id,
                    Image = CombineDomainToRelatedUri(i.RelatedUrl),
                }).ToArray();
            }

            return(dto);
        }
示例#3
0
        public bool TryGetArtworkItem(string md5, string localName, out UploadOutputDto dto)
        {
            dto = Fsql.Select <ArtworkItem>()
                  .Where(i => i.Md5 == md5 && i.LocalName == localName)
                  .WhereCascade(x => x.IsDeleted == false)
                  .ToOne(i => new UploadOutputDto
            {
                Uid        = i.Id,
                Status     = UploadStatus.Done,
                Md5        = i.Md5,
                LocalName  = i.LocalName,
                RelatedUrl = i.RelatedUrl,
            });
            if (dto != null)
            {
                dto.AbsoluteUrl = CombineDomainToRelatedUri(dto.RelatedUrl);
                return(true);
            }

            return(false);
        }
        public async Task <PersonalIntroDto> Get()
        {
            var intro = await Fsql.Select <PersonalIntro>()
                        .WhereCascade(x => x.IsDeleted == false)
                        .ToOneAsync();

            if (intro == null)
            {
                return(null);
            }

            return(new PersonalIntroDto
            {
                Summary = intro.Summary,

                CnDescription = intro.CnDescription,
                CnHonors = intro.CnHonors,
                CnExperiences = intro.CnExperiences,

                EnDescription = intro.EnDescription,
                EnHonors = intro.EnHonors,
                EnExperiences = intro.EnExperiences,
            });
        }
示例#5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                //                app.UseHsts();
            }
            //配置跨域
            app.UseCors("LimitRequests");
            // 启动Response缓存
            app.UseResponseCaching();
            app.UseResponseCompression();
            // URL重写
            app.UseRewriter(new RewriteOptions().AddRedirectToNonWww());
            //注入静态HttpContext对象
            app.UseStaticHttpContext();
            //注入Session
            app.UseSession();
            //app.UseHttpsRedirection();
            app.UseStaticFiles(new StaticFileOptions //静态资源缓存策略
            {
                OnPrepareResponse = ctx =>
                {
                    ctx.Context.Response.Headers[HeaderNames.CacheControl] = "public,no-cache";
                    ctx.Context.Response.Headers[HeaderNames.Expires]      = DateTime.UtcNow.AddDays(7).ToString("R");
                },
                ContentTypeProvider = new FileExtensionContentTypeProvider(MimeMapper.MimeTypes)
            });
            app.UseCookiePolicy();
            //启用网站防火墙
            app.UseRequestIntercept();
            if (AppConfig.IsDebug)
            {
                //初始化系统设置参数
                GlobalConfig.TalentId = 10001;
                var settings = Fsql.Select <Setting>().ToList();
                GlobalConfig.SystemSettings = settings.ToDictionary(s => s.Key, s => JObject.Parse(s.Values));
                //                var wxapp = Fsql.Select<Wxapp>().Where(l => l.WxappId == GlobalConfig.TalentId).ToOneAsync();
                //                GlobalConfig.WxappConfig = wxapp.Mapper<WxappConfig>();
            }
            // 返回错误码
            app.UseStatusCodePages();//把错误码返回前台,比如是404
            app.UseRouting();
            //配置路由
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");

                endpoints.MapControllerRoute(
                    name: "area",
                    pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");

                endpoints.MapRazorPages();
            });
        }
示例#6
0
        public async Task <(IEnumerable <object>, long)> GetList(ArtworkQueryDto queryDto)
        {
            var list = await Fsql.Select <Artwork>()
                       .WhereIf(!queryDto.Name.IsNullOrWhiteSpace(), a => a.Name.Contains(queryDto.Name))
                       .WhereCascade(x => x.IsDeleted == false)
                       .OrderByDescending(a => a.OnTop)
                       .OrderByDescending(a => a.CompletionTime)
                       .OrderByDescending(a => a.CreationTime)
                       .Count(out var count)
                       .Page(queryDto.Page, queryDto.PageSize)
                       .ToListAsync(i => new ArtworkOutputDto
            {
                Id          = i.Id,
                Name        = i.Name,
                Description = i.Description,
                CoverImage  = new ImageOutputDto
                {
                    RelatedUrl = i.CoverImage
                },
                CompletionTime = i.CompletionTime,
                OnTop          = i.OnTop,
            });

            foreach (var item in list)
            {
                item.CoverImage.Id     = 999999;
                item.CoverImage.Name   = "cover";
                item.CoverImage.Status = UploadStatus.Done;
                item.CoverImage.Url    = CombineDomainToRelatedUri(item.CoverImage.RelatedUrl);
            }

            if (queryDto.Full != ImgQuery.Full)
            {
                return(list, count);
            }

            var artworkIds = list.Select(i => i.Id).ToList();
            var items      = await Fsql.Select <ArtworkItem>()
                             .Where(i => artworkIds.Contains(i.ArtworkId))
                             .WhereCascade(x => x.IsDeleted == false)
                             .OrderBy(i => i.Seq)
                             .ToListAsync(i => new
            {
                Id        = i.Id,
                ArtworkId = i.ArtworkId,
                Name      = i.LocalName,
                Image     = i.RelatedUrl,
            });

            var artworkWithItems = list.Select(i => new ArtworkWithItemOutputDto
            {
                Id             = i.Id,
                Name           = i.Name,
                Description    = i.Description,
                CoverImage     = i.CoverImage,
                CompletionTime = i.CompletionTime,
                OnTop          = i.OnTop,
                Items          = new ImageOutputDto[] { },
            }).ToList();

            foreach (var artwork in artworkWithItems)
            {
                artwork.Items = items.Where(item => item.ArtworkId == artwork.Id).Select(item => new ImageOutputDto
                {
                    Id         = item.Id,
                    Name       = item.Name,
                    Status     = UploadStatus.Done,
                    RelatedUrl = item.Image,
                    Url        = CombineDomainToRelatedUri(item.Image),
                }).ToArray();
            }

            return(artworkWithItems, count);
        }