public async Task <ActionResult> Update(string?id, string?date, [FromQuery] string[] itemnames, [FromQuery] string[] removeid)
        {
            foreach (var name in itemnames)
            {
                if (id != null)
                {
                    var labID   = Int16.Parse(id ?? "0");
                    var type    = Int16.Parse(name.Split(' ').Last());
                    int itemIDs = ItemDB.Add(new Item(name.Split(' ')[0], (ItemTypes)type));
                    LabItemDB.AddItem(labID, itemIDs);
                }
            }

            if (id != null)
            {
                foreach (var removeID in removeid)
                {
                    var labID  = Int16.Parse(id ?? "0");
                    var itemID = Int16.Parse(removeID ?? "0");
                    var itemDB = await ItemDB.GetByIDAsync(itemID);

                    var labItemDB = await LabItemDB.GetAllByLabIDAsync(labID);

                    var    db          = new SoftwareStudioContext();
                    string queryString = $"DELETE FROM laboratory_items WHERE item_id = {itemID}; DELETE FROM items WHERE uuid = {itemID}; ";
                    // var items = await db.itemDetails.FromSqlRaw(queryString).ToListAsync();
                    await db.Database.ExecuteSqlRawAsync(queryString);
                }
            }
            return(RedirectToAction("Detail", new { id = id, date = date }));
        }
        public async Task <IActionResult> Detail(string?id, string?date)
        {
            int                labID    = Int16.Parse(id ?? "1");
            DateTime           datetime = DateTime.ParseExact(date ?? DateTime.Now.ToString("yyyy-MM-dd HH:mm"), "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
            Laboratory         lab      = LabDB.GetByID(Int16.Parse(id ?? "1"));
            List <LabItem>     items    = new List <LabItem>();
            IList <ItemDetail> labItems = await ItemDB.GetAllDetailByLabIDAsync(Int16.Parse(id ?? "1"));

            List <List <int> > allQuantity = await LabItemDB.GetCurrentQuantityByDateAsync(datetime);

            List <Transaction> transactions = await TransactionDB.GetByLabIDAndDateAsync(labID, datetime);

            List <int> availableNumber = new List <int> {
                allQuantity[0][labID - 1], allQuantity[1][labID - 1]
            };
            List <Laboratory> labList = await LabDB.GetAllAsync();

            List <int> type = await ItemDB.GetItemSetByLabIDAsync(labID);

            Dictionary <int, string> types = await ItemDB.GetItemSetAsync();

            List <string> realType = new List <string>();

            for (int i = 0; i < labItems.Count; i++)
            {
                var    available = 0;
                string am        = "NO";
                var    pm        = "NO";
                for (int j = 0; j < transactions.Count; j++)
                {
                    if (labItems[i].uuid == transactions[j].item_id)
                    {
                        available = transactions[j].time_id;
                    }
                }
                var pmm = 1 & (available >> 1);
                var amm = 1 & available;
                am = amm == 0 ? "YES" : "NO";
                pm = pmm == 0 ? "YES" : "NO";
                items.Add(new LabItem(labItems[i].uuid.ToString(), labItems[i].name, am, pm));
            }


            foreach (var it in types)
            {
                realType.Add(it.Value.Substring(0, it.Value.Length - 2));
            }

            ViewData["LabItems"]    = items;
            ViewData["Title"]       = labList;
            ViewData["Description"] = lab.description;
            ViewData["LabID"]       = id;
            ViewData["Date"]        = datetime.ToString("yyyy-MM-dd");
            ViewData["Available"]   = availableNumber;
            ViewData["Type"]        = realType;
            ViewData["EnableType"]  = type;

            return(View());
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
0
 public async Task <ActionResult <List <Laboratory_item> > > Gets(int labID)
 {
     return(await LabItemDB.GetAllByLabIDAsync(labID));
 }