//Clear All items, comboboxes, checkboxes etc... private void ClearListButton_Click(object sender, RoutedEventArgs e) { rtb.Document.Blocks.Clear(); CarPrice.Clear(); InsurancePrice.Clear(); Brand.Clear(); Type.Clear(); SenderName.SelectedIndex = 0; AssistanceType.SelectedIndex = 0; AdreserType.SelectedIndex = 0; GlassPrice.SelectedIndex = 0; NnwPrice.SelectedIndex = 0; ValType.SelectedIndex = 0; AcDisc.SelectedIndex = 0; OwnCont.SelectedIndex = 0; GrNet.SelectedIndex = 0; OcComboBox.SelectedIndex = 0; ConstInsuranceValue.SelectedIndex = 0; OcCheckBox.IsChecked = false; AcCheckBox.IsChecked = false; NnwCheckBox.IsChecked = false; GlassCheckBox.IsChecked = false; AssCheckBox.IsChecked = false; AtHomeLimit.IsChecked = false; KmLimit.IsChecked = false; BorderRange.IsChecked = false; InsuranceCompany = ""; Recpient = ""; CarBrand = ""; CarType = ""; DiscountOC = ""; CarPriceAC = ""; GrossNetAC = ""; OwnContributionAC = ""; DiscountAC = ""; ValuationTypeAC = ""; NnwTypes = ""; AssistanceRange = ""; CarGlass = ""; InsurancePriceEnd = ""; Sender = ""; AssistanceTypeCompany = ""; InsuranceChange = ""; FirstPartOfMail = ""; SecondPartOfMail = ""; ThirdPartOfMail = ""; FourthPartOfMail = ""; FourthAndHalfPartOFMail = ""; FifthPartOfMail = ""; SixthPartOfMail = ""; SeventhPartOfMail = ""; EightPartOfMail = ""; AtHomeLimitation = ""; KmLimitation = ""; BorderRangePl = ""; id = 0; }
public ActionResult Create(ServicesPricesData servicesPricesData) { var rows = 0; List <ServicesPrice> prices = servicesPricesData.ServicesPrices; foreach (var price in prices) { price.DateAdded = DateTime.Now; var entry = db.ServicesPrices.FirstOrDefault(e => e.ServiceId == price.ServiceId && e.TariffId == price.TariffId); if (entry != null) { //this is an existing entry, update try { entry.Award = price.Award; entry.AwardUnit = price.AwardUnit; entry.DoctorFee = price.DoctorFee; entry.DoctorFeeUnit = price.DoctorFeeUnit; db.SaveChanges(); } catch (DbEntityValidationException ex) { //TO REMEMBER: How to return specific validation error in EF // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); return(Json(price)); //return Content(exceptionMessage); } } else { //insert as a new record db.ServicesPrices.Add(price); } db.SaveChanges(); rows += 1; } //Get the Tarrif var tariff = db.Tariffs.Find(servicesPricesData.TariffId); foreach (var altered in servicesPricesData.AlteredPrices) { if (tariff != null && tariff.Company.CompanyName != "Cash") { var entry = db.InsurancePrices.FirstOrDefault(e => e.ServicesPrice.ServiceId == altered.ServiceId && e.CompanyId == tariff.CompanyId); if (entry != null) { entry.Price = altered.CashPrice; } else { var ServicePriceId = db.ServicesPrices.FirstOrDefault (e => e.ServiceId == altered.ServiceId && e.TariffId == tariff.Id); var inPrice = new InsurancePrice() { ServicePriceId = ServicePriceId.Id, CompanyId = tariff.CompanyId, Price = altered.CashPrice }; var res = db.InsurancePrices.Add(inPrice); } } else { var service = db.Services.Find(altered.ServiceId); service.CashPrice = altered.CashPrice; } } db.SaveChanges(); return(Content(rows.ToString() + " changes saved successfully")); }