Exemplo n.º 1
0
        public static Listing CreateListing(CreateListingInput input)
        {
            Category c = Category.GetCategoryByName(input.CategoryName);

            if (c == null)
            {
                CreateCategoryInput cInput = new CreateCategoryInput(input.CategoryName);
                c = Category.CreateCategory(cInput);
            }

            Listing item = new Listing()
            {
                Username     = input.Username,
                ItemName     = input.ItemName,
                ItemContent  = input.ItemContent,
                ItemPrice    = input.ItemPrice,
                CategoryName = c.Name,
                CreateTime   = DateTime.Now,
            };

            Listing dbItem = StorageImpl.CreateListing(item);

            Category.UpdateCount(input.CategoryName, true);

            return(dbItem);
        }
Exemplo n.º 2
0
        public static Category CreateCategory(CreateCategoryInput input)
        {
            Category item = new Category()
            {
                Count = 0,
                Name  = input.Name
            };

            return(StorageImpl.CreateCategory(item));
        }
Exemplo n.º 3
0
        public static Listing GetListingByID(int id)
        {
            Listing dbItem = StorageImpl.QueryListingByID(id);

            if (dbItem != null)
            {
                return(dbItem);
            }

            return(null);
        }
Exemplo n.º 4
0
        public static Category GetCategoryByName(string name)
        {
            Category dbItem = StorageImpl.QueryCategoryByName(name);

            if (dbItem != null)
            {
                return(dbItem);
            }

            return(null);
        }
Exemplo n.º 5
0
        public static User GetUserByUsername(string usernameInput)
        {
            string username = usernameInput.ToLower();
            User   dbItem   = StorageImpl.QueryUser(username);

            if (dbItem != null)
            {
                return(dbItem);
            }

            return(null);
        }
Exemplo n.º 6
0
        public static bool DeleteListing(int id)
        {
            Listing target = GetListingByID(id);

            if (target == null)
            {
                return(false);
            }

            if (!StorageImpl.DeleteListingByID(id))
            {
                return(false);
            }

            Category.UpdateCount(target.CategoryName, false);
            return(true);
        }
Exemplo n.º 7
0
        public static User CreateUser(string usernameInput)
        {
            string username = usernameInput.ToLower();

            if (StorageImpl.QueryUser(username) != null)
            {
                return(null); // todo error
            }

            User u = new User
            {
                UserName = username,
                ID       = getID()
            };

            StorageImpl.CreateUser(u);

            return(u);
        }
Exemplo n.º 8
0
        public static List <Listing> GetListingByCategory(string categoryName, string sortBy, bool isAsc)
        {
            List <Listing> lst = StorageImpl.QueryListingByCategory(categoryName);

            IEnumerable <Listing> query;

            if (sortBy == "sort_price" && isAsc)
            {
                query = from item in lst
                        orderby item.ItemPrice
                        select item;
            }
            else if (sortBy == "sort_price" && !isAsc)
            {
                query = from item in lst
                        orderby item.ItemPrice descending
                        select item;
            }

            else if (sortBy == "sort_time" && isAsc)
            {
                query = from item in lst
                        orderby item.CreateTime
                        select item;
            }
            else // if (sortBy == "sort_time" && !isAsc)
            {
                query = from item in lst
                        orderby item.CreateTime descending
                        select item;
            }


            List <Listing> ret = new List <Listing>();

            foreach (Listing l in query)
            {
                ret.Add(l);
            }

            return(ret);
        }
Exemplo n.º 9
0
 public static bool UpdateCount(string name, bool isAddOne)
 {
     return(StorageImpl.UpdateCategoryCount(name, isAddOne));
 }
Exemplo n.º 10
0
 public static List <Category> GetTopCategory()
 {
     return(StorageImpl.GetTopCategory());
 }