/// <summary>
        /// 创建一个组织
        /// </summary>
        /// <param name="org"></param>
        /// <returns></returns>
        public OperationResult CreateOrganization(OrganizationDTO organization)
        {
            //数据校验
            OperationResult result = Validate(organization);

            if (!result.Success)
            {
                return(result);
            }

            organization = _dal.CreateOrganization(organization);

            if (organization != null)
            {
                OrganizationCreatedEvent @event = new OrganizationCreatedEvent()
                {
                    OrgId  = organization.Id,
                    UserId = organization.MasterId
                };


                _eventBus.PublishAsync <OrganizationCreatedEvent>(@event);
            }

            result.Success  = organization != null;
            result.ObjectId = organization.Id;

            return(result);
        }
Beispiel #2
0
        public async Task <OrganizationDTO> GetOrganizationById(string id)
        {
            OrganizationDTO result = null;

            try
            {
                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Add("gooiosapikey", "999960bff18111e799160126c7e9f568");

                    var reqUrl = $"http://organizationservice.gooios.com/api/organization/v1/getbyid?id={id}";

                    var res = await client.GetAsync(reqUrl);

                    if (res.IsSuccessStatusCode)
                    {
                        var resultStr = await res.Content.ReadAsStringAsync();

                        result = JsonConvert.DeserializeObject <OrganizationDTO>(resultStr);
                    }
                }
            }
            catch (Exception ex)
            {
                //TODO: add error handle logic
            }

            return(result);
        }
        public string Validate(OrganizationDTO organization)
        {
            if (null == organization)
            {
                return(GenericMessages.ObjectIsNull);
            }

            if (organization.Address == null)
            {
                return("Address " + GenericMessages.ObjectIsNull);
            }

            if (organization.ClientId == 0)
            {
                return("Client Data is null ");
            }

            if (String.IsNullOrEmpty(organization.DisplayName))
            {
                return(organization.DisplayName + " " + GenericMessages.StringIsNullOrEmpty);
            }

            if (organization.DisplayName.Length > 255)
            {
                return(organization.DisplayName + " can not be more than 255 characters ");
            }

            return(string.Empty);
        }
Beispiel #4
0
        public async Task GetOrganizationAsyncTest(int orgId, string strOrg, string strUser)
        {
            var repository = A.Fake <IReceiverRepository>();
            var tempOrg    = new OrganizationDTO
            {
                OrganizationId = orgId,
                Name           = strOrg,
                Users          = new List <UserDTO>
                {
                    new UserDTO
                    {
                        FirstName = strUser
                    }
                }
            };

            A.CallTo(() => repository.GetOrganizations())
            .Returns(new List <OrganizationDTO> {
                tempOrg
            }.AsQueryable().BuildMock());

            var service = new ReceiverService(repository, GetMapper());
            var result  = await service.GetOrganizationAsync(orgId, CancellationToken.None);

            Assert.Equal(strOrg, result.Name);
            Assert.Equal(strUser, result.Users[0].FirstName);
        }
Beispiel #5
0
        public async Task AddUserToOrganizationAsyncTest(int userId, int organizationId)
        {
            var repository = A.Fake <IReceiverRepository>();
            var service    = new ReceiverService(repository, GetMapper());

            var user = new UserDTO {
                UserId = userId
            };
            var org = new OrganizationDTO {
                OrganizationId = organizationId
            };

            A.CallTo(() => repository.GetUsers())
            .Returns(new List <UserDTO> {
                user
            }.AsQueryable().BuildMock());

            A.CallTo(() => repository.GetOrganizations())
            .Returns(new List <OrganizationDTO> {
                org
            }.AsQueryable().BuildMock());

            var result = await service.AddUserToOrganizationAsync(userId, organizationId, CancellationToken.None);

            A.CallTo(() => repository.AddUserToOrganizationAsync(userId, organizationId, CancellationToken.None)).MustHaveHappened();
        }
Beispiel #6
0
        public async Task <AuthenticationResponse> register(RegisterCommand command)
        {
            try
            {
                Organization existingOrg = await this._repo.GetByEmail(command.email);

                if (existingOrg != null)
                {
                    return(null);
                }

                RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
                byte[] data = new byte[30];
                rng.GetBytes(data);
                data = new SHA256Managed().ComputeHash(data);
                string salt = Encoding.ASCII.GetString(data);

                string password = this.encrypt(command.password, salt);

                Organization org = new Organization(command.email, command.name, password, salt);

                org = await this._repo.Create(org);

                var             token = generateJwtToken(org);
                OrganizationDTO dto   = new OrganizationDTO(org.email, org.name);

                return(new AuthenticationResponse(token, dto));
            }
            catch (Exception)
            {
                throw new Exception("Internal error registering a new organization");
            }
        }
Beispiel #7
0
    public void Update(OrganizationDTO oldOrg)
    {
        if (newOrg.Action != "C")        // Why are you here?
        {
            throw an exception(bad request)

                  context.Organizations.Attach(Map DTO to entity here);
        }
        foreach (var item in newOrg.Products)
        {
            switch (item.Action)
            case "A":
                ProductRepository.Add(item, newOrg.Id);
            break;

        case "C":
            ProductRepository.Update(item, newOrg.Id);
            break;

        case "D":
            ProductRepository.Delete(item);
            break;
        }
        context.SaveChanges();
        return(Ok());
    }
}
Beispiel #8
0
        public async Task GetUsersPageCountAsyncTest(int userCount, int pageSize)
        {
            var repository = A.Fake <IReceiverRepository>();

            var org = new OrganizationDTO
            {
                Name           = "org",
                OrganizationId = 1
            };

            var userList = new List <UserDTO>();

            for (int i = 0; i < userCount; i++)
            {
                userList.Add(new UserDTO
                {
                    FirstName    = $"user{i}",
                    Organization = org
                });
            }

            A.CallTo(() => repository.GetUsers())
            .Returns(userList.AsQueryable().BuildMock());

            var service = new ReceiverService(repository, GetMapper());
            var result  = await service.GetUsersPageCountAsync(1, pageSize, CancellationToken.None);

            var expected = (userCount / pageSize) + 1;

            Assert.Equal((int)expected, (int)result);
        }
Beispiel #9
0
        public async Task <AuthenticationResponse> login(LoginCommand command)
        {
            try
            {
                Organization org = await this._repo.GetByEmail(command.email);

                if (org == null)
                {
                    return(null);
                }
                string loginPassword = this.encrypt(command.password, org.salt);
                if (loginPassword != org.password)
                {
                    return(null);
                }

                var             token = generateJwtToken(org);
                OrganizationDTO dto   = new OrganizationDTO(org.email, org.name);

                return(new AuthenticationResponse(token, dto));
            }
            catch (Exception)
            {
                throw new Exception("Internal error logging in an organization");
            }
        }
Beispiel #10
0
 public async Task ChangeOrganization(OrganizationDTO organization)
 {
     using (ContractContext context = new ContractContext())
     {
         var org = context.Organizations.Where(org => org.Id == organization.Id).FirstOrDefault();
         if (!org.Name.Equals(organization.Name))
         {
             org.Name = organization.Name;
         }
         if (!org.FullName.Equals(organization.FullName))
         {
             org.FullName = organization.FullName;
         }
         if (!org.Address.Equals(organization.Address))
         {
             org.Address = organization.Address;
         }
         if (!org.Email.Equals(organization.Email))
         {
             org.Email = organization.Email;
         }
         if (!org.Smdo.Equals(organization.Smdo))
         {
             org.Smdo = organization.Smdo;
         }
         await context.SaveChangesAsync();
     }
 }
Beispiel #11
0
        public void AddOrganization(OrganizationDTO model, string operatorId)
        {
            var organization = OrganizationFactory.CreateOrganization(model.FullName, model.ShortName, model.CertificateNo, model.Introduction, operatorId, model.Address, model.LogoImageId, model.Phone, model.CustomServicePhone);

            _organizationRepository.Add(organization);
            _dbUnitOfWork.Commit();
        }
Beispiel #12
0
 public OrganizationDTO setdata(OrganizationDTO obj)
 {
     try
     {
         obj.NAME                     = "FullOrgCabinet";
         obj.ADDRESS1                 = "840 Sullivan Drive";
         obj.ADDRESS2                 = "";
         obj.CITY                     = "Lansdale";
         obj.STATECODE                = "";
         obj.ZIPCODE                  = "19442";
         obj.PHONE                    = "2151234567";
         obj.EMAILADDRESS             = "*****@*****.**";
         obj.ORGANIZATIONTYPEID       = 1;//Convert.ToInt16(ddlOrganizationType.SelectedValue);
         obj.CONTACTPERSON            = "Contact name";
         obj.DATECREATED              = DateTime.UtcNow;
         obj.ORGANIZATIONSTATUSID     = 1;
         obj.SALESREPID               = 1;
         obj.DIRECTORNAME             = "Director Name";
         obj.DIRECTOREMAIL            = "*****@*****.**";
         obj.DIRECTORPHONE            = "33344455555";
         obj.ALLOWCOACHTOCREATEEVENTS = Convert.ToString(chkAllowCoach.Checked);
         obj.CCALLEMAILTODIRECTOR     = Convert.ToString(chkCCEmail.Checked);
         obj.CABINETID                = "0";
         obj.COMMENT                  = "comments";
     }
     catch (Exception ex)
     {
     }
     return(obj);
 }
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="organization">OrganizationDTO</param>
 public Organization(OrganizationDTO organization)
 {
     OrganizationID = organization.OrganizationId;
     Name           = organization.Name;
     DisplayName    = organization.DisplayName;
     Description    = organization.Description;
 }
        public static UserOrganization ToModel(this OrganizationDTO source)
        {
            if (source == null)
            {
                return(null);
            }

            var userOrganization = new UserOrganization(source);

            if (source.Identifier != null || source.AdditionalIdentifiers?.Count > 0)
            {
                List <UserOrganizationIdentifier> allIdentifiers = new List <UserOrganizationIdentifier>();
                if (source.Identifier != null)
                {
                    allIdentifiers.Add(new UserOrganizationIdentifier(source.Identifier)
                    {
                        Main = true
                    });
                }
                if (source.AdditionalIdentifiers != null)
                {
                    allIdentifiers.AddRange(source.AdditionalIdentifiers?.Select(i => new UserOrganizationIdentifier(i)));
                }
                userOrganization.AllIdentifiers = allIdentifiers;
            }

            return(userOrganization.InitComplexProperties());
        }
Beispiel #15
0
 public static ProcuringEntity ToModel(this OrganizationDTO source)
 {
     throw new NotImplementedException();
     if (source == null)
     {
         return(null);
     }
 }
Beispiel #16
0
        private OrganizationDTO ToOrganizationDTO(Organization item)
        {
            OrganizationDTO result = new OrganizationDTO();

            result.ID   = item.ID;
            result.Name = item.Name;
            return(result);
        }
 public static Organization Map(OrganizationDTO organizationDTO)
 {
     return(new Organization()
     {
         Id = Guid.Parse(organizationDTO.Id),
         Name = organizationDTO.Name
     });
 }
Beispiel #18
0
        public async Task <int> AddUserOrganization(OrganizationDTO userOrganizationDTO)
        {
            var userOrganizationModel = UserOrganizationMapper.ToModel(userOrganizationDTO);
            var userOrganization      = Context.UserOrganizations.Add(userOrganizationModel);
            await Context.SaveChangesAsync();

            return(userOrganization.Id);
        }
        /// <summary>
        /// 获取组织列表
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public List <OrganizationDTO> GetOrganizations(OrganizationFilter filter)
        {
            List <OrganizationDAO> organizationDaoList = _dal.GetOrganizations(filter);

            List <OrganizationDTO> result = new OrganizationDTO().ConvertList(organizationDaoList);

            return(result);
        }
Beispiel #20
0
        private void ucOrganizationList_OrganizationSelected(object sender, OrganizationSelectedArg e)
        {
            selectedOrganization = e.Organization;
            List <UserDTO> userList = bizUser.GetUserByOrganization(selectedOrganization.ID);

            dtgUsersByOrganization.ItemsSource = userList;
            ClearRoles();
        }
Beispiel #21
0
 public OrganizationBM(OrganizationDTO organizationDto)
 {
     this.id       = organizationDto.id;
     this.name     = organizationDto.name;
     this.category = organizationDto.category;
     this.comment  = organizationDto.comment;
     this.phone    = organizationDto.phone;
     this.email    = organizationDto.email;
 }
Beispiel #22
0
        // Отображение информации об организации
        public async Task <ActionResult> Index()
        {
            OrganizationDTO oDto = await(_organizationService as OrganizationService).GetFirstAsync();

            InitializeMapper();
            OrganizationViewModel organization = Mapper.Map <OrganizationDTO, OrganizationViewModel>(oDto);

            return(View("Index", organization));
        }
Beispiel #23
0
        public static void StartTest()
        {
            initialize();
            string parentId = "0";   //找组织id为0的下面的人员
            string tenantId = "001"; //找租户为011的人员和组织

            List <(Organization, Account)> result = (from o in orgs join oa in organizationAccounts on o.Id equals oa.OrgId join a in accounts on oa.UserId equals a.Id where o.TenantId == tenantId select(o, a)).ToList();

            #region 逻辑一 转化为树

            List <OrganizationDTO> organizationDTOs = new List <OrganizationDTO>();
            foreach (var item in result)
            {
                //查询添加过这个节点没有
                OrganizationDTO organizationDTO = organizationDTOs.Where(x => x.Id == item.Item1.Id).FirstOrDefault();

                if (organizationDTO == null)
                {//没有添加过
                    organizationDTO = new OrganizationDTO()
                    {
                        Id       = item.Item1.Id,
                        Name     = item.Item1.Name,
                        ParentId = item.Item1.ParentId,
                        TenantId = item.Item1.TenantId,
                        Accounts = new List <Account>()
                    };
                    organizationDTO.Accounts.Add(item.Item2);
                    organizationDTOs.Add(organizationDTO);
                }
                else
                {//添加过
                    organizationDTO.Accounts.Add(item.Item2);
                }
            }

            //----------------------查看这个结果-----------------------------
            organizationDTOs = organizationDTOs.ToTree(parentId);

            #endregion

            #region  逻辑二 返回该组织的用户+子组织的用户
            //先筛选出该组织和子组织
            List <(Organization, Account)> ps = SelectChild(result, parentId);
            //再取出用户
            //------------------------------查看这个结局-----------------------------------
            List <Account> resultaccounts = new List <Account>();

            foreach (var item in ps)
            {
                if (!resultaccounts.Any(x => x.Id == item.Item2.Id))
                {
                    resultaccounts.Add(item.Item2);
                }
            }
            #endregion
        }
        public void testOrgDTOModel()
        {
            OrganizationDTO   objOrgDTO            = new OrganizationDTO();
            OrganizationModel objOrganizationModel = new OrganizationModel();
            int numberOfPublicPropertiesofOrgDTO   = objOrgDTO.GetType().GetProperties().Count();
            int numberOfPublicPropertiesofOrgmodel = objOrganizationModel.GetType().GetProperties().Count();

            Assert.AreEqual(numberOfPublicPropertiesofOrgDTO, OrganizationDTOPropertyCount, "OrganizationDTO properties has been changed");
            Assert.AreEqual(numberOfPublicPropertiesofOrgmodel, OrganizationModelPropertyCount, "OrganizationModel properties has been changed");
        }
        public async Task <OrganizationDTO> SaveOrganizationDetails(OrganizationDTO organizationDTO)
        {
            var organization = dbContext.Organizations.Create <Organization>();

            organization = Mapper.Map <OrganizationDTO, Organization>(organizationDTO);
            dbContext.Organizations.Add(organization);
            dbContext.SaveChanges();
            organizationDTO = Mapper.Map <Organization, OrganizationDTO>(organization);
            return(organizationDTO);
        }
Beispiel #26
0
 public static OrganizationBO ToOrgBusinessObject(OrganizationDTO pDTO)
 {
     return(new OrganizationBO
     {
         IsEnabled = pDTO.IsEnabled,
         Organization = pDTO.Organization,
         OrganizationKey = pDTO.OrganizationKey,
         OrganizationId = pDTO.OrganizationId
     });
 }
        public void SaveOrganization(OrganizationDTO organizationDto)
        {
            using (var context = new MyProjectEntities())
            {
                Organization dbOrganization = null;
                if (organizationDto.ID == 0)
                {
                    dbOrganization = new Organization();
                    dbOrganization.SecuritySubject      = new SecuritySubject();
                    dbOrganization.SecuritySubject.Type = (int)SecuritySubjectType.Organization;
                }
                else
                {
                    dbOrganization = context.Organization.First(x => x.ID == organizationDto.ID);
                }

                dbOrganization.Name               = organizationDto.Name;
                dbOrganization.ExternalKey        = organizationDto.ExternalKey;
                dbOrganization.OrganizationTypeID = organizationDto.OrganizationTypeID;

                List <OrganizationPost> removedItems = new List <OrganizationPost>();
                foreach (var post in dbOrganization.OrganizationPost)
                {
                    if (!organizationDto.OrganizationPosts.Any(x => x.ID == post.ID))
                    {
                        removedItems.Add(post);
                    }
                }
                foreach (var item in removedItems.ToList())
                {
                    context.OrganizationPost.Remove(item);
                }
                foreach (var post in organizationDto.OrganizationPosts)
                {
                    var dbPost = dbOrganization.OrganizationPost.FirstOrDefault(x => post.ID != 0 && x.ID == post.ID);
                    if (dbPost == null)
                    {
                        dbPost = new OrganizationPost();
                        dbOrganization.OrganizationPost.Add(dbPost);
                        dbPost.SecuritySubject      = new SecuritySubject();
                        dbPost.SecuritySubject.Type = (int)SecuritySubjectType.OrganizationPost;
                    }
                    dbPost.Name        = post.Name;
                    dbPost.ExternalKey = post.ExternalKey;
                    dbPost.UserID      = post.CurrentUserID;
                    dbPost.OrganizationType_RoleTypeID = post.OrganizationTypeRoleTypeID;
                }

                if (dbOrganization.ID == 0)
                {
                    context.Organization.Add(dbOrganization);
                }
                context.SaveChanges();
            }
        }
        public void EditAsync_NamePropertyIsNull_Throws()
        {
            OrganizationService os   = GetNewService();
            OrganizationDTO     item = new OrganizationDTO {
                Name = null
            };

            Exception ex = Assert.CatchAsync(async() => await os.EditAsync(item));

            StringAssert.Contains("Требуется ввести наименование организации", ex.Message);
        }
Beispiel #29
0
        public static OrganizationModel ToOrganizationModel(this OrganizationDTO DTO)
        {
            OrganizationModel ModelList = new OrganizationModel();

            ModelList.IsEnabled          = DTO.IsEnabled;
            ModelList.IsHostOrganization = DTO.IsHostOrganization;
            ModelList.Organization       = DTO.Organization;
            ModelList.OrganizationId     = DTO.OrganizationId;
            ModelList.OrganizationKey    = DTO.OrganizationKey;
            return(ModelList);
        }
 public static OrganizationBO ToOrganizationBO(this OrganizationDTO pDTO)
 {
     return(new OrganizationBO
     {
         IsEnabled = pDTO.IsEnabled,
         IsHostOrganization = pDTO.IsHostOrganization,
         Organization = pDTO.Organization,
         OrganizationKey = pDTO.OrganizationKey,
         OrganizationId = pDTO.OrganizationId
     });
 }
Beispiel #31
0
 public static OrganizationDTO CreateOrganizationDTO(int ID, bool isValid, int sort, global::System.DateTime createDate, global::System.Collections.ObjectModel.ObservableCollection<OrganizationRoleDTO> organizationRoles)
 {
     OrganizationDTO organizationDTO = new OrganizationDTO();
     organizationDTO.Id = ID;
     organizationDTO.IsValid = isValid;
     organizationDTO.Sort = sort;
     organizationDTO.CreateDate = createDate;
     if ((organizationRoles == null))
     {
         throw new global::System.ArgumentNullException("organizationRoles");
     }
     organizationDTO.OrganizationRoles = organizationRoles;
     return organizationDTO;
 }
Beispiel #32
0
 public void AddToOrganizations(OrganizationDTO organizationDTO)
 {
     base.AddObject("Organizations", organizationDTO);
 }