public FormatedAssociationCounter(AssociationCounters item) { List <int> result = new List <int>(); foreach (var assCounterStairCase in item.AssociationCountersStairCase) { int toAppend = -1; if (assCounterStairCase.Id_StairCase.HasValue) { toAppend = assCounterStairCase.Id_StairCase.Value; } result.Add(toAppend); } AssociationCounterStairCaseIds = result; AssociationCounterStairCaseIdsString = string.Join(",", result); this.AssociationCountersApartment = item.AssociationCountersApartment; this.AssociationCountersStairCase = item.AssociationCountersStairCase; this.Associations = item.Associations; this.Expenses = item.Expenses; this.Id = item.Id; this.Id_Estate = item.Id_Estate; this.Id_Expense = item.Id_Expense; this.InvoiceIndexes = item.InvoiceIndexes; this.Value = item.Value; }
private static void AddCounterStairCase(AssociationCounters counter) { foreach (var assCounterSc in counter.AssociationCountersStairCase) { Add(assCounterSc); } }
private static void UpdateAssociationCountersStairCase(AssociationCounters newCounter) { var exitingCounter = GetContext(true).AssociationCounters.FirstOrDefault(c => c.Id == newCounter.Id); if (exitingCounter != null) { var stairCaseToBeAdded = newCounter.AssociationCountersStairCase.Select(n => n.Id_StairCase) .Except(exitingCounter.AssociationCountersStairCase.Select(o => o.Id_StairCase)); var stairCaseToBeDeleted = exitingCounter.AssociationCountersStairCase.Select(n => n.Id_StairCase) .Except(newCounter.AssociationCountersStairCase.Select(o => o.Id_StairCase)); var add = newCounter.AssociationCountersStairCase.Where(ne => stairCaseToBeAdded.Contains(ne.Id_StairCase)).ToList(); var del = exitingCounter.AssociationCountersStairCase.Where(ne => stairCaseToBeDeleted.Contains(ne.Id_StairCase)).ToList(); foreach (var assCounterSc in add) { assCounterSc.Id_AssCounter = exitingCounter.Id; Add(assCounterSc); } foreach (var assCounterSc in del) { Remove(assCounterSc); } } }
protected void btnAssociationCountersNew_Click(object sender, EventArgs e) { if (newCounter.Visible) { if (!string.IsNullOrEmpty(txtAssociationCounterValueNew.Text)) { List <AssociationCountersStairCase> associationCounterStariCases = GetStairCases(chbAssociationStairs); AssociationCounters associationCounters = new AssociationCounters { Id_Estate = Association.Id, Value = txtAssociationCounterValueNew.Text, Id_Expense = drpAssociationCounterTypeNew.SelectedValue.ToNullableInt().Value, AssociationCountersStairCase = associationCounterStariCases }; AssociationCountersManager.Add(associationCounters); var newAssociation = AssociationsManager.GetById(Association.Id); Session[SessionConstants.SelectedAssociation] = newAssociation; Response.Redirect(Request.RawUrl); } else { txtAssociationCounterValueNew.Attributes.Add("style", "border-color:red"); } } else { newCounter.Visible = true; IEnumerable <Expenses> expenses = ExpensesManager.GetAllExpenses(); foreach (Expenses expense in expenses) { drpAssociationCounterTypeNew.Items.Add(new ListItem { Text = expense.Name, Value = expense.Id.ToString() }); } var defaultExpense = new ListItem { Value = "", Text = "Contor pe bloc" }; chbAssociationStairs.Items.Add(defaultExpense); if (Association.HasStaircase) { foreach (var stairCase in Association.StairCases) { chbAssociationStairs.Items.Add(new ListItem { Text = stairCase.Nume, Value = stairCase.Id.ToString() }); } } } }
protected void btnSave3_Click(object sender, EventArgs e) { List <AssociationCounters> cnts = new List <AssociationCounters>(); foreach (var control in countersConfiguration.Controls) { if (control is Panel) { var thePanel = (Panel)control; if (thePanel.Controls.Count > 1 && thePanel.Controls[0] is DropDownList && thePanel.Controls[1] is TextBox) { var expenseControl = (DropDownList)thePanel.Controls[0]; var expenseCleaned = expenseControl.SelectedValue.Remove(expenseControl.SelectedValue.IndexOf("dummyExpense")); var valueControl = (TextBox)thePanel.Controls[1]; int?stairIdResult = null; if (thePanel.Controls.Count == 3 && thePanel.Controls[2] is DropDownList) { var stairCaseControl = (DropDownList)thePanel.Controls[2]; var stairCleaned = stairCaseControl.SelectedValue.Remove(stairCaseControl.SelectedValue.IndexOf("dummyStair")); int stairId; if (int.TryParse(stairCleaned, out stairId)) { stairIdResult = stairId; } } // to do, add checkbox and select multiple int expenseId; if (!string.IsNullOrEmpty(expenseControl.Text) && int.TryParse(expenseCleaned, out expenseId)) { var cnt = new AssociationCounters() { Id_Estate = Association.Id, Id_Expense = expenseId, Value = valueControl.Text, AssociationCountersStairCase = new List <AssociationCountersStairCase> { new AssociationCountersStairCase { Id_StairCase = stairIdResult } } }; cnts.Add(cnt); } } } } AssociationCountersManager.Addcounter(cnts); var association = AssociationsManager.GetById(Association.Id); Session[SessionConstants.SelectedAssociation] = association; Response.Redirect("~/?message=newEstate"); }
public static void Update(AssociationCounters newCounter) { var exitingCounter = GetContext(true).AssociationCounters.FirstOrDefault(c => c.Id == newCounter.Id); if (exitingCounter != null && exitingCounter.Value != newCounter.Value) { exitingCounter.Value = newCounter.Value; GetContext().Entry(exitingCounter).CurrentValues.SetValues(exitingCounter); GetContext().SaveChanges(); } UpdateAssociationCountersStairCase(newCounter); }
protected void gvCounters_RowUpdating(object sender, GridViewUpdateEventArgs e) { var row = gvCounters.Rows[e.RowIndex]; if (row.Cells.Count > 4 && row.Cells[2].Controls[0] is TextBox && row.Cells[4].Controls[3] is CheckBoxList) { var counterValue = (TextBox)row.Cells[2].Controls[0]; var stairCases = (CheckBoxList)row.Cells[4].Controls[3]; var counterIdValue = row.Cells[6]; int counterId; if (string.IsNullOrEmpty(counterValue.Text) || !int.TryParse(counterIdValue.Text, out counterId)) { counterValue.Attributes.Add("style", "background-color:red"); } else { AssociationCounters associationCounters = AssociationCountersManager.GetById(counterId); List <AssociationCountersStairCase> associationCounterStariCases = GetStairCases(stairCases); if (associationCounters != null) { var theCounter = new AssociationCounters { Value = counterValue.Text, AssociationCountersStairCase = associationCounterStariCases, Id = counterId }; AssociationCountersManager.Update(theCounter); } gvStaircases.EditIndex = -1; gvStaircases.DataBind(); var addedAssociation = AssociationsManager.GetById(Association.Id); Session[SessionConstants.SelectedAssociation] = addedAssociation; var associations = AssociationsManager.GetAllAssociationsByPartner(Association.Id_Partner); Session[SessionConstants.AllAssociations] = associations; Response.Redirect(Request.RawUrl); } } }
public static InvoiceIndexes GetByInvoiceAndCounterFirst(Invoices invoice, AssociationCounters assocCounter) { return(GetContext().InvoiceIndexes.FirstOrDefault(t => t.Id_Invoice == invoice.Id && t.AssociationCounters.Id == assocCounter.Id)); }
public static List <InvoiceIndexes> GetByInvoiceAndCounter(Invoices invoice, AssociationCounters assocCounter) { return(GetContext().InvoiceIndexes.Where(t => t.Id_Invoice == invoice.Id && t.AssociationCounters.Id == assocCounter.Id).ToList()); }
public static void Add(AssociationCounters counter) { GetContext().AssociationCounters.Add(counter); GetContext().SaveChanges(); }