public static DataModel.User ToDataModel(this DomainModel.User entity)
        {
            var phones  = entity.Phones.ToDataModel(entity);
            var address = entity.Address?.ToDataModel();

            var user = new DataModel.User
            {
                Id         = entity.Id,
                FirstName  = entity.Name.FirstName,
                MiddleName = entity.Name.MiddleName,
                LastName   = entity.Name.LastName,
                Email      = entity.Email,
                Cpf        = entity.Cpf,
                Phones     = phones
            };

            if ((address?.Id ?? 0) > 0)
            {
                user.IdAddress = address?.Id;
            }
            else
            {
                user.Address = address;
            }

            return(user);
        }
Beispiel #2
0
        public static IList <DataModel.UserPhone> ToDataModel(this IList <DomainModel.Phone> phones, DomainModel.User user)
        {
            var list   = new List <DataModel.UserPhone>();
            var dmUser = new DataModel.User
            {
                FirstName  = user.Name.FirstName,
                MiddleName = user.Name.MiddleName,
                LastName   = user.Name.LastName,
                Email      = user.Email,
                Cpf        = user.Cpf
            };

            if (user.Id > 0)
            {
                dmUser.Id = user.Id;
            }

            foreach (var p in phones)
            {
                var up = new DataModel.UserPhone();

                if (p.Id > 0)
                {
                    up.IdPhone = p.Id;
                }
                else
                {
                    up.Phone = new DataModel.Phone
                    {
                        LocalCode = p.LocalCode,
                        Number    = p.Number
                    }
                };

                if (user.Id > 0)
                {
                    up.IdUser = user.Id;
                }
                else
                {
                    up.User = dmUser;
                }

                list.Add(up);
            }

            return(list);
        }
    }
Beispiel #3
0
 public UserSpec(Entities.User entity) : base(entity)
 {
     ValidateName(entity.Name);
     ValidateCpf(entity.Cpf);
     ValidateEmail(entity.Email);
 }
Beispiel #4
0
 internal static Entities.TokenModel GetTokenFromUser(Entities.User user)
 => new Faker <Entities.TokenModel>()
 .CustomInstantiator(f => new Entities.TokenModel(user.Id, user.Email, f.Random.String(), GetRefreshTokenFromIdUser(user.Id).RefreshToken))
 .Generate(1)
 .First();
Beispiel #5
0
 internal static UserResponse GetResponseByUser(Entities.User user)
 => new UserResponse
 {
     Id = user.Id
 };
Beispiel #6
0
 internal static Entities.User GetUserWithId(Entities.User user)
 => new Entities.User(50, user.Name, user.Email, user.Cpf, user.Address, user.Phones);