Пример #1
0
        public async Task <UserDTO> Register(UserTransferDTO dto)
        {
            NetworkEntity userEntity = DataContext.NetworkEntities.Add(new NetworkEntity {
                NetworkID = dto.NetworkID, NetworkEntityID = dto.ID, EntityType = EntityType.User
            });

            Data.User user = DataContext.Users.Add(new Data.User()
            {
                ID             = userEntity.ID,
                UserName       = dto.UserName,
                FirstName      = dto.FirstName,
                LastName       = dto.LastName,
                MiddleName     = dto.MiddleName,
                PhoneNumber    = dto.PhoneNumber,
                FaxNumber      = dto.FaxNumber,
                EmailAddress   = dto.EmailAddress,
                NetworkID      = dto.NetworkID,
                OrganizationID = dto.OrganizationID,
                Salutation     = dto.Salutation,
            });

            await DataContext.SaveChangesAsync();

            if (dto.Metadata != null && dto.Metadata.Count() > 0)
            {
                IList <Data.UserDomainData> metadata = new List <Data.UserDomainData>();
                foreach (var meta in dto.Metadata)
                {
                    var orgMeta = new UserDomainData()
                    {
                        UserID         = user.ID,
                        DomainUseID    = meta.DomainUseID,
                        Value          = meta.Value,
                        SequenceNumber = meta.SequenceNumber,
                    };
                    if (meta.DomainReferenceID.HasValue)
                    {
                        orgMeta.DomainReferenceID = meta.DomainReferenceID.Value;
                    }
                    metadata.Add(orgMeta);
                }
                if (metadata.Count > 0)
                {
                    DataContext.DomainDatas.AddRange(metadata);
                }
                await DataContext.SaveChangesAsync();
            }

            return(user.Map <User, UserDTO>());
        }