示例#1
0
        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());
            }

            var        SelectedUser = _showroomerRepository.Find(item.ShowroomerId);
            Showroomer showroomer   = new Showroomer();

            showroomer              = SelectedUser;
            showroomer.Showrooms    = null;
            showroomer.Orders       = null;
            showroomer.Vouchers     = null;
            showroomer.Interactions = null;

            item.Showroomer = showroomer;

            var     SelectedProduct = _productRepository.Find(item.ProductId);
            Product Product         = new Product();

            Product              = SelectedProduct;
            Product.Showrooms    = null;
            Product.Interactions = null;
            Product.Orders       = null;
            Product.Images       = null;
            item.Product         = Product;



            // Unset variables that are unused
            SelectedUser    = null;
            showroomer      = null;
            SelectedProduct = null;
            Product         = null;

            return(new ObjectResult(item));
        }
        public IEnumerable <Voucher> GetAll()
        {
            List <Voucher> ListVoucher = new List <Voucher>();

            foreach (Voucher VoucherOne in _repository.GetAll())
            {
                Voucher NewVoucher = new Voucher();
                NewVoucher = VoucherOne;
                Showroomer UpdatedUser = new Showroomer();
                var        OldUser     = _showroomerRepository.Find(VoucherOne.UserId);
                UpdatedUser              = OldUser;
                UpdatedUser.Vouchers     = null;
                UpdatedUser.Showrooms    = null;
                UpdatedUser.Orders       = null;
                UpdatedUser.Interactions = null;
                NewVoucher.User          = UpdatedUser;
                ListVoucher.Add(NewVoucher);
            }
            return(ListVoucher);
        }
        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));
        }