//[RestoreModelStateFromTempData] public async Task <IActionResult> AddChristening(int?id) { if (id == null) { return(NotFound()); } var parishioner = await _context.Parishioners.FindAsync(id.Value); if (parishioner == null) { return(NotFound()); } //var feligres = await _context.Parishioners // .Include(p => p.Christenings) // .FirstOrDefaultAsync(p => p.Id == id); //if (feligres.Christenings.Count > 0) //{ // ModelState.AddModelError("", "Solo puede agregar un bautizo por Feligrés"); // //return RedirectToAction("Details", new { Id }); //} var model = new ChristeningViewModel { CreatedAt = DateTime.Today, ParishionerId = parishioner.Id, SacramentTypes = _combosHelper.GetChristening() }; return(View(model)); }
public async Task <IActionResult> EditChristening(ChristeningViewModel model) { if (ModelState.IsValid) { var christening = await _converterHelper.ToChristeningAsync(model, false); _context.Christenings.Update(christening); await _context.SaveChangesAsync(); return(RedirectToAction($"Details/{model.ParishionerId}")); } model.SacramentTypes = _combosHelper.GetChristening(); return(View(model)); }
//[SetTempDataModelState] public async Task <IActionResult> AddChristening(ChristeningViewModel model) { //if (model.Id > 0) //{ // ModelState.AddModelError("", "Solo puede agregar un bautizo por Feligrés"); // return RedirectToAction("Details"); //} if (ModelState.IsValid) { var christening = await _converterHelper.ToChristeningAsync(model, true); _context.Christenings.Add(christening); await _context.SaveChangesAsync(); return(RedirectToAction($"Details/{model.ParishionerId}")); } model.SacramentTypes = _combosHelper.GetChristening(); return(View(model)); }
public async Task <Christening> ToChristeningAsync(ChristeningViewModel model, bool isNew) { var christening = new Christening { ChristeningDate = model.ChristeningDate, Id = isNew ? 0 : model.Id, PlaceofEvent = model.PlaceofEvent, FatherName = model.FatherName, FatherId = model.FatherId, MotherName = model.MotherName, MotherId = model.MotherId, GodFatherName = model.GodFatherName, GodFatherId = model.GodFatherId, GodMotherName = model.GodMotherName, GodMotherId = model.GodMotherId, Comments = model.Comments, CeremonialCelebrant = model.CeremonialCelebrant, Parishioner = await _dataContext.Parishioners.FindAsync(model.ParishionerId), SacramentType = await _dataContext.SacramentTypes.FindAsync(model.SacramentTypeId) }; return(christening); }