public static Result <Phone> Create(GroupPhone groupPhone, string number)
        {
            var errors = new List <string>();

            if (groupPhone is null)
            {
                errors.Add(nameof(groupPhone));
            }
            if (string.IsNullOrEmpty(number))
            {
                errors.Add("Number is required");
            }

            if (errors.Any())
            {
                return(Result <Phone> .Fail(errors));
            }

            var newPhone = new Phone
            {
                GroupPhone = groupPhone,
                Number     = number
            };

            return(Result <Phone> .Success(newPhone));
        }
        public Result <bool> AddGroupPhone(string name)
        {
            var errors = new List <string>();

            if (errors.Any())
            {
                return(Result <bool> .Fail(errors));
            }

            var result = GroupPhone.Create(name);

            GroupPhoneInternal.Add(result.Value);
            return(Result <bool> .Success(true));
        }
        public Result <bool> RemoveGroupPhone(GroupPhone groupPhoneToDelete)
        {
            var errors = new List <string>();

            if (groupPhoneToDelete is null)
            {
                errors.Add(nameof(groupPhoneToDelete));
            }

            if (errors.Any())
            {
                return(Result <bool> .Fail(errors));
            }

            GroupPhoneInternal.Remove(groupPhoneToDelete);
            return(Result <bool> .Success(true));
        }
        public Result <bool> AddPhone(GroupPhone groupPhone, string number)
        {
            var errors = new List <string>();

            if (Phones.Any(phone => phone.Number.Equals(number, StringComparison.OrdinalIgnoreCase)))
            {
                errors.Add("This number already exists");
            }

            if (errors.Any())
            {
                return(Result <bool> .Fail(errors));
            }

            var result = Phone.Create(groupPhone, number);

            PhoneInternal.Add(result.Value);
            return(Result <bool> .Success(true));
        }
Exemplo n.º 5
0
        public static Result <GroupPhone> Create(string name)
        {
            var errors = new List <string>();

            if (string.IsNullOrEmpty(name))
            {
                errors.Add(" Name is required");
            }

            if (errors.Any())
            {
                return(Result <GroupPhone> .Fail(errors));
            }

            var newGroupPhone = new GroupPhone
            {
                Name = name
            };

            return(Result <GroupPhone> .Success(newGroupPhone));
        }