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); }
public static Category CreateCategory(CreateCategoryInput input) { Category item = new Category() { Count = 0, Name = input.Name }; return(StorageImpl.CreateCategory(item)); }
public static Listing GetListingByID(int id) { Listing dbItem = StorageImpl.QueryListingByID(id); if (dbItem != null) { return(dbItem); } return(null); }
public static Category GetCategoryByName(string name) { Category dbItem = StorageImpl.QueryCategoryByName(name); if (dbItem != null) { return(dbItem); } return(null); }
public static User GetUserByUsername(string usernameInput) { string username = usernameInput.ToLower(); User dbItem = StorageImpl.QueryUser(username); if (dbItem != null) { return(dbItem); } return(null); }
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); }
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); }
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); }
public static bool UpdateCount(string name, bool isAddOne) { return(StorageImpl.UpdateCategoryCount(name, isAddOne)); }
public static List <Category> GetTopCategory() { return(StorageImpl.GetTopCategory()); }