public bool SaveCase(ICase c) { bool isSuccessful = true; try { conn.Open(); string customerEmail = InsertCustomer(c.Customer); int? imageId = InsertImage(c.Image); int moneyInstituteId = InsertMoneyInstitute(c.MoneyInstitute); string employeeEmail = InsertEmployee(c.Employee); int plotId = InsertPlot(c.Plot); c.CaseNumber = InsertCase(c, customerEmail, moneyInstituteId, employeeEmail, plotId, imageId); InsertTechnicalSpecifications(c.GetAllCategories(), c.DateOfCreation.Year, c.CaseNumber); InsertExtraExpenses(c.GetAllCategories(), c.DateOfCreation.Year, c.CaseNumber); InsertProducts(c, c.DateOfCreation.Year, c.CaseNumber); InsertHouseType(c, c.DateOfCreation.Year, c.CaseNumber); } catch (SqlException) { isSuccessful = false; } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } return(isSuccessful); }
private void InsertProducts(ICase c, int caseYear, int caseNumber) { DeleteCaseProducts(caseYear, caseNumber); Dictionary <Category, IExpenseCategory> dictionary = c.GetAllCategories(); foreach (IExpenseCategory iec in dictionary.Values) { foreach (ProductType pt in iec.ProductTypes) { foreach (ProductOption po in pt.ListOfProductOptions) { if (po.Selected == true) { InsertCaseProductOption(po.ProductId, caseNumber, caseYear, po.Amount, po.SpecialPrice, po.Special); } } } } }