protected void btnInsert_Click(object sender, EventArgs e) { using (var obj = new OntologyDataContext()) { var per = new tblPerson(); per.Category = Convert.ToInt32(RadioButtonList1.SelectedValue); per.HostName = txtHost.Text; per.IPAddress = txtIP.Text; obj.tblPersons.InsertOnSubmit(per); obj.SubmitChanges(); } }
public static int Add(Models.DomainModel.Student student) { using (TestEntities context = new TestEntities()) { tblAddress objAddress = new tblAddress() { HouseNo = student.AddressDetails.HouseNo, Locality = student.AddressDetails.Locality, City = student.AddressDetails.City, District = student.AddressDetails.District, State = student.AddressDetails.State, CreatedDate = DateTime.Now, CreatedBy = "admin" }; tblPerson objPerson = new tblPerson() { Name = student.Name, FatherName = student.FatherName, MotherName = student.MotherName, Age = student.Age, Gender = 1, CreatedDate = DateTime.Now, CreatedBy = "admin" }; context.tblAddresses.AddObject(objAddress); context.tblPersons.AddObject(objPerson); tblStudent objStudent = new tblStudent() { PersonID = objPerson.ID, AddressID = objAddress.ID, CreatedDate = DateTime.Now, CreatedBy = "admin" }; context.tblStudents.AddObject(objStudent); context.SaveChanges(); return objStudent.ID; } }
/// <summary> /// Add a new Person. /// </summary> /// <param name="person"></param> public void Add(tblPerson person) { db.tblPersons.Add(person); db.SaveChanges(); }
partial void DeletetblPerson(tblPerson instance);
partial void UpdatetblPerson(tblPerson instance);
partial void InserttblPerson(tblPerson instance);
void Submit(object obj) { string encryptedString = (obj as PasswordBox).Password; if (encryptedString.Length < 5) { MessageBox.Show("Password has to be at least 5 characters long"); return; } string password = EncryptionHelper.Encrypt(encryptedString); if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(encryptedString)) { MessageBox.Show("Wrong user name or password"); return; } if (UserName.Equals("Admin") && !encryptedString.Equals("Admin123")) { MessageBox.Show("Wrong password for Admin"); return; } if (UserName.Equals("Admin") && encryptedString.Equals("Admin123")) { tblPerson adminInDb = personService.GetUserByUserNameAndPass(UserName, password); if (adminInDb == null) { tblPerson admin = new tblPerson(); admin.Username = UserName; admin.Password = password; adminInDb = personService.AddUser(admin); AdminMainView adminMain = new AdminMainView(adminInDb); adminMain.Show(); view.Close(); return; } else { AdminMainView adminMain = new AdminMainView(adminInDb); adminMain.Show(); view.Close(); return; } } tblPerson userInDb = personService.GetUserByUserName(UserName); if (userInDb == null) { FirstLogin firstLogin = new FirstLogin(UserName, password); firstLogin.Show(); view.Close(); return; } else { if (!userInDb.Password.Equals(password)) { MessageBox.Show("Wrong password for this user"); return; } tblPerson p; using (CookbookDatabaseEntities1 context = new CookbookDatabaseEntities1()) { p = (from x in context.tblPersons where x.Username == UserName select x).First(); } UserMain main = new UserMain(p); main.Show(); view.Close(); return; } }