public async Task <Organization> AddContactAsync(long organizationId, long contactId)
        {
            var entityExists = await _organizationContactRepository.CheckIfOrganizationContactExistsAsync(contactId, organizationId);

            if (entityExists)
            {
                throw new Exception("try to add a connection, while there is already one");
            }

            var organization = await GetByIdAsync(organizationId);

            var contact = await _contactRepository.GetByIdAsync(contactId);

            if (organization == null || contact == null)
            {
                throw new Exception("can not find entities with given ids");
            }

            var organizationContact = new OrganizationContact()
            {
                Organization = organization, Contact = contact
            };

            await _organizationContactRepository.CreateAsync(organizationContact);

            return(organization);
        }
示例#2
0
        public ActionResult EditOrganizationContact(string _ID)
        {
            int Id = Convert.ToInt32(DecryptString(_ID));
            OrganizationContact objorganizationContact = new OrganizationContact();

            objorganizationContact = Mapper.Map <OrganizationContact>(_clientService.GetOrganizationContactByID(Id));
            objorganizationContact.EncryptedOrganizationContactID = (_ID);
            return(View("OrganizationContact", objorganizationContact));
        }
        public async Task RemoveContactAsync(long organizationId, long contactId)
        {
            OrganizationContact organizationContact = await _organizationContactRepository.GetOrganizationContactByIdsAsync(contactId, organizationId);

            if (organizationContact == null)
            {
                throw new Exception("try to remove a connection, while there is none");
            }

            await _organizationContactRepository.DeleteAsync(organizationContact);
        }
示例#4
0
        public static async Task <Organization> UpdateOrganizationContact(this Organization organization, IPrimaryContactModel contactModel, AllReadyContext _context)
        {
            if (organization.OrganizationContacts == null)
            {
                organization.OrganizationContacts = new List <OrganizationContact>();
            }

            var     primaryCampaignContact = organization.OrganizationContacts.SingleOrDefault(tc => tc.ContactType == (int)ContactTypes.Primary);
            var     contactId = primaryCampaignContact?.ContactId;
            Contact primaryContact;

            var contactInfo = string.Concat(contactModel.PrimaryContactEmail?.Trim() + contactModel.PrimaryContactFirstName?.Trim(), contactModel.PrimaryContactLastName?.Trim(), contactModel.PrimaryContactPhoneNumber?.Trim());

            if (contactId == null)
            {
                primaryContact = new Contact();
            }
            else
            {
                primaryContact = await _context.Contacts.SingleAsync(c => c.Id == contactId).ConfigureAwait(false);
            }

            if (string.IsNullOrWhiteSpace(contactInfo) && primaryCampaignContact != null)
            {
                //Delete
                _context.OrganizationContacts.Remove(primaryCampaignContact);
                _context.Remove(primaryCampaignContact);//Not Needed?
                _context.Remove(primaryCampaignContact.Contact);
            }
            else
            {
                primaryContact.Email       = contactModel.PrimaryContactEmail;
                primaryContact.FirstName   = contactModel.PrimaryContactFirstName;
                primaryContact.LastName    = contactModel.PrimaryContactLastName;
                primaryContact.PhoneNumber = contactModel.PrimaryContactPhoneNumber;
                _context.AddOrUpdate(primaryContact);

                if (primaryCampaignContact == null)
                {
                    primaryCampaignContact = new OrganizationContact
                    {
                        Contact      = primaryContact,
                        Organization = organization,
                        ContactType  = (int)ContactTypes.Primary
                    };
                    organization.OrganizationContacts.Add(primaryCampaignContact);
                    _context.AddOrUpdate(primaryCampaignContact);
                }
            }

            return(organization);
        }
        protected override void LoadTestData()
        {
            var organization = new Organization
            {
                Id       = 1,
                Name     = "Org 1",
                WebUrl   = "http://www.org1.org",
                LogoUrl  = "http://www.org1Logo.org",
                Location = new Location {
                    Id = 1, Country = "USA"
                },
                Campaigns            = new List <Campaign>(),
                Users                = new List <ApplicationUser>(),
                OrganizationContacts = new List <OrganizationContact>()
            };
            var campaign = new Campaign
            {
                Id   = 1,
                Name = "Campaign 1",
                ManagingOrganizationId = 1
            };
            var user = new ApplicationUser
            {
                Id    = Guid.NewGuid().ToString(),
                Email = "*****@*****.**"
            };
            var organizationContact = new OrganizationContact
            {
                OrganizationId = 1,
                ContactType    = (int)ContactTypes.Primary,
                Contact        = new Contact
                {
                    Id          = 1,
                    Email       = "*****@*****.**",
                    FirstName   = "firstName",
                    LastName    = "lastName",
                    PhoneNumber = "123"
                }
            };

            Context.Organizations.Add(organization);
            Context.Campaigns.Add(campaign);
            Context.Users.Add(user);
            Context.OrganizationContacts.Add(organizationContact);
            Context.SaveChanges();
        }
        public ActionResult ContactUs()
        {
            OrganizationContact _organizationViewModel = new OrganizationContact();
            var getOrganizationContacts = _clientService.GetSingleOrgContactByOrgID((HCRGUser != null ? HCRGUser.OrganizationID : (Convert.ToInt32(_encryptionService.DecryptString2(System.Configuration.ConfigurationManager.AppSettings["OrganizationID"])))));

            if (getOrganizationContacts != null)
            {
                _organizationViewModel = Mapper.Map <OrganizationContact>(getOrganizationContacts);
                var    Pvalue       = getOrganizationContacts.Phone;
                string _phoneFormat = MaskFormat(Pvalue.ToString());
                var    Fvalue       = getOrganizationContacts.Fax;
                string _faxFormat   = MaskFormat(Fvalue.ToString());
                _organizationViewModel.Fax   = _faxFormat;
                _organizationViewModel.Phone = _phoneFormat;
            }
            return(View(_organizationViewModel));
        }
示例#7
0
        public int CreateNewBusiness(string organizationName, string headquarters, OrganizationOrigin origin)
        {
            int result = 0;

            var org = Repository.Organizations.Create(organizationName, headquarters, origin);

            OrganizationContact orgContact = new OrganizationContact();

            Contact contact = Repository.DataModel.Contacts.SingleOrDefault(p => p.AccountID == CurrentAccount.ID);

            orgContact.Organization = org;
            orgContact.Contact      = contact;
            Repository.OrganizationContacts.Save(orgContact);

            Repository.OrganizationContactPermissionGroups.Update(orgContact, "14");               //OrgAdmin

            Services.Events.CreateOrganizationAdded(org, contact, CurrentAccount);

            CERSSecurityManager.ReloadCurrentUserRoles();

            result = org.ID;
            return(result);
        }
示例#8
0
 public ActionResult OrganizationContact(OrganizationContact _Contact)
 {
     _Contact.Phone = _Contact.Phone.Replace("(", String.Empty).Replace(")", String.Empty).Replace(" ", String.Empty).Replace("-", String.Empty);
     if (_Contact.Fax != null)
     {
         _Contact.Fax = _Contact.Fax.Replace("(", String.Empty).Replace(")", String.Empty).Replace(" ", String.Empty).Replace("-", String.Empty);
     }
     else
     {
         _Contact.Fax = null;
     }
     if (_Contact.EncryptedOrganizationContactID == null)
     {
         _Contact.OrganizationID        = HCRGCLIENT.OrganizationID;
         _Contact.OrganizationContactID = _clientService.AddOrganizationContact(Mapper.Map <NEPService.ClientService.OrganizationContact>(_Contact));
         return(Json(GlobalConst.Message.AddSucessfully, GlobalConst.Message.text_html));
     }
     else
     {
         _Contact.OrganizationContactID = Convert.ToInt32(DecryptString(_Contact.EncryptedOrganizationContactID));
         _Contact.OrganizationContactID = _clientService.UpdateOrganizationContact(Mapper.Map <NEPService.ClientService.OrganizationContact>(_Contact));
         return(Json(GlobalConst.Message.UpdateSucessfully, GlobalConst.Message.text_html));
     }
 }
示例#9
0
        public async Task <int> Handle(EditOrganizationCommand message)
        {
            var org = await _context.Organizations
                      .Include(l => l.Location)
                      .Include(tc => tc.OrganizationContacts)
                      .SingleOrDefaultAsync(t => t.Id == message.Organization.Id) ?? _context.Add(new Organization()).Entity;

            org.Name    = message.Organization.Name;
            org.LogoUrl = message.Organization.LogoUrl;
            org.WebUrl  = message.Organization.WebUrl;

            org.DescriptionHtml = message.Organization.Description;
            org.Summary         = message.Organization.Summary;

            if (org.OrganizationContacts == null)
            {
                org.OrganizationContacts = new List <OrganizationContact>();
            }

            var     primaryCampaignContact = org.OrganizationContacts.SingleOrDefault(tc => tc.ContactType == (int)ContactTypes.Primary);
            var     contactId = primaryCampaignContact?.ContactId;
            Contact primaryContact;

            var contactInfo = string.Concat(message.Organization.PrimaryContactEmail?.Trim() + message.Organization.PrimaryContactFirstName?.Trim(), message.Organization.PrimaryContactLastName?.Trim(), message.Organization.PrimaryContactPhoneNumber?.Trim());

            if (contactId == null)
            {
                primaryContact = new Contact();
                _context.Contacts.Add(primaryContact);
            }
            else
            {
                primaryContact = await _context.Contacts.SingleAsync(c => c.Id == contactId);
            }

            if (string.IsNullOrWhiteSpace(contactInfo) && primaryCampaignContact != null)
            {
                //Delete
                _context.OrganizationContacts.Remove(primaryCampaignContact);
                _context.Remove(primaryCampaignContact.Contact);
            }
            else
            {
                primaryContact.Email       = message.Organization.PrimaryContactEmail;
                primaryContact.FirstName   = message.Organization.PrimaryContactFirstName;
                primaryContact.LastName    = message.Organization.PrimaryContactLastName;
                primaryContact.PhoneNumber = message.Organization.PrimaryContactPhoneNumber;

                if (primaryCampaignContact == null)
                {
                    primaryCampaignContact = new OrganizationContact
                    {
                        Contact      = primaryContact,
                        Organization = org,
                        ContactType  = (int)ContactTypes.Primary
                    };
                    org.OrganizationContacts.Add(primaryCampaignContact);
                }
            }
            org.Location = org.Location.UpdateModel(message.Organization.Location);

            org.PrivacyPolicy    = message.Organization.PrivacyPolicy;
            org.PrivacyPolicyUrl = message.Organization.PrivacyPolicyUrl;

            await _context.SaveChangesAsync();

            return(org.Id);
        }