Exemplo n.º 1
0
        public IActionResult Herd(string herdDays)
        {
            int T = 0;

            try
            {
                T = int.Parse(herdDays);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            var repository             = CreateRepository();
            List <YakDetails> herdInfo = repository.GetAll();

            YakUtilities YakUtilities = new YakUtilities();

            YakUtilities.GetHerdStatistics(ref herdInfo, T);

            ViewData["herdInfo"]   = herdInfo;
            ViewData["MaxAge"]     = 10f;
            ViewData["CurrentDay"] = T;
            return(View());
        }
Exemplo n.º 2
0
        public IActionResult Stock(string herdDays)
        {
            int T = 0;

            try
            {
                T = int.Parse(herdDays);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            YakUtilities      YakUtilities = new YakUtilities();
            var               repository   = CreateRepository();
            List <YakDetails> herdInfo     = repository.GetAll();

            var stockInfo = YakUtilities.GetHerdStatistics(ref herdInfo, T);
            var json      = JsonConvert.SerializeObject(stockInfo, Formatting.Indented);

            System.IO.File.WriteAllText(@"JsonFiles\DataStock_JSON.json", json);

            ViewData["stockInfoMilk"]  = Math.Round(stockInfo.Milk, 2);
            ViewData["stockInfoSkins"] = stockInfo.Skins;
            ViewData["CurrentDay"]     = T;
            return(View());
        }
Exemplo n.º 3
0
        public async Task <ActionResult <IEnumerable <YakDetails> > > GetYakDetails(int day)
        {
            var yakList = await _context.YakItems.ToListAsync();

            if (yakList == null)
            {
                return(NotFound());
            }
            var yakUtilities = new YakUtilities();

            yakUtilities.GetHerdStatistics(ref yakList, day);
            return(yakList);
        }
Exemplo n.º 4
0
        public async Task <ActionResult <StockDetails> > GetstockDetails(int day)
        {
            var yakList = await _context.YakItems.ToListAsync();

            if (yakList == null)
            {
                return(NotFound());
            }
            var yakUtilities = new YakUtilities();

            var StockInfo = yakUtilities.GetHerdStatistics(ref yakList, day);

            return(StockInfo);
        }
Exemplo n.º 5
0
        public IActionResult Order(string customerName, string milkOrder, string skinsOrder, string herdDays)
        {
            bool  enoughMilk  = false;
            bool  enoughSkins = false;
            int   T           = 0;
            float milk        = 0;
            int   skins       = 0;

            try
            {
                T     = int.Parse(herdDays);
                milk  = float.Parse(milkOrder);
                skins = int.Parse(skinsOrder);
                T     = int.Parse(herdDays);
                milk  = float.Parse(milkOrder);
                skins = int.Parse(skinsOrder);

                YakUtilities      YakUtilities = new YakUtilities();
                var               repository   = CreateRepository();
                List <YakDetails> herdInfo     = repository.GetAll();

                StockDetails stockInfo = new StockDetails();
                stockInfo = YakUtilities.GetHerdStatistics(ref herdInfo, T);

                if ((stockInfo.Milk - milk) >= 0)
                {
                    enoughMilk = true;
                }
                if ((stockInfo.Skins - skins) >= 0)
                {
                    enoughSkins = true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            HttpResponseMessage message    = OrderMessage(enoughMilk, enoughSkins);
            HttpStatusCode      statusCode = message.StatusCode;

            ViewData["CurrentDay"]  = T;
            ViewData["StatusCode"]  = (int)statusCode;
            ViewData["enoughMilk"]  = enoughMilk;
            ViewData["enoughSkins"] = enoughSkins;
            ViewData["milk"]        = milk;
            ViewData["skins"]       = skins;

            OrderDetails orderInfo = new OrderDetails();

            orderInfo.status = (int)statusCode;
            Order order = new Order();

            if (enoughMilk)
            {
                order.milk = milk;
            }
            if (enoughSkins)
            {
                order.skins = skins;
            }
            orderInfo.order = order;

            var json = JsonConvert.SerializeObject(orderInfo, Formatting.Indented);

            System.IO.File.WriteAllText(@"JsonFiles\DataOrder_JSON.json", json);

            return(View());
        }