public void addBill(int _houseID, string _billType, double _amount, DateTime dueDate, string[] _tenantID, string[] _tenantAmounts) { using (var context = new houseMateEntities01()) { // create a new house bill house_bill newHouseBill = new house_bill { FK_houseID = _houseID, billType = _billType, amount = _amount, dueDate = dueDate, paid_ = 0 }; context.house_bill.Add(newHouseBill); context.SaveChanges(); // create individual bills for each tenant in the house for (int i = 0; i < _tenantID.Length; i++) { if(_tenantAmounts[i] != "0") { individual_bills newIndividualBill = new individual_bills { FK_houseBillID = newHouseBill.PK_houseBillID, FK_tenantID = Convert.ToInt32(_tenantID[i]), splitAmount = Convert.ToDouble(_tenantAmounts[i]) }; context.individual_bills.Add(newIndividualBill); context.SaveChanges(); } } } }
public House createHouse(string housename, string password, int userID, string _addr, string _city, string _state) { using (var context = new houseMateEntities01()) { if (!houseExists(housename)) { if (getTID(userID) <= 0) { // create the new house house newHouse = new house { houseName = housename, password = password, address = _addr, city = _city, state = _state }; context.houses.Add(newHouse); context.SaveChanges(); // create the list for that house list newList = new list { FK_houseID = newHouse.PK_houseID }; context.lists.Add(newList); context.SaveChanges(); // create the notice board for that house notice_board newNBoard = new notice_board { FK_houseID = newHouse.PK_houseID }; context.notice_board.Add(newNBoard); context.SaveChanges(); return joinHouse(housename, password, userID); } else { return new House(-1, "already in a house"); } } else { return new House(-1, "house doesn't exist"); } } }
public void addItem(int houseID, string name_, string desc_, string category_) { using (var context = new houseMateEntities01()) { int listID = getListID(houseID); bool added = false; item newItem = new item { FK_listID = listID, name = name_, category = category_, bought_ = 0, description = desc_ }; var itemArr = from item in context.items where item.FK_listID == listID select item; List<item> itemList = new List<item>(); itemList.AddRange(itemArr); foreach (item i in itemList) { if (!added) { if (i.name.ToLower().Equals(newItem.name.ToLower()) && i.description.ToLower().Equals(newItem.description.ToLower())) { i.bought_ = 0; context.SaveChanges(); added = true; } } } if (!added) { context.items.Add(newItem); context.SaveChanges(); } } }
public void addChore(int houseID, string choreName_) { using (var context = new houseMateEntities01()) { chore newChore = new chore { FK_houseID = houseID, choreName = choreName_ }; context.chores.Add(newChore); context.SaveChanges(); } }
public void buyItem(int itemID) { using (var context = new houseMateEntities01()) { var boughtItem = (from item in context.items where item.PK_itemID == itemID select item).FirstOrDefault(); boughtItem.bought_ = 1; context.SaveChanges(); //Record purchase here } }
public void allocateChore(int houseID, string cName, int tenantID, string dayOfWeek_, int cycle_) { using (var context = new houseMateEntities01()) { chore chore_ = context.chores.First(c=>c.FK_houseID == houseID && c.choreName.Equals(cName)); chore_allocation newAllocation = new chore_allocation { FK_choreID = chore_.PK_choreID, FK_tenantID = tenantID, dayOfWeek = dayOfWeek_, cycle = (sbyte)cycle_ }; context.chore_allocation.Add(newAllocation); context.SaveChanges(); } }
public void updateRegID(int tenID, string regID) { using (var context = new houseMateEntities01()) { try { var ten1 = (from t in context.tenants where t.PK_tenantID == tenID select t).FirstOrDefault(); ten1.registrationID = regID; context.SaveChanges(); } catch { } } }
public void setInfo(int houseID, string houseName, string housePwd, string wifi, string binNight, string recOrGre) { using (var context = new houseMateEntities01()) { house currH = context.houses .First(h => h.PK_houseID == houseID); if (houseName != "") currH.houseName = houseName; if (housePwd != "") currH.password = housePwd; if(wifi != "") currH.wifiPass = wifi; if (binNight != "") currH.binNight = binNight; if (recOrGre != "") { if (recOrGre == "recycling") currH.recycOrGreen = 0; else currH.recycOrGreen = 1; } context.SaveChanges(); } }
//public string getHouseName(int houseID) //{ // using (var context = new houseMateEntities01()) // { // return context.houses // .Where(h=> h.PK_houseID == houseID) // .Select(h=> h.houseName).Single(); // } //} //public string getHousePass(int houseID) //{ // using (var context = new houseMateEntities01()) // { // return context.houses // .Where(h => h.PK_houseID == houseID) // .Select(h => h.password).Single(); // } //} //public void setHouseName(int houseID, string newHouseName) //{ // using (var context = new houseMateEntities01()) // { // house current = context.houses // .First(h=> h.PK_houseID == houseID); // current.houseName = newHouseName; // context.SaveChanges(); // } //} //public void setHousePass(int houseID, string newHousePass) //{ // using (var context = new houseMateEntities01()) // { // house current = context.houses // .First(h => h.PK_houseID == houseID); // current.password = newHousePass; // context.SaveChanges(); // } //} public int leaveHouse(int uid) { using (var context = new houseMateEntities01()) { try { tenant current = context.tenants .First(t => t.my_aspnet_membership.userId == uid); current.isCurrent = 1; context.SaveChanges(); return 1; } catch { return -1; } } }
public House joinHouse(string houseName, string password, int userID) { using (var context = new houseMateEntities01()) { if (getTID(userID) <= 0) { int hID = Convert.ToInt32(context.houses .Where(h => h.houseName.Equals(houseName) && h.password.Equals(password)) .Select(h => h.PK_houseID).FirstOrDefault()); tenant newTennant = new tenant { FK_houseID = hID, FK_aspMemberID = userID }; context.tenants.Add(newTennant); context.SaveChanges(); return getHouse(userID); } else { return new House(-1, "already in a house"); } } }
public void payBill(int billID, int tenantID) { using (var context = new houseMateEntities01()) { // select the individual bill for the tenant and mark it as paid individual_bills bill = context.individual_bills .First(i => i.FK_houseBillID == billID && i.FK_tenantID == tenantID); bill.datePaid = DateTime.Now; context.SaveChanges(); // if all tenants have paid this bill then mark the whole bill as paid if(CheckFullyPaid(billID)) { house_bill mainBill = context.house_bill .First(b=>b.PK_houseBillID == billID); mainBill.paid_ = 1; context.SaveChanges(); } // Record payment here } }