public void CreateDefaultTrashItems(string companyName) { //find the company name in the trash item table id not in the table then create a new row and fill // it with defaults else ignore try { DataContext dc = new DataContext(); TrashItems defaultItems = new TrashItems(); defaultItems.CompanyName = companyName; defaultItems.ItemName1 = "Plastic"; defaultItems.ItemName2 = "Glass"; defaultItems.ItemName3 = "Polythene"; defaultItems.ItemName4 = "E-waste"; defaultItems.ItemName5 = "Cardboard"; using (dc) { dc.trashItemModel.Add(defaultItems); dc.SaveChanges(); } } catch (Exception) { throw; } }
public List <string> FindItemList(TrashItems trashItemsList) { List <string> finalItemList = new List <string>(); List <string> itemList = ItemListWithNullValues(trashItemsList); for (int i = 0; i < itemList.Count(); i++) { if (itemList[i] != null && itemList[i] != "") { finalItemList.Add(itemList[i]); } } return(finalItemList); }
private List <string> ItemListWithNullValues(TrashItems trashItemsList) { List <string> itemList = new List <string>(); itemList.Add(trashItemsList.ItemName1); itemList.Add(trashItemsList.ItemName2); itemList.Add(trashItemsList.ItemName3); itemList.Add(trashItemsList.ItemName4); itemList.Add(trashItemsList.ItemName5); itemList.Add(trashItemsList.ItemName6); itemList.Add(trashItemsList.ItemName7); itemList.Add(trashItemsList.ItemName8); itemList.Add(trashItemsList.ItemName9); itemList.Add(trashItemsList.ItemName10); return(itemList); }
public void ItemTableUpdateItemNames(string[] itemNameList, UserModel um) { var trashItemNamesList = db.trashItemModel.Where(c => c.CompanyName == um.CompanyName).FirstOrDefault(); var tableId = trashItemNamesList.TableID; var trashItem = new TrashItems() { TableID = tableId, ItemName1 = itemNameList[0], ItemName2 = itemNameList[1], ItemName3 = itemNameList[2], ItemName4 = itemNameList[3], ItemName5 = itemNameList[4], ItemName6 = itemNameList[5], ItemName7 = itemNameList[6], ItemName8 = itemNameList[7], ItemName9 = itemNameList[8], ItemName10 = itemNameList[9], ItemName11 = itemNameList[10], ItemName12 = itemNameList[11], ItemName13 = itemNameList[12], ItemName14 = itemNameList[13], ItemName15 = itemNameList[14] }; using (DataContext db = new DataContext()) { db.trashItemModel.Attach(trashItem); db.Entry(trashItem).Property(x => x.ItemName1).IsModified = true; db.Entry(trashItem).Property(x => x.ItemName2).IsModified = true; db.Entry(trashItem).Property(x => x.ItemName3).IsModified = true; db.Entry(trashItem).Property(x => x.ItemName4).IsModified = true; db.Entry(trashItem).Property(x => x.ItemName5).IsModified = true; db.Entry(trashItem).Property(x => x.ItemName6).IsModified = true; db.Entry(trashItem).Property(x => x.ItemName7).IsModified = true; db.Entry(trashItem).Property(x => x.ItemName8).IsModified = true; db.Entry(trashItem).Property(x => x.ItemName9).IsModified = true; db.Entry(trashItem).Property(x => x.ItemName10).IsModified = true; db.Entry(trashItem).Property(x => x.ItemName11).IsModified = true; db.Entry(trashItem).Property(x => x.ItemName12).IsModified = true; db.Entry(trashItem).Property(x => x.ItemName13).IsModified = true; db.Entry(trashItem).Property(x => x.ItemName14).IsModified = true; db.Entry(trashItem).Property(x => x.ItemName15).IsModified = true; db.SaveChanges(); } }