예제 #1
0
        public async Task <ActionResult> GetQuantity(int labID, int itemType, int timestamp)
        {
            DateTime date = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

            date = date.AddSeconds(timestamp);

            List <Transaction> transactions = await TransactionDB.GetByLabIDTypeAndDateAsync(labID, itemType, date);

            int allItems = await LabItemDB.GetLabItemCountByLabIDAndType(labID, itemType);

            int amTimeSlot = allItems;
            int pmTimeSlot = allItems;

            foreach (var transaction in transactions)
            {
                switch (transaction.time_id)
                {
                case (int)Time_id_type.AM:
                    amTimeSlot--;
                    break;

                case (int)Time_id_type.PM:
                    pmTimeSlot--;
                    break;

                case (int)Time_id_type.Day:
                    amTimeSlot--;
                    pmTimeSlot--;
                    break;

                case (int)Time_id_type.none:
                    break;

                default:
                    break;
                }
            }

            string  jsonString = $@"{{
                am: {amTimeSlot},
                pm: {pmTimeSlot},
            }}";
            JObject result     = JObject.Parse(jsonString);

            return(Json(result));
        }