public IActionResult Index(string?toolName, string?time)
        {
            ViewData["Page1"] = "select";
            ViewData["Page2"] = "unselect";
            ViewData["Page3"] = "unselect";
            dynamic        mymodel = new ExpandoObject();
            List <Tool>    tool    = new List <Tool>();
            List <History> history = new List <History>();

            // Console.WriteLine(JsonConvert.SerializeObject(mydata, Formatting.Indented));
            tool    = _toolService.Get();
            history = _historyService.Get();
            List <History> temp = new List <History>();

            if (toolName != null)
            {
                // Console.WriteLine("1");
                foreach (var item in history)
                {
                    if (item.createTime == item.lendTime && item.toolName == toolName)
                    {
                        temp.Add(item);
                    }
                }
            }
            else
            {
                // Console.WriteLine("2");
                foreach (var item in history)
                {
                    if (item.createTime == item.lendTime)
                    {
                        temp.Add(item);
                    }
                }
            }
            List <History> sort   = temp.OrderByDescending(history => history.rentTime).ToList();
            List <History> result = new List <History>();

            //Console.WriteLine(JsonConvert.SerializeObject(sort, Formatting.Indented));
            if (time != null)
            {
                foreach (var item in sort)
                {
                    if (item.rentTime.ToString("HH:mm") == time)
                    {
                        result.Add(item);
                    }
                }
            }
            else
            {
                result = sort;
            }
            mymodel.tool    = tool;
            mymodel.history = result;
            return(View(mymodel));
        }
        public async Task <ActionResult <List <ToolGroup> > > Get([FromHeader] string authToken)
        {
            if (!await _authenticationService.CheckAccess(authToken, "stuToolView"))
            {
                return(Unauthorized());
            }

            List <ToolGroup> toolGroups = await _toolService.Get();

            if (!await _authenticationService.CheckAccess(authToken, "stuToolMgr"))
            {
                List <ToolGroup> activeToolGroups = new List <ToolGroup>();

                foreach (ToolGroup toolGroup in toolGroups)
                {
                    if (toolGroup.Status != "Active")
                    {
                        continue;
                    }

                    List <Tool> activeTools = new List <Tool>();

                    foreach (Tool tool in toolGroup.Tools)
                    {
                        if (tool.Status != "Active")
                        {
                            continue;
                        }

                        activeTools.Add(tool);
                    }

                    toolGroup.Tools = activeTools;

                    activeToolGroups.Add(toolGroup);
                }

                return(activeToolGroups);
            }

            return(toolGroups);
        }
Пример #3
0
 public ActionResult <List <Tool> > Get() =>
 _toolService.Get();
Пример #4
0
        public async Task <Tool> Get(string id)
        {
            Tool tool = await _toolService.Get(id);

            return(tool);
        }
        public ActionResult <List <ExternalApi> > Get()
        {
            List <Tool>    tools      = _toolService.Get();
            List <History> allHistory = _historyService.Get();
            List <History> history    = new List <History>();

            foreach (var lend in allHistory)
            {
                if (lend.createTime == lend.lendTime)
                {
                    history.Add(lend);
                }
            }

            DateTime           date   = DateTime.Now;
            List <ExternalApi> result = new List <ExternalApi>();

            foreach (var tool in tools)
            {
                ExternalApi temp = new ExternalApi();
                temp.toolName = tool.toolName;
                temp.room     = tool.room;
                temp.maxCount = tool.maxCount;
                var            nEquipment = tool.maxCount;
                List <History> isLend     = new List <History>();


                for (var item = 1; item < history.Count; item++)
                {
                    if (DateTime.Compare(history[item].rentTime.AddMinutes(70), DateTime.Now) < 0)
                    {
                        nEquipment--;
                    }
                }
                // Console.WriteLine(nEquipment);
                int[] nInEachTime = { nEquipment, nEquipment, nEquipment, nEquipment, nEquipment, nEquipment };
                for (var i = 0; i < nInEachTime.Length; i++)
                {
                    if (i > 2)
                    {
                        foreach (var j in history)
                        {
                            if (DateTime.Compare(j.rentTime, history[0].rentTime.AddHours(10 + i).AddMinutes(30)) == 0)
                            {
                                nInEachTime[i]--;
                            }
                        }
                    }
                    else
                    {
                        foreach (var j in history)
                        {
                            if (DateTime.Compare(j.rentTime, history[0].rentTime.AddHours(9 + i).AddMinutes(30)) == 0)
                            {
                                nInEachTime[i]--;
                            }
                        }
                    }
                }
                temp.slot1 = nInEachTime[0];
                temp.slot2 = nInEachTime[1];
                temp.slot3 = nInEachTime[2];
                temp.slot4 = nInEachTime[3];
                temp.slot5 = nInEachTime[4];
                temp.slot6 = nInEachTime[5];
                result.Add(temp);
            }

            return(Ok(result));
        }