public IEnumerable <Product> GetAllWithRate() { List <Product> ListProductWithRate = new List <Product>(); foreach (Product ProductOne in _repository.GetAll()) { Product NewProduct = new Product(); NewProduct = ProductOne; #region Rate List List <Interaction> RateList = new List <Interaction>(); var RateQuery = from rate in _interactionRepository.GetAll() where rate.ProductId == NewProduct.ProductId select rate; foreach (Interaction rated in RateQuery) { if (rated is Rate) { Interaction RateToAdd = new Interaction(); RateToAdd = rated; RateList.Add(RateToAdd); } } #endregion NewProduct.Interactions = RateList; NewProduct.Showrooms = null; //NewProduct.Interactions = null; NewProduct.Orders = null; NewProduct.Images = null; ListProductWithRate.Add(NewProduct); } return(ListProductWithRate); }
public IActionResult Get() { StringValues hearderValues; var firstValue = string.Empty; if (Request.Headers.TryGetValue("id", out hearderValues)) { firstValue = hearderValues.FirstOrDefault(); } long id = Convert.ToInt64(firstValue); var item = _repository.Find(id); if (item == null) { return(NotFound()); } #region Interactions List // Rate list for the user that he commented for this product List <Interaction> InteractionList = new List <Interaction>(); var InteractionQuery = from interaction in _interactionRepository.GetAll() where interaction.UserId == item.UserId select interaction; foreach (var interaction in InteractionQuery) { Interaction UserRate = new Interaction(); UserRate = interaction; var InteractedProduct = _productRepository.Find(interaction.ProductId); UserRate.Product = InteractedProduct; UserRate.User = null; InteractionList.Add(UserRate); } item.Interactions = InteractionList; #endregion #region Vouchers List // Vouchers List var Query = from voucher in _voucherRepository.GetAll() where voucher.UserId == item.UserId select voucher; List <Voucher> VoucherList = new List <Voucher>(); foreach (var voucher in Query) { Voucher v = new Voucher(); v = voucher; VoucherList.Add(v); } item.Vouchers = VoucherList; // End Vouchers List #endregion // Unset variables that are unused InteractionList = null; InteractionQuery = null; VoucherList = null; Query = null; return(new ObjectResult(item)); }
public IActionResult Get() { StringValues hearderValues; var firstValue = string.Empty; if (Request.Headers.TryGetValue("id", out hearderValues)) { firstValue = hearderValues.FirstOrDefault(); } long id = Convert.ToInt64(firstValue); var item = _repository.Find(id); if (item == null) { return(NotFound()); } #region Interactions List // Rate list for the user that he commented for this product List <Interaction> InteractionList = new List <Interaction>(); var InteractionQuery = from interaction in _interactionRepository.GetAll() where interaction.UserId == item.UserId select interaction; foreach (var interaction in InteractionQuery) { Interaction UserRate = new Interaction(); UserRate = interaction; UserRate.User = null; UserRate.Product = null; InteractionList.Add(UserRate); } item.Interactions = InteractionList; #endregion #region Vouchers List // Vouchers List var Query = from voucher in _voucherRepository.GetAll() where voucher.UserId == item.UserId select voucher; List <Voucher> VoucherList = new List <Voucher>(); foreach (var voucher in Query) { Voucher v = new Voucher(); v = voucher; v.User = null; VoucherList.Add(v); } item.Vouchers = VoucherList; // End Vouchers List #endregion #region Showrooms List // Rate list for the user that he commented for this product List <Showroom> ShowroomList = new List <Showroom>(); var ShowroomQuery = from showroom in _showroomRepository.GetAll() where showroom.ShowroomerId == item.UserId select showroom; foreach (var showroom in ShowroomQuery) { Showroom UserShowroom = new Showroom(); UserShowroom = showroom; // Product that this user accept to be showroom var ProductQuery = from product in _productRepository.GetAll() where product.ProductId == showroom.ProductId select product; if (ProductQuery == null) { UserShowroom.Product = null; } else { Product NewProduct = new Product(); var OldProduct = ProductQuery.First(); NewProduct = OldProduct; NewProduct.Images = null; NewProduct.Interactions = null; NewProduct.Orders = null; NewProduct.Showrooms = null; UserShowroom.Product = NewProduct; } UserShowroom.Showroomer = null; ShowroomList.Add(UserShowroom); } item.Showrooms = ShowroomList; #endregion // Unset variables that are unused InteractionList = null; InteractionQuery = null; VoucherList = null; Query = null; ShowroomList = null; ShowroomQuery = null; return(new ObjectResult(item)); }