Esempio n. 1
0
        public void UpdatePurchase(long id)
        {
            Purchase p = _purchaseRespository.Find(id);

            p.Status = "Order";
            _purchaseRespository.Update(p);
        }
Esempio n. 2
0
        public IEnumerable <DonutEntity> GetCompanyRevenuePerRegion()
        {
            StringValues headersValues;
            string       firstValue = string.Empty;

            if (Request.Headers.TryGetValue("company", out headersValues))
            {
                firstValue = headersValues.FirstOrDefault().Trim();
            }
            string CompanySelected = char.ToUpper(firstValue[0]) + firstValue.Substring(1);

            // List that should be returned and the fun of this method
            List <DonutEntity> ListeDonut = new List <DonutEntity>();

            // Total Revenue for a company
            double TotalRevenue = 0;

            // A dictionnary that contains the total revenue for each region
            Dictionary <string, double> RevenueByRegion = new Dictionary <string, double>();

            // Here we are going to calculate the TotalRevenue and the RevenueByRegion
            foreach (Order OneOrder in _orderRepository.GetAll())
            {
                Product  OrderedProduct = _productRepository.Find(OneOrder.ProductId);
                Purchase Purchased      = _purchaseRepository.Find(OneOrder.PurchaseId);
                User     Buyer          = _userRepository.Find(OneOrder.UserId);
                if (OrderedProduct.Owner == CompanySelected && Purchased.Status == "Order")
                {
                    TotalRevenue += Purchased.Total;
                    string Region = string.Empty;
                    string City   = Buyer.City.Trim();
                    Region = char.ToUpper(City[0]) + City.Substring(1);
                    if (RevenueByRegion.ContainsKey(Region))
                    {
                        RevenueByRegion[Region] = RevenueByRegion[Region] + Purchased.Total;
                    }
                    else
                    {
                        RevenueByRegion.Add(Region, Purchased.Total);
                    }
                }
            }

            // Here we are going to calculate the percentage of Revenue of each region

            foreach (KeyValuePair <string, double> entry in RevenueByRegion)
            {
                DonutEntity RegionDonut = new DonutEntity();
                double      PercentageOfRevenueByRegion = (entry.Value * 100) / TotalRevenue;
                RegionDonut.Label = entry.Key;
                RegionDonut.Value = Math.Round(PercentageOfRevenueByRegion, 2);
                ListeDonut.Add(RegionDonut);
            }

            return(ListeDonut);
        }
        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 || item.UserId == null)
            {
                return(NotFound());
            }

            var  SelectedUser = _userRepository.Find(item.UserId);
            User User         = new Models.User();

            // item.User = SelectedUser;
            User              = SelectedUser;
            User.password     = null;
            User.Interactions = null;
            User.Orders       = null;
            User.Vouchers     = null;
            item.User         = User;

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

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

            var      SelectedPurchase = _purchaseRepository.Find(item.PurchaseId);
            Purchase purchase         = new Purchase();

            purchase        = SelectedPurchase;
            purchase.Orders = null;
            item.Purchase   = purchase;

            // Unset variables that are unused
            SelectedUser     = null;
            User             = null;
            SelectedProduct  = null;
            Product          = null;
            SelectedPurchase = null;
            purchase         = 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());
            }
            item.Orders = null;
            return(new ObjectResult(item));
        }