示例#1
0
        // [ValidateAntiForgeryToken]
        // To fix the MemberID and Member problem, the Member CvgsClubContext had to change its foreign key connection
        // Member now has a foreign connection to the friendID rather than the memberID
        public async Task <IActionResult> Add(string id, FriendsFamily friendsFamily)
        {
            string memberId = HttpContext.Session.GetString("userId");

            _familyContext.AddFamily(_context, friendsFamily, id, memberId);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public void AddFamily(CvgsClubContext context, FriendsFamily friends, string id, string memberId)
        {
            try
            {
                if (id == null || memberId == null || friends == null || context == null)
                {
                    throw new Exception();
                }

                friends.MemberId = memberId;
                friends.FriendId = id;
                context.Add(friends);
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
                throw e;
            }
        }
示例#3
0
        public void AddFamily_SendCvgsContextAndFriendAndIdAndLoginMemberId_ReturnNoException()
        {
            // Arrange
            FriendsFamily friendsFamily = new FriendsFamily();
            string        id            = "FRIEND";
            string        memberId      = "USER";
            Exception     exception     = null;

            // Act
            try
            {
                contextFriend.AddFamily(context, friendsFamily, id, memberId);
            }
            catch (Exception e)
            {
                exception = e;
            }

            // Assert
            Assert.Null(exception);
            context.EFValidation();
        }