Esempio n. 1
0
        /// <inheritdoc />
        public async Task <int> AddMemberAsync(string firstName, string lastName, DateTime birthday)
        {
            CheckIfInitialized();
            if (string.IsNullOrEmpty(firstName))
            {
                throw new ArgumentException("firstName is null");
            }
            if (string.IsNullOrEmpty(lastName))
            {
                throw new ArgumentException("lastName is null");
            }
            if (await dataContext.Members.AnyAsync((m => m.LastName == lastName)))
            {
                throw new DuplicateNameException();
            }
            Member add = new Member
            {
                FirstName = firstName,
                LastName  = lastName,
                Birthday  = birthday
            };
            await dataContext.AddAsync(add);

            await dataContext.SaveChangesAsync();

            return(add.MemberNumber);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public async Task <int> AddMemberAsync(string firstName, string lastName, DateTime birthday)
        {
            if (context == null)
            {
                throw new InvalidOperationException("Not initialized");
            }

            if (string.IsNullOrEmpty(firstName))
            {
                throw new ArgumentException("Firstname has to be not null or not empty");
            }

            if (string.IsNullOrEmpty(lastName))
            {
                throw new ArgumentException("Lastname has to be not null or not empty");
            }
            if (await context.Members.AnyAsync(m => m.LastName == lastName))
            {
                throw new DuplicateNameException("This Lastname already exists in database");
            }
            var newMember = new Member
            {
                FirstName = firstName,
                LastName  = lastName,
                Birthday  = birthday
            };

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

            return(newMember.MemberNumber);
        }