/// <summary> /// Get a product with reviews and ratings /// </summary> /// <param name="id">Product id</param> /// <returns>DTO of Product with Reviews and Average rating</returns> public AlzaAdminDTO <ProductBO> GetProduct(int id) { try { //gets the base product with no reviews and ratings var baseProduct = _productRepository.GetProduct(id); //if the product was not found, it cannot be joined with any ratings if (ReferenceEquals(baseProduct, null)) { return(AlzaAdminDTO <ProductBO> .Data(null)); } //average rating of the product var avRating = _productRatingRepository.GetRating(id); //get product reviews and users who submitted the reviews var reviews = _reviewRepository.GetReviews().Where(r => r.ProductId == id).ToList(); var users = _userProfileRepository.GetAllProfiles().Where(p => reviews.Select(r => r.UserId).Contains(p.Id)); reviews = reviews.Join(users, r => r.UserId, p => p.Id, (r, p) => { r.User = p; return(r); }).OrderBy(r => r.Date).ToList(); var product = new ProductBO(baseProduct, avRating, reviews); return(AlzaAdminDTO <ProductBO> .Data(product)); } catch (Exception e) { return(AlzaAdminDTO <ProductBO> .Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/// <summary> /// BY CATEGORY WITH PAGING - GAMES collection /// </summary> /// <param name="categoryName"></param> /// <param name="pageNumber"></param> /// <param name="itemsPerPage"></param> /// <returns></returns> public AlzaAdminDTO GetGames(string categoryName, int pageNumber, int itemsPerPage) { try { ////zjisteni vsech produktu v dane kategorii //var allproducts = _productRepo.Query().ToList(); //List<Product> productWithCategory = new List<Product>(); //foreach (var pr in allproducts) //{ // foreach (var prCat in pr.ProductCategories) // { // if (prCat.Category.Name == categoryName) // { // productWithCategory.Add(pr); // } // } //} ////zjisteni vsech her pro dane produkty //List<Media> gamesWithCategory = new List<Media>(); //List<string> tempArray = new List<string>(); //foreach (var item in productWithCategory) //{ // var fullproduct = _productRepo.Get(item.Id); // foreach (var med in fullproduct.ProductMedia) // { // if (med.Media.MediaType.Value == "Game") // { // if (!tempArray.Contains(med.Media.Name)) // { // gamesWithCategory.Add(med.Media); // tempArray.Add(med.Media.Name); // } // } // } //} ////strankovani //var result = gamesWithCategory.Skip((pageNumber - 1) * itemsPerPage).Take(itemsPerPage).ToList(); var filter = new Dictionary <string, string>(); filter.Add("@PageOffset", ((pageNumber - 1) * itemsPerPage).ToString()); filter.Add("@PageSize", itemsPerPage.ToString()); filter.Add("@MediaType", "Game"); filter.Add("@CategoryName", categoryName); var result = _mediaRepo.Query(filter).ToList(); return(AlzaAdminDTO.Data(result)); } catch (Exception e) { return(Error(e.Message + Environment.NewLine + e.StackTrace)); } }
public AlzaAdminDTO GetProducts(int pageNumber, int itemsPerPage) { try { //var temp = _productRepo.Query().ToList(); ////strankovani //var result = temp.Skip((pageNumber - 1) * itemsPerPage).Take(itemsPerPage).ToList(); //return AlzaAdminDTO.Data(result); var filter = new Dictionary <string, string>(); filter.Add("@PageOffset", ((pageNumber - 1) * itemsPerPage).ToString()); filter.Add("@PageSize", itemsPerPage.ToString()); filter.Add("@CategoryName", null); var result = _productRepo.Query(filter).ToList(); return(AlzaAdminDTO.Data(result)); } catch (Exception e) { return(Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/// <summary> /// Enables to update an already submitted review. /// </summary> /// <param name="review">Review to update with</param> /// <returns>Updated review</returns> public AlzaAdminDTO <Review> UpdateReview(Review review) { try { return(AlzaAdminDTO <Review> .Data(_reviewRepository.UpdateReview(review))); } catch (Exception e) { return(AlzaAdminDTO <Review> .Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/// <summary> /// This method returns a filtered page of products. The product filtering occurs on the database side. /// </summary> /// <param name="parameters">Filtering parameters</param> /// <returns>A filtered page of products</returns> public AlzaAdminDTO <QueryResultWrapper> GetPageADO(QueryParametersWrapper parameters) { try { return(AlzaAdminDTO <QueryResultWrapper> .Data(_filteringRepository.FilterProducts(parameters))); } catch (Exception e) { return(AlzaAdminDTO <QueryResultWrapper> .Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/// <summary> /// This method returns products with applied filtering that can be displayed on the front page. /// </summary> /// <param name="parameter">Specifies the nature of the front page items, orders the products by this parameter.</param> /// <param name="type">Specifies whether the sorting is ascending or descending</param> /// <param name="count">Specifies how many items should be returned</param> /// <param name="categoryId">Specifies the category of the front page products.</param> /// <param name="timeOffset">Limits the age in days of products (by addition time).</param> /// <returns></returns> public AlzaAdminDTO <List <ProductBO> > GetFrontPage(FrontPageParameter parameter, SortType type, int count, int categoryId, int?timeOffset = null) { try { return(AlzaAdminDTO <List <ProductBO> > .Data(_filteringRepository.GetProducts(parameter, type, count, categoryId, timeOffset).ToList())); } catch (Exception e) { return(AlzaAdminDTO <List <ProductBO> > .Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/// <summary> /// Gets a front page preset that can be applied to the method GetFrontPage. /// </summary> /// <param name="id">Id of the preset</param> /// <returns>DTO of the preset item</returns> public AlzaAdminDTO <FrontPageItem> GetFrontPageItem(int id) { try { return(AlzaAdminDTO <FrontPageItem> .Data(_frontPageRepository.GetFrontPageItem(id))); } catch (Exception e) { return(AlzaAdminDTO <FrontPageItem> .Error(e.Message)); } }
/**********************************************/ /* UPDATE ITEM */ /**********************************************/ public AlzaAdminDTO UpdateUserProfile(Dal.Entities.UserProfile item) { try { _userProfileRepo.Update(item); return(AlzaAdminDTO.Data(item)); } catch (Exception e) { return(Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/****************************************/ /* GET COUNTRY BY ID */ /****************************************/ /// <summary> /// Provides a country with a specified id /// </summary> /// <param name="id">Country id</param> /// <returns>DTO containing the country with matching id</returns> public AlzaAdminDTO <Country> GetCountry(int id) { try { var result = _countryRepos.GetCountry(id); return(AlzaAdminDTO <Country> .Data(result)); } catch (Exception e) { return(AlzaAdminDTO <Country> .Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/// <summary> /// Gets all payments /// </summary> /// <returns>DTO of payments</returns> public AlzaAdminDTO <List <Payment> > GetPayments() { try { var payments = _paymentRepository.GetPayments().ToList(); return(AlzaAdminDTO <List <Payment> > .Data(payments)); } catch (Exception e) { return(AlzaAdminDTO <List <Payment> > .Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/// <summary> /// Gets all shippings /// </summary> /// <returns>Shippings</returns> public AlzaAdminDTO <List <Shipping> > GetShippings() { try { var shippings = _shippingRepository.GetShippings().ToList(); return(AlzaAdminDTO <List <Shipping> > .Data(shippings)); } catch (Exception e) { return(AlzaAdminDTO <List <Shipping> > .Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/// <summary> /// Gets a payment by id /// </summary> /// <param name="id">Payment id</param> /// <returns>DTO of the payment</returns> public AlzaAdminDTO <Payment> GetPayment(int id) { try { var payment = _paymentRepository.GetPayment(id); return(AlzaAdminDTO <Payment> .Data(payment)); } catch (Exception e) { return(AlzaAdminDTO <Payment> .Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/// <summary> /// Adds a new order item /// </summary> /// <param name="item">Item to be added</param> /// <returns>DTO of the order item</returns> public AlzaAdminDTO <OrderItem> AddOrderItem(OrderItem item) { try { var orderItem = _orderItemRepository.AddOrderItem(item); return(AlzaAdminDTO <OrderItem> .Data(orderItem)); } catch (Exception e) { return(AlzaAdminDTO <OrderItem> .Error(e.Message + Environment.NewLine + e.StackTrace)); } }
public AlzaAdminDTO GetMedia(int id) { try { var result = _mediaRepo.Get(id); return(AlzaAdminDTO.Data(result)); } catch (Exception e) { return(Error(e.Message + Environment.NewLine + e.StackTrace)); } }
public AlzaAdminDTO GetProductByCode(string code) { try { var result = _productRepo.GetByCode(code); return(AlzaAdminDTO.Data(result)); } catch (Exception e) { return(Error(e.Message + Environment.NewLine + e.StackTrace)); } }
public AlzaAdminDTO GetCategoryBySEOName(string seoName) { try { var result = _categoryRepo.GetBySEOName(seoName); return(AlzaAdminDTO.Data(result)); } catch (Exception e) { return(Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/// <summary> /// Gets all front page presets marked as active. /// </summary> /// <returns>DTO of active Front page items</returns> public AlzaAdminDTO <List <FrontPageItem> > GetActivePageItems() { try { var result = _frontPageRepository.GetFrontPageItems().Where(fi => fi.Active == true).ToList(); return(AlzaAdminDTO <List <FrontPageItem> > .Data(result)); } catch (Exception e) { return(AlzaAdminDTO <List <FrontPageItem> > .Error(e.Message)); } }
public AlzaAdminDTO UpdateMedia(Media item) { try { _mediaRepo.Update(item); return(AlzaAdminDTO.Data(item)); } catch (Exception e) { return(Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/// <summary> /// Gets a shipping by id /// </summary> /// <param name="id">Shipping id</param> /// <returns>DTO of the shipping</returns> public AlzaAdminDTO <Shipping> GetShipping(int id) { try { var shipping = _shippingRepository.GetShipping(id); return(AlzaAdminDTO <Shipping> .Data(shipping)); } catch (Exception e) { return(AlzaAdminDTO <Shipping> .Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/**********************************************/ /* ADD ITEM */ /**********************************************/ public AlzaAdminDTO AddProduct(Product item) { try { _productRepo.Add(item); return(AlzaAdminDTO.Data(item)); } catch (Exception e) { return(Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/// <summary> /// Deletes an item from the cart. /// </summary> /// <param name="visitorId">Id of the item owner</param> /// <param name="productId">Product id</param> /// <returns>DTO of the cart</returns> public AlzaAdminDTO <List <CartItem> > RemoveCartItem(string visitorId, int productId) { try { _cartItemRepository.DeleteCartItem(visitorId, productId); var result = _cartItemRepository.GetCartItems().Where(ci => ci.VisitorId == visitorId).ToList(); return(AlzaAdminDTO <List <CartItem> > .Data(result)); } catch (Exception e) { return(AlzaAdminDTO <List <CartItem> > .Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/**********************************************/ /* GET COLLECTIONS */ /**********************************************/ public AlzaAdminDTO GetUserProfiles() { try { var result = _userProfileRepo.Query().ToList(); return(AlzaAdminDTO.Data(result)); } catch (Exception e) { return(Error(e.Message + Environment.NewLine + e.StackTrace)); } }
public AlzaAdminDTO GetGamesCount(string categoryName) { try { var result = _categoryRepo.GetStats1ByCategoryName(categoryName, "Game"); return(AlzaAdminDTO.Data(result)); } catch (Exception e) { return(Error(e.Message + Environment.NewLine + e.StackTrace)); } }
public AlzaAdminDTO GetCategories() { try { var result = _categoryRepo.Query().ToList().Where(c => c.ParentId != null).ToList(); return(AlzaAdminDTO.Data(result)); } catch (Exception e) { return(Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/****************************************/ /* GET ALL COUNTRIES */ /****************************************/ /// <summary> /// Provides a list of all countries /// </summary> /// <returns>DTO containing a list of all available countries</returns> public AlzaAdminDTO <ICollection <Country> > GetAllCountries() { try { var result = _countryRepos.GetCountries().ToList(); return(AlzaAdminDTO <ICollection <Country> > .Data(result)); } catch (Exception e) { return(AlzaAdminDTO <ICollection <Country> > .Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/// <summary> /// Gets a dictionary of indexed front page slots which contain front page items currently assigned to it. /// </summary> /// <returns>DTO of a dictionary containing all FrontPageSlots</returns> public AlzaAdminDTO <Dictionary <int, FrontPageSlot> > GetPageSlots() { try { var result = _frontPageRepository.GetSlotItems().ToDictionary(si => si.SlotId); return(AlzaAdminDTO <Dictionary <int, FrontPageSlot> > .Data(result)); } catch (Exception e) { return(AlzaAdminDTO <Dictionary <int, FrontPageSlot> > .Error(e.Message)); } }
/// <summary> /// Full - GAMES collection /// </summary> /// <returns></returns> public AlzaAdminDTO GetGames() { try { var result = _mediaRepo.Query("Game").ToList(); return(AlzaAdminDTO.Data(result)); } catch (Exception e) { return(Error(e.Message + Environment.NewLine + e.StackTrace)); } }
//ToDo validate input data (UserProfile properties, index uniqueness,...) /****************************************/ /* GET USER PROFILE */ /****************************************/ /// <summary> /// Provides a UserProfile in DTO.data whose Id property matches the id parameter. /// </summary> /// <param name="id">User id</param> /// <returns>Returns matching UserProfile in DTO data</returns> public AlzaAdminDTO <UserProfile> GetUserProfile(int id) { try { var result = _userRepos.GetProfile(id); return(AlzaAdminDTO <UserProfile> .Data(result)); } catch (Exception e) { return(AlzaAdminDTO <UserProfile> .Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/// <summary> /// Gets a review of a product by a specific user. /// </summary> /// <param name="userId">Id of the user who submitted the review</param> /// <param name="productId">Id of the reviewed product</param> /// <returns>DTO of the review</returns> public AlzaAdminDTO <Review> GetReview(int userId, int productId) { try { var result = _reviewRepository.GetReview(userId, productId); result.User = _userProfileRepository.GetProfile(result.UserId); return(AlzaAdminDTO <Review> .Data(result)); } catch (Exception e) { return(AlzaAdminDTO <Review> .Error(e.Message + Environment.NewLine + e.StackTrace)); } }
/// <summary> /// Merges an anonymous cart with an existing user cart. If there are any items in the user cart, it is possible to delete them or leave them intact. /// </summary> /// <param name="visitorId">Id of the visitor who owns the cart.</param> /// <param name="userId">Id of the user who should receive the visitor cart</param> /// <param name="delete">Specifies whether the old user cart items should be deleted or not</param> /// <returns>DTO of the merged cart</returns> public AlzaAdminDTO <List <CartItem> > TransformCart(string visitorId, int userId, bool delete) { try { //the old items should be deleted if (delete) { var oldCartItems = _cartItemRepository.GetCartItems().Where(ci => ci.UserId == userId).ToList(); foreach (var item in oldCartItems) { _cartItemRepository.DeleteCartItem(item.VisitorId, item.ProductId); } } //gets the visitor cart var currentCart = _cartItemRepository.GetCartItems().Where(ci => ci.VisitorId == visitorId).ToList(); foreach (var item in currentCart) { CartItem existingItem = null; //if we want to keep the items, the amount might need to be updated for the same product if (!delete) { existingItem = _cartItemRepository.GetCartItems().FirstOrDefault(ci => ci.UserId == userId && ci.ProductId == item.ProductId); } if (existingItem != null) { //adding the amounts existingItem.Amount += item.Amount; _cartItemRepository.UpdateCartItem(existingItem); } else { item.VisitorId = userId.ToString(); item.UserId = userId; _cartItemRepository.AddCartItem(item); } //the old cart needs to be deleted afterwards _cartItemRepository.DeleteCartItem(visitorId, item.ProductId); } //the new cart var result = _cartItemRepository.GetCartItems().Where(ci => ci.UserId == userId).ToList(); return(AlzaAdminDTO <List <CartItem> > .Data(result)); } catch (Exception e) { return(AlzaAdminDTO <List <CartItem> > .Error(e.Message + Environment.NewLine + e.StackTrace)); } }