Ejemplo n.º 1
0
        public static int UpdateFavorite(int favoriteId, string tags, string remark)
        {
            FavoriteDao favoriteDao = new FavoriteDao();
            string      text        = "";

            string[] array = null;
            array = ((!tags.Contains(",")) ? new string[1]
            {
                tags
            } : tags.Split(','));
            string[] array2 = array;
            foreach (string text2 in array2)
            {
                if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(text2.Trim())))
                {
                    favoriteDao.UpdateOrAddFavoriteTags(text2.Trim(), HiContext.Current.UserId);
                    string text3 = tags.Replace(text2, "");
                    int    num   = (tags.Length - text3.Length) / text2.Length;
                    if (num == 1 || !text.Contains(text2))
                    {
                        text = text + DataHelper.CleanSearchString(text2) + ",";
                    }
                }
            }
            if (!string.IsNullOrEmpty(text))
            {
                text = text.Substring(0, text.Length - 1);
            }
            return(new FavoriteDao().UpdateFavorite(favoriteId, tags, remark));
        }
Ejemplo n.º 2
0
        public InsertNewFavoriteResult InsertNewFavorite(int userId, int storyId)
        {
            var maybeStory = Context.Stories.SingleOrDefault(s => s.Id == storyId);
            if (maybeStory == null)
            {
                return InsertNewFavoriteResult.StoryDoesNotExist;
            }

            var maybeUser = Context.Users.Single(u => u.Id == userId);
            if (maybeUser == null)
            {
                return InsertNewFavoriteResult.UserDoesNotExist;
            }

            var alreadyExists = Context.Favorites.Any(f => f.User.Id == userId && f.StoryDao.Id == storyId);

            if (alreadyExists)
            {
                return InsertNewFavoriteResult.IsAlreadyFavorite;
            }

            var dao = new FavoriteDao
            {
                StoryDao = maybeStory,
                User = maybeUser
            };
            Context.Favorites.Add(dao);
            Context.SaveChanges();
            return InsertNewFavoriteResult.Success;
        }
Ejemplo n.º 3
0
        public static string GetFavoriteTags()
        {
            string  text         = string.Empty;
            DataSet favoriteTags = new FavoriteDao().GetFavoriteTags();

            if (favoriteTags.Tables.Count > 0)
            {
                foreach (DataRow dataRow in favoriteTags.Tables[0].Rows)
                {
                    object obj = text;
                    text = string.Concat(new object[]
                    {
                        obj,
                        "{\"TagId\":\"",
                        dataRow["TagId"],
                        "\",\"TagName\":\"",
                        dataRow["TagName"],
                        "\"},"
                    });
                }
            }
            if (text.Length > 1)
            {
                text = text.Substring(0, text.Length - 1);
            }
            return(text);
        }
Ejemplo n.º 4
0
        public static int AddProductToFavorite(int productId, int userId, int storeId = 0)
        {
            FavoriteDao favoriteDao = new FavoriteDao();

            if (favoriteDao.ExistsProduct(productId, userId, storeId))
            {
                return((favoriteDao.DeleteFavorite(userId, productId, storeId) > 0) ? 1 : 0);
            }
            return((ProductBrowser.AddProduct(productId, userId, storeId) > 0) ? 2 : 0);
        }
Ejemplo n.º 5
0
        public static int AddProduct(int productId, int userId, int storeId = 0)
        {
            FavoriteDao favoriteDao = new FavoriteDao();

            if (favoriteDao.ExistsProduct(productId, userId, storeId))
            {
                return(1);
            }
            FavoriteInfo model = new FavoriteInfo
            {
                ProductId = productId,
                UserId    = userId,
                StoreId   = storeId,
                Tags      = ""
            };

            return((int)favoriteDao.Add(model, null));
        }
Ejemplo n.º 6
0
        public static int UpdateFavorite(int favoriteId, string tags, string remark)
        {
            FavoriteDao favoriteDao = new FavoriteDao();
            string      text        = "";

            string[] array;
            if (tags.Contains(","))
            {
                array = tags.Split(new char[]
                {
                    ','
                });
            }
            else
            {
                array = new string[]
                {
                    tags
                };
            }
            string[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                string text2 = array2[i];
                if (!string.IsNullOrEmpty(DataHelper.CleanSearchString(text2.Trim())))
                {
                    favoriteDao.UpdateOrAddFavoriteTags(text2.Trim());
                    string text3 = tags.Replace(text2, "");
                    int    num   = (tags.Length - text3.Length) / text2.Length;
                    if (num == 1 || !text.Contains(text2))
                    {
                        text = text + DataHelper.CleanSearchString(text2) + ",";
                    }
                }
            }
            if (!string.IsNullOrEmpty(text))
            {
                text = text.Substring(0, text.Length - 1);
            }
            return(new FavoriteDao().UpdateFavorite(favoriteId, tags, remark));
        }
Ejemplo n.º 7
0
        public static string GetFavoriteTags()
        {
            if (HiContext.Current.UserId == 0)
            {
                return(string.Empty);
            }
            string  text         = string.Empty;
            DataSet favoriteTags = new FavoriteDao().GetFavoriteTags(HiContext.Current.UserId);

            if (favoriteTags.Tables.Count > 0)
            {
                foreach (DataRow row in favoriteTags.Tables[0].Rows)
                {
                    text = text + "{\"TagId\":\"" + row["TagId"] + "\",\"TagName\":\"" + row["TagName"] + "\"},";
                }
            }
            if (text.Length > 1)
            {
                text = text.Substring(0, text.Length - 1);
            }
            return(text);
        }
Ejemplo n.º 8
0
        public static bool AddProductToFavorite(int productId, int userId)
        {
            FavoriteDao dao = new FavoriteDao();

            return(dao.ExistsProduct(productId, userId) || dao.AddProductToFavorite(productId, userId));
        }
Ejemplo n.º 9
0
        public static DataTable GetFavoritesTypeTags()
        {
            FavoriteDao favoriteDao = new FavoriteDao();

            return(favoriteDao.GetTypeTags(HiContext.Current.UserId));
        }
Ejemplo n.º 10
0
 public FavoriteService(FavoriteDao favoriteDao)
 {
     _favoriteDao = favoriteDao;
 }
Ejemplo n.º 11
0
 public static bool AddProductToFavorite(int productId, int userId)
 {
     FavoriteDao dao = new FavoriteDao();
     return (dao.ExistsProduct(productId, userId) || dao.AddProductToFavorite(productId, userId));
 }
Ejemplo n.º 12
0
        public static DataTable GetFavoritesTypeTags()
        {
            FavoriteDao favoriteDao = new FavoriteDao();

            return(favoriteDao.GetTypeTags());
        }
Ejemplo n.º 13
0
        public static int AddProduct(int productId, int userId)
        {
            FavoriteDao favoriteDao = new FavoriteDao();

            return(favoriteDao.AddProduct(productId, userId));
        }
Ejemplo n.º 14
0
        public static bool CollectProduct(int productId, int userId, string tags, string remark)
        {
            FavoriteDao favoriteDao = new FavoriteDao();

            return(favoriteDao.AddProductToFavorite(productId, userId, tags, remark));
        }