public ActionResult Create(VaccinationDefinition Vaccination) { ViewBag.CurrentPage = "Vaccination"; Vaccination.Age = db.Ages.FirstOrDefault(p => p.Code == Vaccination.Age.Code); try { if (ModelState.IsValid) { Vaccination.Id = Guid.NewGuid(); VaccinationDefinition resultObj = db.VaccinationDefinitions.Add(Vaccination); db.SaveChanges(); DataAccessLayer.VaccincationPriceDal provider = new VaccincationPriceDal(); provider.AddVaccinationPrice(Vaccination.Id.ToString(), (Decimal) 0.0, true); return RedirectToAction("Index"); } } catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log.) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } PopulateVaccinationDefinitionDropDownList(Vaccination.Id); return View(Vaccination); }
private void InitiateVaccinationPrices() { List<VaccinationDefinition> vaccinationDefs = db.VaccinationDefinitions.ToList(); VaccincationPriceDal provider = new VaccincationPriceDal(); foreach (VaccinationDefinition def in vaccinationDefs) { provider.AddVaccinationPrice(def.Id.ToString(), (Decimal)0.0, true); } }