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 }));
        }
Example #2
0
 public async Task <ActionResult <List <Laboratory_item> > > Gets(int labID)
 {
     return(await LabItemDB.GetAllByLabIDAsync(labID));
 }