protected void btnSave_Click(object sender, EventArgs e) { bool isThereSelectedItem = gvConfiguration.Rows.Count > 0; if (!isThereSelectedItem) { lblTotalAmount.Visible = false; lblError.Visible = true; lblError.Text = "Please select at least one component!"; } else { PCConfiguration pCConfiguration = new PCConfiguration(); IBusinessLayer businessLayer = new BuinessLayer(); decimal totalAmount = 0; foreach (GridViewRow row in gvConfiguration.Rows) { var id = int.Parse(row.Cells[0].Text); pCConfiguration.PCComponentConfigurations.Add(new PCComponentConfiguration { ComponentId = id, PCConfigurationId = pCConfiguration.Id }); totalAmount += decimal.Parse(row.Cells[2].Text); } pCConfiguration.TotalAmount = totalAmount; // TODO fix this businessLayer.AddPCConfiguration(pCConfiguration); Session["PCConfigurationComponents"] = new List <Component>(); lblTotalAmount.Visible = false; ddlComponents.SelectedIndex = 0; gvConfiguration.DataSource = new List <Component>(); gvConfiguration.DataBind(); lblError.Visible = true; lblError.Text = "Configuration saved!"; } }
private void Update() { IBusinessLayer businessLayer = new BuinessLayer(); if (OperationType == OperationType.Insert) { businessLayer.AddCities(new Cities { Number = CitiesId, Name = Name, Region = Region, IsRegionCenter = IsRegionCenter, }); Container.CitiesList = Container.GetCitiess(); } else if (OperationType == OperationType.Update) { businessLayer.UpdateCities(new Cities { Number = CitiesId, Name = Name, Region = Region, IsRegionCenter = IsRegionCenter }); _originalValue = (CitiesViewModel)MemberwiseClone(); } }
private void Delete() { IBusinessLayer businessLayer = new BuinessLayer(); businessLayer.RemoveCities(new Cities { Number = CitiesId, Name = Name, Region = Region, IsRegionCenter = IsRegionCenter }); Container.CitiesList = Container.GetCitiess(); }
internal ObservableCollection <StreetsViewModel> GetStreets() { _streets = new ObservableCollection <StreetsViewModel>(); IBusinessLayer businessLayer = new BuinessLayer(); foreach (var i in businessLayer.GetStreetssByCitiesNumber(CitiesId)) { StreetsViewModel street = new StreetsViewModel(i); street.Cities = this; _streets.Add(street); } return(_streets); }
static void Main(string[] args) { IBusinessLayer businessLayer = new BuinessLayer(); /* Create a department graph with two related employee objects */ Department it = new Department() { Name = "IT" }; it.Employee = new List<Employee> { new Employee { FirstName="Donald", LastName="Duck", EntityState=EntityState.Added }, new Employee { FirstName="Mickey", LastName="Mouse", EntityState=EntityState.Added } }; it.EntityState = EntityState.Added; businessLayer.AddDepartment(it); /*Add another employee to the IT department */ Employee employee = new Employee() { FirstName = "Robin", LastName = "Hood", DepartmentId = it.DepartmentId, EntityState = EntityState.Added }; /* and change the name of the department */ it.Name = "Information Technology Department"; it.EntityState = EntityState.Modified; foreach (Employee emp in it.Employee) emp.EntityState = EntityState.Unchanged; it.Employee.Add(employee); businessLayer.UpdateDepartment(it); /* Verify changes by quering for the updated department */ it = businessLayer.GetDepartmentByName("Information Technology Department"); if (it != null) { Console.WriteLine(string.Format("Employees at the {0} department:", it.Name)); foreach (Employee e in it.Employee) Console.WriteLine(string.Format("{0}, {1}", e.LastName, e.FirstName)); }; /* Delete all entities */ it.EntityState = EntityState.Deleted; foreach (Employee e in it.Employee) e.EntityState = EntityState.Deleted; businessLayer.RemoveDepartment(it); Console.ReadLine(); }