public async Task <IActionResult> Create([Bind("InstitutionName,type,duration,amount")] SocialHelp socialHelp)
        {
            if (ModelState.IsValid)
            {
                // _context.Add(socialHelp);
                // await _context.SaveChangesAsync();
                //return RedirectToAction(nameof(Index));
                if (TempData["Field"] != null)
                {
                    socialHelp.BeneficiarID = (int)TempData.Peek("BenId");
                    _context.Add(socialHelp);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("ChooseField", "Home"));
                }


                CreateModel model = TempData.Get <CreateModel>("model");
                model.SocialHelp = socialHelp;
                TempData.Put <CreateModel>("model", model);

                string b = model.SocialHelp.duration;

                return(Redirect("~/Beneficiars/PushToDB"));
            }
            return(View(socialHelp));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,InstitutionName,type,duration,amount,BeneficiarID")] SocialHelp socialHelp)
        {
            if (id != socialHelp.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(socialHelp);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SocialHelpExists(socialHelp.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("ChooseField", "Home"));
                //return RedirectToAction(nameof(Index));
            }
            return(View(socialHelp));
        }
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var beneficiar = await _context.Beneficiars.FindAsync(id);

            Wife wife = _context.Wives.Where(w => w.BeneficiarID == id).FirstOrDefault();

            if (wife != null)
            {
                Work w1 = _context.works.Where(w => w.WifeID == wife.Id).FirstOrDefault();
                if (w1 != null)
                {
                    _context.works.Remove(w1);
                }
                await _context.SaveChangesAsync();

                Disease d1 = _context.diseases.Where(w => w.WifeID == wife.Id).FirstOrDefault();
                if (d1 != null)
                {
                    _context.diseases.Remove(d1);
                }
                await _context.SaveChangesAsync();

                _context.Wives.Remove(wife);
            }
            Work w = _context.works.Where(w => w.BeneficiarID == id).FirstOrDefault();

            if (w != null)
            {
                _context.works.Remove(w);
            }

            Belongings b = _context.belongings.Where(w => w.BeneficiarID == id).FirstOrDefault();

            if (b != null)
            {
                _context.belongings.Remove(b);
            }

            Address a = _context.addresses.Where(w => w.BeneficiarID == id).FirstOrDefault();

            if (a != null)
            {
                _context.addresses.Remove(a);
            }

            Loans l = _context.loans.Where(w => w.BeneficiarID == id).FirstOrDefault();

            if (l != null)
            {
                _context.loans.Remove(l);
            }

            SocialHelp s = _context.socialHelps.Where(w => w.BeneficiarID == id).FirstOrDefault();

            if (s != null)
            {
                _context.socialHelps.Remove(s);
            }

            Disease d = _context.diseases.Where(w => w.BeneficiarID == id).FirstOrDefault();

            if (d != null)
            {
                _context.diseases.Remove(d);
            }

            List <Child> children = _context.children.Where(c => c.BeneficiarID == id).ToList();

            foreach (Child c in children)
            {
                Work w2 = _context.works.Where(w => w.ChildID == c.Id).FirstOrDefault();
                if (w2 != null)
                {
                    _context.works.Remove(w2);
                }
                Disease d2 = _context.diseases.Where(w => w.ChildID == c.Id).FirstOrDefault();
                if (d2 != null)
                {
                    _context.diseases.Remove(d2);
                }

                await _context.SaveChangesAsync();

                _context.children.Remove(c);
            }
            await _context.SaveChangesAsync();

            _context.Beneficiars.Remove(beneficiar);

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }