/// <inheritdoc />
        public async Task <int> AddMemberAsync(string firstName, string lastName, DateTime birthday)
        {
            CheckIfDataBaseExists();
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName))
            {
                throw new ArgumentException("FirstName or Lastname is null");
            }
            //Wurde von der Lösung kopiert
            if (await context.Members.AnyAsync(m => m.LastName == lastName))
            {
                throw new DuplicateNameException();
            }

            Member m = new Member
            {
                FirstName = firstName,
                LastName  = lastName,
                Birthday  = birthday,
            };

            context.Members.Add(m);
            await context.SaveChangesAsync();

            return(m.MemberNumber);
        }
        /// <inheritdoc />
        public async Task <int> AddMemberAsync(string firstName, string lastName, DateTime birthday)
        {
            if (String.IsNullOrEmpty(firstName))
            {
                throw new ArgumentException("First name cannot be null");
            }
            if (String.IsNullOrEmpty(lastName))
            {
                throw new ArgumentException("Last name cannot be null");
            }
            if (birthday == null)
            {
                throw new ArgumentException("Birthday cannot be null");
            }

            Member m = new Member
            {
                FirstName = firstName,
                LastName  = lastName,
                Birthday  = birthday
            };

            if (dataContext.Member.Any(m => m.LastName.Equals(lastName)))
            {
                throw new DuplicateNameException("LastName is already in use");
            }

            dataContext.Add(m);

            await dataContext.SaveChangesAsync();

            return(m.MemberNumber);
        }
        /// <inheritdoc />
        public async Task <int> AddMemberAsync(string firstName, string lastName, DateTime birthday)
        {
            CheckDatabaseInitialized();
            var newMember = new Member
            {
                FirstName = firstName,
                LastName  = lastName,
                Birthday  = birthday
            };

            dataContext.Members.Add(newMember);

            await dataContext.SaveChangesAsync();

            return(newMember.MemberNumber);
        }
 /// <inheritdoc />
 public async Task InitializeDatabaseAsync()
 {
     if (_context != null)
     {
         throw new InvalidOperationException();
     }
     _context = new CashDeskDataContext();
     await _context.SaveChangesAsync();
 }
        /// <inheritdoc />
        public async Task <int> AddMemberAsync(string firstName, string lastName, DateTime birthday)
        {
            if (_context == null)
            {
                throw new InvalidOperationException();
            }
            if (_context.Members.Count(member => member.LastName == lastName) > 0)
            {
                throw new DuplicateNameException();
            }
            if (firstName == null || lastName == null || birthday == null)
            {
                throw new ArgumentException("Value NULL is not allowed");
            }

            var result = await _context.AddAsync(new Member
            {
                FirstName = firstName,
                LastName  = lastName,
                Birthday  = birthday
            });

            await _context.SaveChangesAsync();

            return(result.Entity.MemberNumber);
        }
        /// <inheritdoc />
        public async Task <int> AddMemberAsync(string firstName, string lastName, DateTime birthday)
        {
            ThrowIfNotInitialized();

            if (string.IsNullOrEmpty(firstName))
            {
                throw new ArgumentException("Must not be null or empty", nameof(firstName));
            }

            if (string.IsNullOrEmpty(lastName))
            {
                throw new ArgumentException("Must not be null or empty", nameof(lastName));
            }

            if (await dataContext.Members.AnyAsync(m => m.LastName == lastName))
            {
                // Member with the same last name already exists.
                throw new DuplicateNameException();

                // Note that we cannot rely on EFCore's InMemory provider to throw an exception
                // if the duplicate last names are insted even if we create a unique key.
                // InMemory is NOT a full relational database. A real database like SQL Server
                // would throw an exception. For details see:
                // https://docs.microsoft.com/en-us/ef/core/miscellaneous/testing/in-memory#inmemory-is-not-a-relational-database
            }

            var newMember = new Member
            {
                FirstName = firstName,
                LastName  = lastName,
                Birthday  = birthday
            };

            dataContext.Members.Add(newMember);

            await dataContext.SaveChangesAsync();

            return(newMember.MemberNumber);
        }
        /// <inheritdoc />
        public async Task <int> AddMemberAsync(string firstName, string lastName, DateTime birthday)
        {
            if (context == null)
            {
                throw new InvalidOperationException();
            }
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || birthday == null)
            {
                throw new ArgumentException("Firstname, Lastname, or birthday is null or empty!");
            }
            if (context.Members.Where(curMember => curMember.LastName.Equals(lastName)).Count() > 0)
            {
                throw new DuplicateNameException("The lastname " + lastName + " already exists!");
            }
            Member member = new Member {
                FirstName = firstName, LastName = lastName, Birthday = birthday
            };

            context.Members.Add(member);
            await context.SaveChangesAsync();

            return(member.MemberNumber);
        }