public async Task <ActionResult <ParentFuneralHome> > PostParentFuneralHome(ParentFuneralHome parentFuneralHome) { _context.ParentFuneralHomes.Add(parentFuneralHome); await _context.SaveChangesAsync(); return(CreatedAtAction("GetParentFuneralHome", new { id = parentFuneralHome.Id }, parentFuneralHome)); }
public async Task <IActionResult> PutParentFuneralHome(int id, ParentFuneralHome parentFuneralHome) { if (id != parentFuneralHome.Id) { return(BadRequest()); } _context.Entry(parentFuneralHome).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ParentFuneralHomeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
// GET: FuneralHomes public async Task <IActionResult> Index(string sortOrder, string currentFilter, string searchString, int?pageNumber) { ViewData["CurrentSort"] = sortOrder; if (searchString != null) { pageNumber = 1; } else { searchString = currentFilter; } int pageSize = 25; //Get list of funeral homes //var fhList = await _context.FuneralHomes.ToListAsync(); var fhList = from fh in _context.FuneralHomes orderby fh.Name select fh; //Iterate through each item in the list foreach (var item in fhList) { //Instantiate a parent var pfh = new ParentFuneralHome(); if (item.ParentFuneralHomeId != 0 && item.ParentFuneralHomeId != null) { pfh = await _context.ParentFuneralHomes.FindAsync(item.ParentFuneralHomeId); } if (item.ParentName != null) { if (pfh != null) { item.ParentName = pfh.ParentFuneralhomeName.Trim(); } } var plt = new Plant(); if (item.PlantId != 0 && item.PlantId != null) { plt = await _context.Plants.FindAsync(item.PlantId); } if (item.PlantName != null) { if (plt != null) { item.PlantName = plt.PlantName; } } item.State = Enum.GetName(typeof(States), Int32.Parse(item.State)); } //return View(await _context.FuneralHomes.ToListAsync()); return(View(await PaginatedList <FuneralHome> .CreateAsync(fhList, pageNumber ?? 1, pageSize))); }
private void initParentList(FuneralHome fh) { ParentFuneralHome pfh = new ParentFuneralHome(); pfh.ParentFuneralhomeName = ""; fh.ParentFuneralHomes = new List <ParentFuneralHome>(); fh.ParentFuneralHomes.Add(pfh); _context.ParentFuneralHomes.Add(pfh); }
private void addParent(FuneralHome fh) { ParentFuneralHome pfh = new ParentFuneralHome(); pfh.ParentFuneralhomeName = fh.Name; fh.ParentFuneralHomes = _context.ParentFuneralHomes.ToList(); fh.ParentFuneralHomes.Add(pfh); _context.ParentFuneralHomes.Add(pfh); }
public async Task <IActionResult> Create([Bind("FuneralHomeId,ParentFuneralHomeId,PlantId,Name,Address,Address2,City,State,ZipCode,County,Email,Website,Phone1,Phone2,Phone3,PhoneType1,PhoneType2,PhoneType3,IsParent,ParentName,PlantName")] FuneralHome funeralHome) { if (ModelState.IsValid) { // If no parent funeralhomes exist... if (_context.ParentFuneralHomes.Count() == 0) { // if this funeralhome is a parent funeral home... if (funeralHome.IsParent) { // 1) initialize a list of funeral homes. initParentList(funeralHome); // 2) add to list of funeral homes. addParent(funeralHome); } else { // if this funeralhome is a parent funeral home... initParentList(funeralHome); } } else { if (funeralHome.IsParent) { // add to list of funeral homes. addParent(funeralHome); } } if (funeralHome.ParentFuneralHomeId != null) { var pfh = new ParentFuneralHome(); pfh = await _context.ParentFuneralHomes.FindAsync(funeralHome.ParentFuneralHomeId); funeralHome.ParentName = pfh.ParentFuneralhomeName; } if (funeralHome.PlantId != 0) { Plant plt = await _context.Plants.FindAsync(funeralHome.PlantId); funeralHome.PlantName = plt.PlantName; } _context.FuneralHomes.Add(funeralHome); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } // ViewData["PlantId"] = new SelectList(_context.Plants, "PlantId", "PlantId", funeralHome.PlantId); return(View(funeralHome)); }
public async Task <IEnumerable <FuneralHome> > ListAllFuneralHomesAsync() { //Get list of funeral homes IQueryable <FuneralHome> fhList = from fh in _context.FuneralHomes orderby fh.Name select fh; _context.Database.CloseConnection(); //Iterate through each item in the list foreach (var item in fhList) { //Instantiate a parent var pfh = new ParentFuneralHome(); if (item.ParentFuneralHomeId != 0 && item.ParentFuneralHomeId != null) { pfh = await _context.ParentFuneralHomes.FindAsync(item.ParentFuneralHomeId); } if (item.ParentName != null) { if (pfh != null) { item.ParentName = pfh.ParentFuneralhomeName.Trim(); } } // Get Plants //var additives = p.Additives.ToList(); var plants = item.Plants.ToList(); foreach (var p in plants) { if (p.PlantId == item.PlantId) { item.Plants.Add(p); item.PlantName = p.PlantName; } } item.State = Enum.GetName(typeof(States), Int32.Parse(item.State)); } return(fhList); }
public async Task <IActionResult> Edit(int id, [Bind("FuneralHomeId,ParentFuneralHomeId,PlantId," + "Name,Address,Address2,City,State,ZipCode,County,Email,Website,Phone1,Phone2,Phone3," + "PhoneType1,PhoneType2,PhoneType3,IsParent,ParentName,PlantName")] FuneralHome funeralHome) { //if (id != funeralHome.FuneralHomeId) if (id == 0) { return(NotFound()); } if (ModelState.IsValid) { if (_context.ParentFuneralHomes.Count() > 1) { ParentFuneralHome parentFuneralHome = await _context.ParentFuneralHomes.FindAsync(funeralHome.ParentFuneralHomeId); if (funeralHome.IsParent && parentFuneralHome == null) { initParentList(funeralHome); addParent(funeralHome); } else { initParentList(funeralHome); } funeralHome.ParentName = parentFuneralHome.ParentFuneralhomeName; } else { ParentFuneralHome parentFuneralHome = await _context.ParentFuneralHomes.FindAsync(funeralHome.ParentFuneralHomeId); if (funeralHome.IsParent && parentFuneralHome == null) { addParent(funeralHome); } if (parentFuneralHome != null) { funeralHome.ParentName = parentFuneralHome.ParentFuneralhomeName; } } if (funeralHome.PlantId != 0) { Plant plt = await _context.Plants.FindAsync(funeralHome.PlantId); funeralHome.PlantName = plt.PlantName; } try { _context.Update(funeralHome); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FuneralHomeExists(funeralHome.FuneralHomeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(funeralHome)); }