Beispiel #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         var repo = new LinkRepository();
         gridLinks.DataSource = repo.GetAll();
         gridLinks.DataBind();
     }
 }
Beispiel #2
0
 public JsonResult GetAll()
 {
     return(new JsonResult(new
     {
         links = _linkRepo.GetAll().ToList().Select(l => new LinkViewModel
         {
             Id = l.Id,
             Title = l.Title,
             LinkURL = l.LinkURL,
             Rating = l.Rating,
             Date = l.Date,
             UserName = _context.ApplicationUser.Where(au => au.Id == l.UserId).FirstOrDefault().UserName,
             UserId = l.UserId,
             Category = l.CategoryName
         })
     }));
 }
Beispiel #3
0
        /// <summary>
        /// 更新友情链接附件
        /// </summary>
        /// <returns></returns>
        private bool UpdateLinkBySQL(out string message)
        {
            int           allCount       = 0;
            int           moveCount      = 0;
            bool          result         = false;
            StringBuilder messageBuilder = new StringBuilder();

            LinkRepository           linkRepository = new LinkRepository();
            IEnumerable <LinkEntity> imageLinks     = linkRepository.GetAll().Where(n => n.LinkType == LinkType.ImageLink).Where(n => !string.IsNullOrEmpty(n.ImageUrl));

            Directory.SetCurrentDirectory(currentDirectory);

            allCount = imageLinks.Count();

            foreach (var link in imageLinks)
            {
                string newRelativePath = GetRelativePathById(link.LinkId, "Link");
                string oldSubDirectory = string.Empty;

                if (link.OwnerType == OwnerTypes.Instance().Group())
                {
                    oldSubDirectory = "Club";
                }
                else if (link.OwnerType == OwnerTypes.Instance().Site())
                {
                    oldSubDirectory = "Site";
                }
                else if (link.OwnerType == OwnerTypes.Instance().User())
                {
                    oldSubDirectory = "User";
                }

                if (!string.IsNullOrEmpty(oldSubDirectory))
                {
                    string oldDirectory = Path.Combine(currentDirectory, GetOldLinkRelativePath("LinkImages", oldSubDirectory, link.OwnerId));
                    foreach (var oldFile in Directory.GetFiles(oldDirectory))
                    {
                        FileInfo oldFileInfo = new FileInfo(oldFile);
                        if (link.ImageUrl.Contains(oldFileInfo.Name))
                        {
                            string newFilePath = Path.Combine(newRelativePath, oldFileInfo.Name);
                            if (!Directory.Exists(newRelativePath))
                            {
                                Directory.CreateDirectory(newRelativePath);
                            }
                            if (!System.IO.File.Exists(newFilePath))
                            {
                                System.IO.File.Move(oldFile, newFilePath);
                                storeProvider.GetResizedImage(newRelativePath, oldFileInfo.Name, new Size(150, 50), Tunynet.Imaging.ResizeMethod.KeepAspectRatio);
                                moveCount++;
                            }
                            break;
                        }
                    }
                }
            }
            if (allCount > 0)
            {
                messageBuilder.AppendFormat("{0}:一共找到{1}个可以升级的友情链接图片", Path.Combine(currentDirectory, "Old", "LinkImages"), allCount);
                if (moveCount > 0)
                {
                    result = true;
                    messageBuilder.AppendFormat(",成功升级了{0}个友情链接图片", moveCount);
                }
            }
            message = messageBuilder.ToString();
            return(result);
        }