Esempio n. 1
0
        /// <inheritdoc />
        public async Task <int> AddMemberAsync(string firstName, string lastName, DateTime birthday)
        {
            ThrowIfNotInitialized();

            if (string.IsNullOrEmpty(firstName))
            {
                throw new ArgumentException();
            }

            if (string.IsNullOrEmpty(lastName))
            {
                throw new ArgumentException();
            }

            if (await dataContext.Members.AnyAsync(m => m.LastName == lastName))
            {
                throw new DuplicateNameException();
            }

            //
            // Add new member and save the context
            //
            var newMember = new Member {
                Birthday = birthday, FirstName = firstName, LastName = lastName
            };

            _ = await dataContext.Members.AddAsync(newMember);

            _ = await dataContext.SaveChangesAsync();

            return(newMember.MemberNumber);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public async Task <int> AddMemberAsync(string firstName, string lastName, DateTime birthday)
        {
            IsContextValid();

            // check for duplicate not implemented yet
            var newMember = new Member
            {
                FirstName = firstName,
                LastName  = lastName,
                Birthday  = birthday
            };

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

            return(newMember.MemberNumber);
        }
        /// <inheritdoc />
        public async Task <int> AddMemberAsync(string firstName, string lastName, DateTime birthday)
        {
            if (context == null)
            {
                throw new InvalidOperationException();
            }
            if (context.Members.Count(m => m.LastName == lastName) > 0)
            {
                throw new DuplicateNameException();
            }
            var member = new Member {
                Birthday = birthday, FirstName = firstName, LastName = lastName
            };
            await context.Members.AddAsync(member);

            await context.SaveChangesAsync();

            return(member.MemberNumber);
        }
Esempio n. 4
0
        /// <inheritdoc />
        public async Task <int> AddMemberAsync(string firstName, string lastName, DateTime birthday)
        {
            ThrowIfNotInitialised();
            if (string.IsNullOrEmpty(firstName))
            {
                throw new ArgumentException("FirstName is invalid");
            }
            if (string.IsNullOrEmpty(lastName))
            {
                throw new ArgumentException("LastName is invalid");
            }
            if (birthday == null)
            {
                throw new ArgumentException("Birthday is invalid");
            }

            if (_context == null)
            {
                throw new InvalidOperationException();
            }

            if (_context.Members.Where(m => m.LastName.Equals(lastName)).Any())
            {
                throw new DuplicateNameException();
            }

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

            _context.Members.Add(member);

            await _context.SaveChangesAsync();

            return(member.MemberNumber);
        }