public async Task <IActionResult> CreateBaptism(BaptismCreateViewModel model) { if (ModelState.IsValid) { var baptism = new Baptism(model); foreach (var id in model.SelectedMembers) { var member = await memberRepository.GetMember(id); if (member != null) { try { baptism.AddMember(member); } catch (Exception ex) { throw new Exception("Erro ao adicionar membros presentes.", ex); } } } try { repository.Add(baptism); } catch (Exception ex) { throw new Exception("Erro ao salvar Escola Dominical", ex); } return(RedirectToAction("list", "event")); } return(await ReloadDataAndReturnView()); }
public BaptismEditViewModel(Baptism baptism) { PageTitle = "Editar Batismo"; Id = baptism.Id; Date = baptism.Date; Place = baptism.Place; TeacherId = baptism.BaptizerId; }
public ActionResult EditBaptism(BaptismViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { var baptism = new Baptism { Id = model.Id, BapitsmNumber = model.BaptismNumber, BaptismPlace = model.BaptismPlace, BaptismDate = DateTime.Parse(model.BaptismDate), BaptismName = model.BaptismName, BaptismType = model.BaptismType, Othername = model.Othername, Surname = model.Surname, DateOfBirth = DateTime.Parse(model.DateOfBirth), PlaceOfBirth = model.PlaceOfBirth, HomeTown = model.HomeTown, FathersName = model.FathersName, MothersName = model.MothersName, NameOfGodParent1 = model.NameOfGodParent1, NameOfGodParent2 = model.NameOfGodParent2, NameOfMinister = model.NameOfMinister, Remarks = model.Remarks, Deleted = 0, CreateDate = model.CreateDate, UpdateDate = DateTime.Now }; if (_sacramentRepository.UpdateBaptism(baptism)) { var returnData = new ReturnData { HasValue = true, Message = "Baptismal record was successfully Updated" }; TempData["returnMessage"] = returnData; //return Redirect("/Baptism"); return(RedirectToAction("Baptism")); } ModelState.AddModelError(string.Empty, "There was an error completing the registration, Please check if the bapismal number is correct, also check the record"); return(View(model)); } catch (Exception e) { //error occured ModelState.AddModelError(string.Empty, "There was an error completing the registration, Please try again later"); ErrorUtil.LogError(e); return(View(model)); } }
public bool AddBaptism(Baptism baptism) { var existingBaptism = _entities.Baptism.FirstOrDefault(m => m.BapitsmNumber == baptism.BapitsmNumber); if (existingBaptism == null) { _entities.Baptism.Add(baptism); _entities.SaveChanges(); return(true); } return(false); }
public bool UpdateBaptism(Baptism baptism) { var existingBaptism = _entities.Baptism.FirstOrDefault(m => m.Id == baptism.Id); if (existingBaptism != null) { baptism.CreateDate = existingBaptism.CreateDate; _entities.Entry(existingBaptism).CurrentValues.SetValues(baptism); _entities.SaveChanges(); return(true); } return(false); }