public async Task <IActionResult> AcceptShare(int id)
        {
            ApplicationUser user = await GetCurrentUserAsync();

            SharedDependent remove = await _context.SharedDependent
                                     .Where(sd => sd.DependentUserId == id && sd.ToUser == user)
                                     .SingleOrDefaultAsync();

            DependentUser DependentUser = new DependentUser
            {
                DependentId = id,
                User        = user,
            };

            _context.Add(DependentUser);
            await _context.SaveChangesAsync();

            _context.Remove(remove);
            await _context.SaveChangesAsync();



            // SharedDependent Remove =  RemoveFromShareTable(id);
            //return RedirectToAction("RemoveShared", new { id = id });
            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("DependentId,FirstName,LastName,Birthday,SocialSecurityNumber,DependentNotes")] Dependent dependent)
        {
            //gets the current user
            ApplicationUser user = await GetCurrentUserAsync();

            if (ModelState.IsValid)
            {
                _context.Add(dependent);
                await _context.SaveChangesAsync();


                //create entry on DependentUser Table
                var newDependentUser = new DependentUser
                {
                    User        = user,
                    DependentId = dependent.DependentId
                };

                _context.Add(newDependentUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            return(View(dependent));
        }