public string AddLog(string unitID, DateTime timestamp, string action) { DataAccess da = new DataAccess(); //Send til generelt log table if (da.AddLogToMainTable(unitID, timestamp, action)) { //Find out which customer got the ID, then go to below IF statement if (da.UnitExist(unitID)) { string customer = da.getCustomerForUnit(unitID); //RegionH should be replaced by customer if (da.UnitExist(unitID, customer)) { if (da.EventExistForUnit(unitID, action)) { if (da.AddLog(unitID, timestamp, action)) { if (doSpecialEvent(unitID, action, customer)) { return "Log added, special event"; } else { return "Log added, no special event"; } } else { return "Log added to main table - Failed to add to customer table"; } } else { return "Log added to main table - Action not found for unit"; } } else { return "Log added to main database - Unit not found in a customer table"; } } else { return "Log added to main table - Unit not mapped to a customer"; } } //Failed to add log to main database else { return "Failed to add log to main database"; } }
//Check for om hvor vidt kunden / unit / rum eller typen eksisterer i forvejen public string AddUnit(string UnitID, string Room, string type, string customer) { DataAccess da = new DataAccess(); if (!da.UnitExist(UnitID)) { if (da.customerExist(customer)) { if (!da.UnitExist(UnitID, customer)) { if (da.TypeExist(type, customer)) { if (da.RoomExist(Room, customer)) { return AddUnitForCustomer(UnitID, Room, type, customer); } else { //Lav room if (da.AddRoom(Room, customer)) { return AddUnitForCustomer(UnitID, Room, type, customer); } else { return "Failed to add room"; } } } else { if (da.AddType(type, customer)) { if (da.RoomExist(Room, customer)) { return AddUnitForCustomer(UnitID, Room, type, customer); } else { //Create room if (da.AddRoom(Room, customer)) { return AddUnitForCustomer(UnitID, Room, type, customer); } else { return "Failed to add room"; } } } else { return "Failed to add type"; } } } else { return "Unit already exist in your database"; } } else { return "customer doesn't exist"; } } else { return "Unit already exist in Customer Database"; } }