Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        public Result <bool> UpdatePhone(int id, GroupPhone groupPhone, string number)
        {
            var phone = PhoneInternal.FirstOrDefault(g => g.Id == id);

            if (phone != null)
            {
                var updateResult = phone.Update(groupPhone, number);
                if (!updateResult.Succeeded)
                {
                    return(Result <bool> .Fail(updateResult.Errors));
                }
                return(Result <bool> .Success(true));
            }
            return(Result <bool> .Fail("Phone not found"));
        }
Exemplo n.º 3
0
        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 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));
        }
Exemplo n.º 5
0
        public Result <bool> Update(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 <bool> .Fail(errors));
            }

            GroupPhone = groupPhone;
            Number     = number;

            return(Result <bool> .Success(true));
        }
Exemplo n.º 6
0
        public Result <bool> AddGroupPhone(GroupPhone groupPhone)
        {
            GroupPhoneInternal.Add(groupPhone);

            return(Result <bool> .Success(true));
        }