//[RestoreModelStateFromTempData] public async Task <IActionResult> AddFirstCommunion(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.FirstCommunions) .FirstOrDefaultAsync(p => p.Id == id); if (feligres.FirstCommunions.Count > 0) { ModelState.AddModelError("", "Solo puede haber una Primera Comunión por Feligrés"); } var model = new FirstCommunionViewModel { CreatedAt = DateTime.Today, ParishionerId = parishioner.Id, SacramentTypes = _combosHelper.GetFirstCommunion() }; return(View(model)); }
public async Task <IActionResult> EditFirstCommunion(FirstCommunionViewModel model) { if (ModelState.IsValid) { var firstCommunion = await _converterHelper.ToFirstCommunionAsync(model, false); _context.FirstCommunions.Update(firstCommunion); await _context.SaveChangesAsync(); return(RedirectToAction($"Details/{model.ParishionerId}")); } model.SacramentTypes = _combosHelper.GetFirstCommunion(); return(View(model)); }
public async Task <FirstCommunion> ToFirstCommunionAsync(FirstCommunionViewModel model, bool isNew) { var firstCommunion = new FirstCommunion { FirstCommunionDate = model.FirstCommunionDate, Id = isNew ? 0 : model.Id, PlaceofEvent = model.PlaceofEvent, FatherName = model.FatherName, FatherId = model.FatherId, MotherName = model.MotherId, Comments = model.Comments, CeremonialCelebrant = model.CeremonialCelebrant, Parishioner = await _dataContext.Parishioners.FindAsync(model.ParishionerId), SacramentType = await _dataContext.SacramentTypes.FindAsync(model.SacramentTypeId) }; return(firstCommunion); }