示例#1
0
        public void DbDeleteTest()
        {
            var options = new DbContextOptionsBuilder <InvitationsDbContext>()
                          .UseInMemoryDatabase(databaseName: "DbDeleteTestDatabase")
                          .Options;

            using (var context = new InvitationsDbContext(options))
            {
                context.Invitations.Add(new Invitation {
                    Phone = "79998887766", Author = 4
                });
                context.Invitations.Add(new Invitation {
                    Phone = "79998887765", Author = 4
                });
                context.Invitations.Add(new Invitation {
                    Phone = "79998887764", Author = 4
                });
                context.SaveChanges();
            }

            using (var context = new InvitationsDbContext(options))
            {
                var invitationRepository = new InvitationRepository(context);

                var invitation = new Invitation {
                    Phone = "78888888888", Author = 4
                };

                Invitation addedInvitation = invitationRepository.Delete(2);

                Assert.True(context.Invitations.Count() == 2 && invitation != null);
            }
        }
示例#2
0
        public Member Create(Member member)
        {
            IInvitationRepository _invitationRepository = new InvitationRepository();

            // interdiction de créer un membre s'il n'y a pas d'invitation en cours
            Invitation invitation = _invitationRepository.GetByUserAndPlanning(member.IdUser, member.IdPlanning);

            if (invitation == null)
            {
                return(null);
            }

            using (var connection = Database.GetConnection())
            {
                connection.Open();
                var command = connection.CreateCommand();

                command.CommandText = MemberQueries.ReqCreate;
                command.Parameters.AddWithValue($"@{MemberQueries.ColIdUser}", member.IdUser);
                command.Parameters.AddWithValue($"@{MemberQueries.ColIdPlanning}", member.IdPlanning);
                command.Parameters.AddWithValue($"@{MemberQueries.ColIsGranted}", member.IsGranted);

                command.ExecuteNonQuery();
            }

            // une fois le membre présent, plus besoin de l'invitation
            _invitationRepository.Delete(invitation.Id);

            return(member);
        }
        public ActionResult Delete(int id)
        {
            if (_invitationRepository.Delete(id))
                return Ok();

            return NotFound();
        }