public ActionResult Index() { //SQL Server SQLDALManager manager = new SQLDALManager("dbConnKey"); DataTable allUsers = manager.ExecuteStoredProcedure("getAllUsers"); List <UserData> usersList = new List <UserData>(); List <UserPhoneBookData> phonebook = new List <UserPhoneBookData>(); foreach (DataRow dr in allUsers.Rows) { UserData user = new UserData { UserId = Convert.ToInt32(dr["user_id"]), UserName = dr["user_name"].ToString() }; usersList.Add(user); List <SqlParameter> param = new List <SqlParameter>(); param.Add(new SqlParameter("@userId", Convert.ToInt32(dr["user_id"]))); DataTable contacts = manager.ExecuteStoredProcedure("getContacts", param); List <UserData> contcts = new List <UserData>(); foreach (DataRow contact in contacts.Rows) { contcts.Add(new UserData { UserId = Convert.ToInt32(contact["user_id"]), UserName = contact["user_name"].ToString() }); } phonebook.Add(new UserPhoneBookData { User = user, Contacts = contcts }); } //Dummy data //List<UserData> dummyUsers = new List<UserData> //{ // new UserData { UserId = 1, UserName = "******"}, // new UserData { UserId = 2, UserName = "******"}, // new UserData { UserId = 3 , UserName = "******"} //}; //List<UserPhoneBookData> dummyPhonebook = new List<UserPhoneBookData> //{ // new UserPhoneBookData { User = usersList[0], // Contacts = new List<UserData>{ usersList[1], usersList[2] } } //}; UserModel model = new UserModel { Users = usersList, PhoneBook = phonebook, NewUser = new UserData() }; // strongly typed view concept return(View(model)); }
public ActionResult Create(UserData data) { SQLDALManager manager = new SQLDALManager("dbConnKey"); manager.ExecuteStoredProcedure("createUser", new List <SqlParameter> { new SqlParameter("@userName", data.UserName) }); return(RedirectToAction("Index")); }
public ActionResult Create(UserModel data) { SQLDALManager manager = new SQLDALManager("dbConnKey"); manager.ExecuteStoredProcedure("createUserPhoneBook", new List <SqlParameter> { new SqlParameter("@userId", data.NewPhonebookRecord.UserId), new SqlParameter("@contactId", data.NewPhonebookRecord.ContactId) }); return(RedirectToAction("Index")); }