public void Save() { Validate(); var individualEntity = new IndividualEntity { Id = Id, LastName = LastName, FirstName = FirstName, MiddleName = MiddleInitial, Suffix = Suffix, DateOfBirth = DateOfBirth, }; var studentId = individualEntity.Id; if (studentId > 0) { _individualRepo.Update(individualEntity); } else { studentId = _individualRepo.Create(individualEntity); } var studentEntity = _studentRepo.Retrieve(studentId); if (studentEntity != null) { Id = studentEntity.Id; studentEntity.HighSchoolName = HighSchool.Name; studentEntity.HighSchoolCity = HighSchool.City; studentEntity.HighSchoolState = HighSchool.State; _studentRepo.Update(studentEntity); return; } var retVal = _studentRepo.Create( new StudentEntity { Id = studentId, HighSchoolName = HighSchool.Name, HighSchoolCity = HighSchool.City, HighSchoolState = HighSchool.State, }); if (retVal != studentId) { throw new InvalidOperationException( string.Format("Create failed for student (Id={0})", studentId)); } Id = studentId; }
public ActionResult ShowAppsToUsers() { try { UserLoginPageReq userdets = TempData["userdata"] as UserLoginPageReq; var userName = userdets.name; DatabaseModel db = new DatabaseModel(); DisplayFunctionalities df = new DisplayFunctionalities(); List <Application> apps = df.ShowApplicationsOwnedByUser(userName); ShowAppsToSpecificUser sa = new ShowAppsToSpecificUser(); IndividualEntity ie = new IndividualEntity(); sa.ApplicationOwned = new List <string>(); List <IndividualEntity> users = new List <IndividualEntity>(); users = db.Person.ToList(); ie = users.Find(x => x.Username == userName); sa.firstNameOfTheUser = ie.FirstName; foreach (var temp in apps) { sa.ApplicationOwned.Add(temp.ApplicationName); } return(View(sa)); } catch (Exception e) { log.Error("Problem in show apps to users function " + e.Message); throw new Exception(e.Message); } }
public int Create(IndividualEntity entity) { // Guard against invalid arguments. if (entity == null) { throw new ArgumentNullException("entity"); } if (entity.Id > 0) { throw new InvalidOperationException("Entity is invalid for Create, the Id must be 0."); } var sqlHelper = new DalHelper(_connectionString); var parameters = new List<SqlParameter> { new SqlParameter("LastName", entity.LastName), new SqlParameter("FirstName", entity.FirstName), new SqlParameter("MiddleName", entity.MiddleName), new SqlParameter("Suffix", entity.Suffix), new SqlParameter("DateOfBirth", entity.DateOfBirth), }; try { var dataSet = sqlHelper.ExecuteStoredProcedure( "dal_Individual_Create", parameters); // Returns createdId if a record was created. var createdId = default(int); if (dataSet != null && dataSet.Tables.Count > 0) { var table = dataSet.Tables[0]; foreach (DataRow row in table.Rows) { createdId = row.Field<int>("Id"); // Retrieve returns the first record. break; } } return createdId; } catch (Exception exception) { // Throw an exception if the Id was not returned. throw new InvalidOperationException("Failed to create.", exception); } }
private IndividualEntity SaveIndividualEntitySupplier() { IndividualEntity individualSupplier = new IndividualEntity( GetCompany(), txtCompanyName.Text, SaveDocuments(), DateTime.Now, this.Phones, dtpBirthDate.Value ); return(individualSupplier); }
internal void LoadData( IndividualEntity individual, StudentEntity student) { Id = student.Id; LastName = individual.LastName; FirstName = individual.FirstName; MiddleInitial = GetMiddleInitial(individual.MiddleName); Suffix = individual.Suffix; DateOfBirth = individual.DateOfBirth; HighSchool = new School { Name = student.HighSchoolName, City = student.HighSchoolCity, State = student.HighSchoolState, }; }
public IndividualEntity Retrieve(int id) { var sqlHelper = new DalHelper(_connectionString); var parameters = new List <SqlParameter> { new SqlParameter("Id", id) }; var procedureName = string.Format( DalHelper.RetrieveStoredProcFormat, TableName); var dataSet = sqlHelper.ExecuteStoredProcedure( procedureName, parameters); IndividualEntity entity = null; if (dataSet != null && dataSet.Tables.Count > 0) { var table = dataSet.Tables[0]; foreach (DataRow row in table.Rows) { entity = new IndividualEntity { Id = row.Field <int>("Id"), LastName = row.Field <string>("LastName"), FirstName = row.Field <string>("FirstName"), MiddleName = row.Field <string>("MiddleName"), Suffix = row.Field <string>("Suffix"), DateOfBirth = row.Field <DateTime>("DateOfBirth"), }; } } return(entity); }
public IndividualEntity Retrieve(int id) { var sqlHelper = new DalHelper(_connectionString); var parameters = new List<SqlParameter> { new SqlParameter("Id", id), }; var dataSet = sqlHelper.ExecuteStoredProcedure( "dal_Individual_Retrieve", parameters); IndividualEntity entity = null; if (dataSet != null && dataSet.Tables.Count > 0) { var table = dataSet.Tables[0]; foreach (DataRow row in table.Rows) { entity = new IndividualEntity { Id = row.Field<int>("Id"), LastName = row.Field<string>("LastName"), FirstName = row.Field<string>("FirstName"), MiddleName = row.Field<string>("MiddleName"), Suffix = row.Field<string>("Suffix"), DateOfBirth = row.Field<DateTime>("DateOfBirth"), }; // Retrieve shouldn't return more than 1 row. break; } } return entity; }
private static Individual AsDomainModel(this IndividualEntity entity, Graph graph, IProblem problem) { return(new Individual(graph, problem, entity.CurrentSolution.Select(Convert.ToBoolean).ToArray(), entity.Id)); }
protected string PrintEntity(IndividualEntity individualEntity) { return(@"<owl:Individual rdf:ID=""" + individualEntity.Identity.Replace(' ', '_') + @"""/>"); }
public void Delete(IndividualEntity entity) { // Guard against invalid arguments. if (entity == null) { throw new ArgumentNullException("entity"); } if (entity.Id <= 0) { throw new InvalidOperationException("Entity is invalid for Update, the Id must be greater than 0."); } var sqlHelper = new DalHelper(_connectionString); var parameters = new List<SqlParameter> { new SqlParameter("Id", entity.Id), }; var rowsAffected = sqlHelper.ExecuteStoredProcedureNonQuery( "dal_Individual_Delete", parameters); if (rowsAffected != 1) { throw new InvalidOperationException("Entity saving failed during Update."); } }
private void btnSave_Click(object sender, EventArgs e) { if (ValidateSupplier()) { if (this.IsIndividualEntity) //If it's an individual entity { if (IndividualEntity.IsFromPR(this.SelectedCompany)) //And the company it attends is from PR { if (IndividualEntity.HasLegalAge(dtpBirthDate.Value.Date)) //Check if it is at least 18 y/o { if (this.IndividualEntities != null) { var individualSuppliers = new List <IndividualEntity>(this.IndividualEntities); individualSuppliers.Add(SaveIndividualEntitySupplier()); this.IndividualEntities = individualSuppliers; MessageBox.Show("Supplier saved successfully!", "Supplier saved", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { var individualSuppliers = new List <IndividualEntity>(); individualSuppliers.Add(SaveIndividualEntitySupplier()); this.IndividualEntities = individualSuppliers; MessageBox.Show("Supplier saved successfully!", "Supplier saved", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } else { MessageBox.Show("Individual entity suppliers must be at least 18 years old", "Supplier not old enough", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else //else, if it is not from PR, there's no need to be 18 years old { if (this.IndividualEntities != null) { var individualSuppliers = new List <IndividualEntity>(this.IndividualEntities); individualSuppliers.Add(SaveIndividualEntitySupplier()); this.IndividualEntities = individualSuppliers; MessageBox.Show("Supplier saved successfully!", "Supplier saved", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { var individualSuppliers = new List <IndividualEntity>(); individualSuppliers.Add(SaveIndividualEntitySupplier()); this.IndividualEntities = individualSuppliers; MessageBox.Show("Supplier saved successfully!", "Supplier saved", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } } else // else, if it is a legal entity supplier { if (this.Suppliers != null) { var suppliers = new List <Supplier>(this.Suppliers); suppliers.Add(SaveLegalEntitySupplier()); this.Suppliers = suppliers; MessageBox.Show("Supplier saved successfully!", "Supplier saved", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { var suppliers = new List <Supplier>(); suppliers.Add(SaveLegalEntitySupplier()); this.Suppliers = suppliers; MessageBox.Show("Supplier saved successfully!", "Supplier saved", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } } }