コード例 #1
0
ファイル: AlbumService.cs プロジェクト: Oldsooh/XGDG
        /// <summary>
        /// 添加专辑及其图片
        /// </summary>
        /// <param name="album">专辑</param>
        /// <param name="images">所属图片</param>
        /// <returns>是否添加成功</returns>
        public bool AddAlbum(Album album, List<Image> images)
        {
            bool result = false;
            var conn = DBRepository.GetSqlConnection();
            try
            {
                conn.Open();
                if (album != null && images != null && images.Count > 0)
                {
                    album.ImagesCount = images.Count;
                    album.UrlOriginal = images[0].UrlOriginal;
                    album.UrlThumbnailWidth102x102 = images[0].UrlThumbnailWidth102x102;
                    album.UrlThumbnailWidth235x350 = images[0].UrlThumbnailWidth235x350;
                    album.UrlThumbnailWidth490x350 = images[0].UrlThumbnailWidth490x350;
                    album.UrlThumbnailHeight200 = images[0].UrlThumbnailHeight200;

                    List<string> filterColumns = new List<string>() { "Id" };
                    int albumId = Int32.Parse(DBRepository.Insert<Album>(album, filterColumns, conn));

                    foreach (var item in images)
                    {
                        item.AlbumId = albumId;
                        DBRepository.Insert<Image>(item, conn, filterColumns);
                    }

                    if (albumId > 0)
                    {
                        result = true;
                    }
                }
            }
            catch (Exception e)
            {
                LogService.Log("添加专辑及其图片", e.ToString());
            }
            finally
            {
                conn.Close();
            }
            return result;
        }
コード例 #2
0
ファイル: AlbumService.cs プロジェクト: Oldsooh/XGDG
        private static void GetHomeAlbums(out List<Album> albums, SqlDataReader reader)
        {
            albums = new List<Album>();
            while (reader.Read())
            {
                Album album = new Album
                {
                    Id = reader[0] != DBNull.Value ? reader.GetInt32(0) : 0,
                    CategoryId = reader[1] != DBNull.Value ? reader.GetString(1) : string.Empty,
                    Title = reader[2] != DBNull.Value ? reader.GetString(2) : string.Empty,
                    Keywords = reader[3] != DBNull.Value ? reader.GetString(3) : string.Empty,
                    Description = reader[4] != DBNull.Value ? reader.GetString(4) : string.Empty,
                    IsDelete = reader[5] != DBNull.Value ? reader.GetBoolean(5) : false,
                    IsShow = reader[6] != DBNull.Value ? reader.GetBoolean(6) : true,
                    IsTop = reader[7] != DBNull.Value ? reader.GetBoolean(7) : true,
                    InsertTime = reader[8] != DBNull.Value ? reader.GetDateTime(8) : DateTime.Now,
                    ViewTime = reader[9] != DBNull.Value ? reader.GetInt32(9) : 0,
                    ImagesCount = reader[10] != DBNull.Value ? reader.GetInt32(10) : 0,
                    UrlOriginal = reader[11] != DBNull.Value ? reader.GetString(11) : string.Empty,
                    UrlThumbnailWidth102x102 = reader[12] != DBNull.Value ? reader.GetString(12) : string.Empty,
                    UrlThumbnailWidth235x350 = reader[13] != DBNull.Value ? reader.GetString(13) : string.Empty,
                    UrlThumbnailWidth490x350 = reader[14] != DBNull.Value ? reader.GetString(14) : string.Empty,
                    UrlThumbnailHeight200 = reader[15] != DBNull.Value ? reader.GetString(15) : string.Empty,
                    UpdatedTime = reader[16] != DBNull.Value ? reader.GetDateTime(16) : DateTime.Now
                };

                albums.Add(album);
            }

            reader.NextResult(); ;
        }
コード例 #3
0
ファイル: ImageController.cs プロジェクト: Oldsooh/XGDG
        public ActionResult Upload(string c, string t, string k, string d, string isShow, string isTop, string urls)
        {
            if (Session["UserId"] == null)
            {
                return Redirect("/admin/");
            }
            UploadModel model = new UploadModel();
            model.CategoryList = categoryService.GetCategories("album");
            model.isSuccessful = "添加失败";
            model.SelectedCategory = c;

            if (!string.IsNullOrEmpty(c) && !string.IsNullOrEmpty(t) && !string.IsNullOrEmpty(urls))
            {
                Album album = new Album();
                album.CategoryId = c;
                album.Title = t;
                album.Keywords = k ?? string.Empty;
                album.Description = d ?? string.Empty;
                album.IsDelete = false;
                album.IsShow = false;
                album.IsTop = false;
                album.InsertTime = DateTime.Now;
                album.ViewTime = 0;
                if (!string.IsNullOrEmpty(isShow) && isShow == "true")
                {
                    album.IsShow = true;
                }
                if (!string.IsNullOrEmpty(isTop) && isTop == "true")
                {
                    album.IsTop = true;
                }

                urls = urls.Substring(0, urls.Length);
                string[] us = urls.Split('|');

                List<Image> images = new List<Image>();
                foreach (var original in us)
                {
                    if (original.Contains(".jpg") || original.Contains(".png") || original.Contains(".gif"))
                    {
                        string imageName = original.Substring(0, original.Length - 4);
                        string filetrype = original.Substring(original.Length - 4, 4);

                        Model.Image image = new Model.Image();
                        image.UrlOriginal = original;
                        image.UrlThumbnailWidth102x102 = imageName + "-102x102" + filetrype;
                        image.UrlThumbnailWidth235x350 = imageName + "-235x350" + filetrype;
                        image.UrlThumbnailWidth490x350 = imageName + "-490x350" + filetrype;
                        image.UrlThumbnailHeight200 = imageName + "-big" + filetrype;

                        images.Add(image);
                    }
                }

                if (albumService.AddAlbum(album, images))
                {
                    model.isSuccessful = "添加成功";
                    //更新首页缓存
                    Cache.UpdateHomeData();
                }
            }
            return View(model);
        }
コード例 #4
0
ファイル: AlbumService.cs プロジェクト: Oldsooh/XGDG
 /// <summary>
 /// 根据Id查询专辑
 /// </summary>
 /// <param name="id">专辑Id</param>
 /// <returns>专辑对象</returns>
 public Album GetAlbumById(int id)
 {
     Album album = new Album();
     var conn = DBRepository.GetSqlConnection();
     try
     {
         conn.Open();
         album = DBRepository.SelectOne<Album>("Id=" + id.ToString() + " and IsDelete=0 and IsShow = 1 ", conn);
         if (album != null)
         {
             DBRepository.UpdateOneColumn<Album>("ViewTime", album.ViewTime + 1, "Id=" + album.Id.ToString(), conn);
         }
     }
     catch (Exception e)
     {
         LogService.Log("查询专辑", e.ToString());
     }
     finally
     {
         conn.Close();
     }
     return album;
 }
コード例 #5
0
ファイル: AlbumService.cs プロジェクト: Oldsooh/XGDG
        public bool UpdateAlbum(Album album)
        {
            bool result = false;
            var conn = DBRepository.GetSqlConnection();
            try
            {
                if (album != null)
                {
                    conn.Open();

                    result = DBRepository.Update<Album>(album, "Id", conn);
                }
            }
            catch (Exception e)
            {
                LogService.Log("添加专辑及其图片", e.ToString());
            }
            finally
            {
                conn.Close();
            }
            return result;
        }