private Feed ToFeed(Contact contact)
        {
            var item = string.Empty;

            if (contact is Person)
            {
                item = "person";
            }
            else if (contact is Company)
            {
                item = "company";
            }

            var itemUrl = "/products/crm/?id=" + contact.ID + "#profile";

            return(new Feed(contact.CreateBy, contact.CreateOn)
            {
                Item = item,
                ItemId = contact.ID.ToString(CultureInfo.InvariantCulture),
                ItemUrl = CommonLinkUtility.ToAbsolute(itemUrl),
                Product = Product,
                Module = Name,
                Title = contact.GetTitle(),
                Description = Helper.GetHtmlDescription(HttpUtility.HtmlEncode(contact.About)),
                Keywords = string.Format("{0}", contact.GetTitle()),
                HasPreview = false,
                CanComment = false,
                GroupId = GetGroupId(item, contact.CreateBy)
            });
        }
Пример #2
0
        public static ContactBaseWrapper ToContactBaseWrapperQuick(Contact contact)
        {
            var result = new ContactBaseWrapper(contact.ID);

            result.DisplayName = contact.GetTitle();
            result.IsPrivate   = CRMSecurity.IsPrivate(contact);
            result.IsShared    = contact.ShareType == ShareType.ReadWrite || contact.ShareType == ShareType.Read;
            result.ShareType   = contact.ShareType;

            if (result.IsPrivate)
            {
                result.AccessList = CRMSecurity.GetAccessSubjectTo(contact)
                                    .Select(item => EmployeeWraper.Get(item.Key));
            }
            result.Currency = !String.IsNullOrEmpty(contact.Currency) ?
                              new CurrencyInfoWrapper(CurrencyProvider.Get(contact.Currency)) :
                              null;

            result.SmallFotoUrl  = String.Format("{0}HttpHandlers/filehandler.ashx?action=contactphotoulr&cid={1}&isc={2}&ps=1", PathProvider.BaseAbsolutePath, contact.ID, contact is Company);
            result.MediumFotoUrl = String.Format("{0}HttpHandlers/filehandler.ashx?action=contactphotoulr&cid={1}&isc={2}&ps=2", PathProvider.BaseAbsolutePath, contact.ID, contact is Company);
            result.IsCompany     = contact is Company;
            result.CanEdit       = CRMSecurity.CanEdit(contact);
            //result.CanDelete = CRMSecurity.CanDelete(contact);

            return(result);
        }
Пример #3
0
        public override void UpdateContact(Contact contact)
        {
            if (contact != null && contact.ID > 0)
                ResetCache(contact.ID);

            base.UpdateContact(contact);
        }
Пример #4
0
 protected ContactWrapper(Contact contact)
     : base(contact)
 {
     CreateBy = EmployeeWraper.Get(contact.CreateBy);
     Created  = (ApiDateTime)contact.CreateOn;
     About    = contact.About;
     Industry = contact.Industry;
 }
Пример #5
0
        private ContactBaseWrapper ToContactBaseWrapper(Contact contact)
        {
            if (contact == null)
            {
                return(null);
            }

            return(new ContactBaseWrapper(contact));
        }
Пример #6
0
        public override int SaveContact(Contact contact)
        {
            if (contact != null)
            {
                ResetCache(contact.ID);
            }

            return base.SaveContact(contact);

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            MobileVer = MobileDetector.IsMobile;

            TargetCompanyIfPerson = TargetContact is Person && ((Person)TargetContact).CompanyID != 0 ?
                Global.DaoFactory.GetContactDao().GetByID(((Person)TargetContact).CompanyID) :
                null;

            RegisterClientScriptHelper.DataContactFullCardView(Page, TargetContact);

            ExecHistoryView();
            RegisterScript();
        }
Пример #8
0
 public static void Contact(Contact contact, String actionText, int actionType, int businessValue)
 {
     var type = (int)EntityType.Contact;
     if(contact is Company)
         type = (int)EntityType.Company;
     
     UserActivityPublisher.Publish<TimeLinePublisher>(new TimeLineUserActivity(actionText, actionType, businessValue)
     {
         ContentID = contact.ID.ToString(),
         Title = contact.GetTitle(),
         SecurityId = String.Format(SecurityDataPattern, type, contact.SecurityId),
         URL = String.Concat(VirtualPathUtility.ToAbsolute(PathProvider.BaseVirtualPath + "default.aspx"), String.Format("?id={0}", contact.ID))
     });
 }
Пример #9
0
        public ContactBaseWrapper(Contact contact)
            : base(contact.ID)
        {
            DisplayName = contact.GetTitle();
            IsPrivate   = CRMSecurity.IsPrivate(contact);

            if (IsPrivate)
            {
                AccessList = CRMSecurity.GetAccessSubjectTo(contact)
                             .Select(item => EmployeeWraper.Get(item.Key));
            }

            SmallFotoUrl = ContactPhotoManager.GetSmallSizePhoto(contact.ID, contact is Company);
            IsCompany    = contact is Company;
            CanEdit      = CRMSecurity.CanEdit(contact);
        }
Пример #10
0
        private void SetAccessToContact(
            Contact contact,
            bool isPrivate,
            IEnumerable <Guid> accessList)
        {
            var accessListLocal = accessList.ToList();

            if (isPrivate && accessListLocal.Count > 0)
            {
                CRMSecurity.SetAccessTo(contact, accessListLocal);
            }
            else
            {
                CRMSecurity.MakePublic(contact);
            }
        }
Пример #11
0
        private string GetContactActivityPage(UserActivityView ctrlUserActivity, Contact contact, int messageCount)
        {
            var page = new Page();
            var form = new HtmlForm { EnableViewState = false };

            ctrlUserActivity = (UserActivityView)page.LoadControl(PathProvider.GetFileStaticRelativePath("SocialMedia/UserActivityView.ascx"));
            InitTwitter(ctrlUserActivity, contact);
            if (ctrlUserActivity.TwitterInformation.UserAccounts.Count == 0)
            {
                page.Controls.Add(new EmptyScreenControl
                {
                    ImgSrc = WebImageSupplier.GetAbsoluteWebPath("empty_screen_twitter.png", ProductEntryPoint.ID),
                    Header = CRMSocialMediaResource.EmptyContentTwitterAccountsHeader,
                    Describe = CRMSocialMediaResource.EmptyContentTwitterAccountsDescribe,
                    ButtonHTML = String.Format(@"<a class='link underline blue plus' href='javascript:void(0);'
                                                    onclick='ASC.CRM.SocialMedia.FindTwitterProfiles(jq(this),""{0}"", 1, 9);'>{1}</a>",
                                               contact is Company ? "company" : "people",
                                               CRMSocialMediaResource.LinkTwitterAccount)
                });

                return RenderPage(page);
            }

            ctrlUserActivity.MessageCount = messageCount;
            form.Controls.Add(ctrlUserActivity);
            page.Controls.Add(form);

            var executedPage = RenderPage(page);

            if (ctrlUserActivity.LoadedMessageCount == 0 && ctrlUserActivity.LastException == null)
            {
                page = new Page();

                //TODO
                page.Controls.Add(new EmptyScreenControl
                {

                    Header = CRMCommonResource.NoLoadedMessages,

                });
                executedPage = RenderPage(page);
            }

            return executedPage;
        }
Пример #12
0
        public ContactBaseWrapper(Contact contact)
            : base(contact.ID)
        {
            DisplayName = contact.GetTitle();
            IsPrivate   = CRMSecurity.IsPrivate(contact);
            IsShared    = contact.IsShared;

            if (IsPrivate)
            {
                AccessList = CRMSecurity.GetAccessSubjectTo(contact)
                             .Select(item => EmployeeWraper.Get(item.Key));
            }


            SmallFotoUrl  = String.Format("{0}HttpHandlers/filehandler.ashx?action=contactphotoulr&cid={1}&isc={2}&ps=1", PathProvider.BaseAbsolutePath, contact.ID, contact is Company).ToLower();
            MediumFotoUrl = String.Format("{0}HttpHandlers/filehandler.ashx?action=contactphotoulr&cid={1}&isc={2}&ps=2", PathProvider.BaseAbsolutePath, contact.ID, contact is Company).ToLower();
            IsCompany     = contact is Company;
            CanEdit       = CRMSecurity.CanEdit(contact);
        }
        public ContactBaseWrapper(Contact contact)
            : base(contact.ID)
        {
            DisplayName = contact.GetTitle();
            IsPrivate   = CRMSecurity.IsPrivate(contact);
            IsShared    = contact.ShareType == ShareType.ReadWrite || contact.ShareType == ShareType.Read;
            ShareType   = contact.ShareType;

            if (IsPrivate)
            {
                AccessList = CRMSecurity.GetAccessSubjectTo(contact)
                             .Select(item => EmployeeWraper.Get(item.Key));
            }
            Currency = !String.IsNullOrEmpty(contact.Currency) ?
                       new CurrencyInfoWrapper(CurrencyProvider.Get(contact.Currency)) :
                       null;

            SmallFotoUrl  = String.Format("{0}HttpHandlers/filehandler.ashx?action=contactphotoulr&cid={1}&isc={2}&ps=1", PathProvider.BaseAbsolutePath, contact.ID, contact is Company).ToLower();
            MediumFotoUrl = String.Format("{0}HttpHandlers/filehandler.ashx?action=contactphotoulr&cid={1}&isc={2}&ps=2", PathProvider.BaseAbsolutePath, contact.ID, contact is Company).ToLower();
            IsCompany     = contact is Company;
            CanEdit       = CRMSecurity.CanEdit(contact);
            CanDelete     = CRMSecurity.CanDelete(contact);
        }
Пример #14
0
        private void InitTwitter(UserActivityView ctrlUserActivity, Contact contact)
        {
            ctrlUserActivity.TwitterInformation = new UserActivityView.TwitterInfo();

            var twitterAccounts = Global.DaoFactory.GetContactInfoDao().GetList(contact.ID, ContactInfoType.Twitter, null, null);

            if (twitterAccounts.Count == 0)
                return;


            foreach (var twitterAccount in twitterAccounts)
                ctrlUserActivity.TwitterInformation.UserAccounts.Add(new UserActivityView.UserAccountInfo { ScreenName = twitterAccount.Data });

            ctrlUserActivity.TwitterInformation.ApiInfo = TwitterApiHelper.GetTwitterApiInfoForCurrentUser();
            ctrlUserActivity.SelectedSocialNetworks.Add(SocialNetworks.Twitter);
        }
Пример #15
0
 public static bool IsPrivate(Contact contact)
 {
     return !CanAccessTo(contact);
 }
Пример #16
0
        private ContactWrapper ToContactWrapper(Contact contact)
        {
            ContactWrapper result;

            if (contact is Person)
            {
                var people = (Person)contact;

                var peopleWrapper = new PersonWrapper(people);

                if (people.CompanyID > 0)
                {
                    peopleWrapper.Company = ToContactBaseWrapper(DaoFactory.GetContactDao().GetByID(people.CompanyID));
                }

                result = peopleWrapper;
            }
            else if (contact is Company)
            {
                result = new CompanyWrapper((Company)contact);
            }
            else
            {
                throw new ArgumentException();
            }

            if (contact.StatusID > 0)
            {
                result.ContactType = GetContactTypeByID(contact.StatusID);
            }

            result.TaskCount     = DaoFactory.GetTaskDao().GetTasksCount(contact.ID);
            result.HaveLateTasks = DaoFactory.GetTaskDao().HaveLateTask(contact.ID);

            var contactInfos = new List <ContactInfoWrapper>();
            var addresses    = new List <Address>();

            var data = DaoFactory.GetContactInfoDao().GetList(contact.ID, null, null, null);

            foreach (var contactInfo in data)
            {
                if (contactInfo.InfoType == ContactInfoType.Address)
                {
                    addresses.Add(new Address(contactInfo));
                }
                else
                {
                    contactInfos.Add(new ContactInfoWrapper(contactInfo));
                }
            }

            result.Addresses  = addresses;
            result.CommonData = contactInfos;

            if (contact is Person)
            {
                result.CustomFields = DaoFactory.GetCustomFieldDao().GetEnityFields(EntityType.Person, contact.ID, false).ConvertAll(item => new CustomFieldWrapper(item)).ToSmartList();
            }
            else
            {
                result.CustomFields = DaoFactory.GetCustomFieldDao().GetEnityFields(EntityType.Company, contact.ID, false).ConvertAll(item => new CustomFieldWrapper(item)).ToSmartList();
            }

            return(result);
        }
Пример #17
0
        private ContactWrapper ToContactWrapper(Contact contact)
        {
            ContactWrapper result;

            var person = contact as Person;
            if (person != null)
            {
                var peopleWrapper = new PersonWrapper(person);
                if (person.CompanyID > 0)
                {
                    peopleWrapper.Company = ToContactBaseWrapper(DaoFactory.GetContactDao().GetByID(person.CompanyID));
                }

                result = peopleWrapper;
            }
            else
            {
                var company = contact as Company;
                if (company != null)
                {
                    result = new CompanyWrapper(company);
                    ((CompanyWrapper)result).PersonsCount = DaoFactory.GetContactDao().GetMembersCount(result.ID);
                }
                else throw new ArgumentException();
            }

            if (contact.StatusID > 0)
            {
                var listItem = DaoFactory.GetListItemDao().GetByID(contact.StatusID);
                if (listItem == null) throw new ItemNotFoundException();

                result.ContactStatus = new ContactStatusBaseWrapper(listItem);
            }

            result.TaskCount = DaoFactory.GetTaskDao().GetTasksCount(contact.ID);
            result.HaveLateTasks = DaoFactory.GetTaskDao().HaveLateTask(contact.ID);

            var contactInfos = new List<ContactInfoWrapper>();
            var addresses = new List<Address>();

            var data = DaoFactory.GetContactInfoDao().GetList(contact.ID, null, null, null);

            foreach (var contactInfo in data)
            {
                if (contactInfo.InfoType == ContactInfoType.Address)
                {
                    addresses.Add(new Address(contactInfo));
                }
                else
                {
                    contactInfos.Add(new ContactInfoWrapper(contactInfo));
                }
            }

            result.Addresses = addresses;
            result.CommonData = contactInfos;

            if (contact is Person)
            {
                result.CustomFields = DaoFactory.GetCustomFieldDao()
                                                .GetEnityFields(EntityType.Person, contact.ID, false)
                                                .ConvertAll(item => new CustomFieldBaseWrapper(item)).ToSmartList();
            }
            else
            {
                result.CustomFields = DaoFactory.GetCustomFieldDao()
                                                .GetEnityFields(EntityType.Company, contact.ID, false)
                                                .ConvertAll(item => new CustomFieldBaseWrapper(item)).ToSmartList();
            }

            return result;
        }
Пример #18
0
 public static void SetAccessTo(Contact contact, List<Guid> subjectID)
 {
     SetAccessTo((ISecurityObjectId)contact, subjectID);
 }
Пример #19
0
 public static void MakePublic(Contact contact)
 {
     MakePublic((ISecurityObjectId)contact);
 }
Пример #20
0
 public static List<Guid> GetAccessSubjectGuidsTo(Contact contact)
 {
     return GetAccessSubjectGuidsTo((ISecurityObjectId)contact);
 }
Пример #21
0
        private Feed ToFeed(Contact contact)
        {
            var item = string.Empty;
            if (contact is Person)
            {
                item = "person";
            }
            else if (contact is Company)
            {
                item = "company";
            }

            var itemUrl = "/products/crm/?id=" + contact.ID + "#profile";
            return new Feed(contact.CreateBy, contact.CreateOn)
                {
                    Item = item,
                    ItemId = contact.ID.ToString(CultureInfo.InvariantCulture),
                    ItemUrl = CommonLinkUtility.ToAbsolute(itemUrl),
                    Product = Product,
                    Module = Name,
                    Title = contact.GetTitle(),
                    Description = Helper.GetHtmlDescription(HttpUtility.HtmlEncode(contact.About)),
                    Keywords = string.Format("{0}", contact.GetTitle()),
                    HasPreview = false,
                    CanComment = false,
                    GroupId = string.Format("{0}_{1}", item, contact.ID)
                };
        }
Пример #22
0
 public ContactBaseWithEmailWrapper(Contact contact)
     : base(contact)
 {
 }
Пример #23
0
        public virtual int SaveContact(Contact contact)
        {
            // Delete relative  keys
            _cache.Insert(_contactCacheKey, String.Empty);

            String firstName;
            String lastName;
            bool isCompany;
            String companyName;
            String title;
            int companyID;

            var displayName = String.Empty;

            if (contact is Company)
            {
                firstName = String.Empty;
                lastName = String.Empty;
                title = String.Empty;
                companyName = ((Company)contact).CompanyName.Trim();
                isCompany = true;
                companyID = 0;
                displayName = companyName;

                if (String.IsNullOrEmpty(companyName))
                    throw new ArgumentException();

            }
            else
            {
                var people = (Person)contact;

                firstName = people.FirstName.Trim();
                lastName = people.LastName.Trim();
                title = people.JobTitle;
                companyName = String.Empty;
                isCompany = false;
                companyID = people.CompanyID;

                displayName = String.Concat(firstName, _displayNameSeparator, lastName);


                if (String.IsNullOrEmpty(firstName) || String.IsNullOrEmpty(lastName))
                    throw new ArgumentException();

            }

            if (!String.IsNullOrEmpty(title))
                title = title.Trim();

            if (!String.IsNullOrEmpty(contact.About))
                contact.About = contact.About.Trim();

            if (!String.IsNullOrEmpty(contact.Industry))
                contact.Industry = contact.Industry.Trim();

            var contactID = DbManager.ExecuteScalar<int>(
                Insert("crm_contact")
                    .InColumnValue("id", 0)
                    .InColumnValue("first_name", firstName)
                    .InColumnValue("last_name", lastName)
                    .InColumnValue("company_name", companyName)
                    .InColumnValue("title", title)
                    .InColumnValue("notes", contact.About)
                    .InColumnValue("is_company", isCompany)
                    .InColumnValue("industry", contact.Industry)
                    .InColumnValue("status_id", contact.StatusID)
                    .InColumnValue("company_id", companyID)
                    .InColumnValue("create_by", ASC.Core.SecurityContext.CurrentAccount.ID)
                    .InColumnValue("create_on", TenantUtil.DateTimeToUtc(TenantUtil.DateTimeNow()))
                    .InColumnValue("last_modifed_on", TenantUtil.DateTimeToUtc(TenantUtil.DateTimeNow()))
                    .InColumnValue("last_modifed_by", ASC.Core.SecurityContext.CurrentAccount.ID)
                    .InColumnValue("display_name", displayName)
                    .Identity(1, 0, true));

            contact.ID = contactID;

            if (companyID > 0)
                AddMember(contactID, companyID);

            return contactID;

        }
Пример #24
0
        private void MergeContactInfo(Contact fromContact, Contact toContact)
        {

            if ((toContact is Person) && (fromContact is Person))
            {
                var fromPeople = (Person)fromContact;
                var toPeople = (Person)toContact;

                if (toPeople.CompanyID == 0)
                    toPeople.CompanyID = fromPeople.CompanyID;

                if (String.IsNullOrEmpty(toPeople.JobTitle))
                    toPeople.JobTitle = fromPeople.JobTitle;
            }

            if (String.IsNullOrEmpty(toContact.Industry))
                toContact.Industry = fromContact.Industry;

            if (toContact.StatusID == 0)
                toContact.StatusID = fromContact.StatusID;

            if (String.IsNullOrEmpty(toContact.About))
                toContact.About = fromContact.About;

            UpdateContact(toContact);

        }
Пример #25
0
 public static bool CanAccessTo(Contact contact)
 {
     return contact.IsShared || IsAdmin || GetAccessSubjectTo(contact).ContainsKey(SecurityContext.CurrentAccount.ID);
 }
Пример #26
0
        public virtual void UpdateContact(Contact contact)
        {
            CRMSecurity.DemandAccessTo(contact);

            String firstName;
            String lastName;
            String companyName;
            String title;
            int companyID;

            var displayName = String.Empty;

            if (contact is Company)
            {
                firstName = String.Empty;
                lastName = String.Empty;
                title = String.Empty;
                companyName = ((Company)contact).CompanyName.Trim();
                companyID = 0;
                displayName = companyName;

                if (String.IsNullOrEmpty(companyName))
                    throw new ArgumentException();

            }
            else
            {
                var people = (Person)contact;

                firstName = people.FirstName.Trim();
                lastName = people.LastName.Trim();
                title = people.JobTitle;
                companyName = String.Empty;
                companyID = people.CompanyID;

                displayName = String.Concat(firstName, _displayNameSeparator, lastName);

                RemoveMember(people.ID);

                if (companyID > 0)
                {
                    AddMember(people.ID, companyID);

                    contact.StatusID = 0;
                }

                if (String.IsNullOrEmpty(firstName) || String.IsNullOrEmpty(lastName))
                    throw new ArgumentException();

            }

            if (!String.IsNullOrEmpty(title))
                title = title.Trim();

            if (!String.IsNullOrEmpty(contact.About))
                contact.About = contact.About.Trim();

            if (!String.IsNullOrEmpty(contact.Industry))
                contact.Industry = contact.Industry.Trim();


            DbManager.ExecuteNonQuery(
                Update("crm_contact")
                    .Set("first_name", firstName)
                    .Set("last_name", lastName)
                    .Set("company_name", companyName)
                    .Set("title", title)
                    .Set("notes", contact.About)
                    .Set("industry", contact.Industry)
                    .Set("status_id", contact.StatusID)
                    .Set("company_id", companyID)
                    .Set("last_modifed_on", TenantUtil.DateTimeToUtc(TenantUtil.DateTimeNow()))
                    .Set("last_modifed_by", ASC.Core.SecurityContext.CurrentAccount.ID)
                    .Set("display_name", displayName)
                    .Where(Exp.Eq("id", contact.ID)));

            // Delete relative  keys
            _cache.Insert(_contactCacheKey, String.Empty);


        }
Пример #27
0
 public static void DemandAccessTo(Contact contact)
 {
     if (!CanAccessTo(contact)) throw CreateSecurityException();
 }
Пример #28
0
        private List<SocialMediaImageDescription> GetLinkedInImageDescriptionList(Contact contact, Tenant tenant)
        {
            CoreContext.TenantManager.SetCurrentTenant(tenant);

            var images = new List<SocialMediaImageDescription>();

            var linkedInAccounts = Global.DaoFactory.GetContactInfoDao().GetListData(contact.ID, ContactInfoType.LinkedIn);

            if (linkedInAccounts.Count == 0)
                return images;

            var provider = LinkedInApiHelper.GetLinkedInDataProviderForCurrentUser();

            if (provider == null)
                return images;

            //images.AddRange(from linkedInAccount in linkedInAccounts
            //                let imageUrl = provider.GetUrlOfUserImage(account.UserID)
            //                select new SocialMediaImageDescription
            //                           {
            //                               Identity = account.UserID, ImageUrl = imageUrl, SocialNetwork = ASC.SocialMedia.Core.SocialNetworks.LinkedIn
            //                           });

            return images;
        }
Пример #29
0
 public static Dictionary<Guid, string> GetAccessSubjectTo(Contact contact)
 {
     return GetAccessSubjectTo((ISecurityObjectId)contact);
 }
Пример #30
0
        private List<SocialMediaImageDescription> GetFacebookImageDescriptionList(Contact contact, Tenant tenant)
        {
            CoreContext.TenantManager.SetCurrentTenant(tenant);

            var images = new List<SocialMediaImageDescription>();

            var facebookAccounts = Global.DaoFactory.GetContactInfoDao().GetListData(contact.ID, ContactInfoType.Facebook);

            if (facebookAccounts.Count == 0)
                return images;

            var provider = new FacebookDataProvider(FacebookApiHelper.GetFacebookApiInfoForCurrentUser());

            images.AddRange(from facebookAccount in facebookAccounts
                            let imageUrl = provider.GetUrlOfUserImage(facebookAccount, FacebookDataProvider.ImageSize.Small)
                            where imageUrl != null
                            select new SocialMediaImageDescription
                                       {
                                           Identity = facebookAccount,
                                           ImageUrl = imageUrl,
                                           SocialNetwork = SocialNetworks.Facebook
                                       });

            return images;
        }
Пример #31
0
 private static ContactBaseWrapper ToContactBaseWrapper(Contact contact)
 {
     return contact == null ? null : new ContactBaseWrapper(contact);
 }
Пример #32
0
        public static void SendAutoReminderAboutTask(DateTime scheduleDate)
        {
            var execAlert = new List <int>();

            var defaultDao = new DaoFactory(Tenant.DEFAULT_TENANT, CRMConstants.StorageModule);

            foreach (var row in defaultDao.GetTaskDao()
                     .GetInfoForReminder(scheduleDate))
            {
                var tenantId      = Convert.ToInt32(row[0]);
                var taskId        = Convert.ToInt32(row[1]);
                var deadline      = Convert.ToDateTime(row[2]);
                var alertValue    = Convert.ToInt32(row[3]);
                var responsibleID = !string.IsNullOrEmpty(Convert.ToString(row[4])) ? new Guid(Convert.ToString(row[4])) : Guid.Empty;

                var deadlineReminderDate = deadline.AddMinutes(-alertValue);

                if (deadlineReminderDate.Subtract(scheduleDate).Minutes > 1)
                {
                    continue;
                }

                execAlert.Add(taskId);

                var tenant = CoreContext.TenantManager.GetTenant(tenantId);
                if (tenant == null ||
                    tenant.Status != TenantStatus.Active ||
                    TariffState.NotPaid <= CoreContext.PaymentManager.GetTariff(tenant.TenantId).State)
                {
                    continue;
                }

                try
                {
                    CoreContext.TenantManager.SetCurrentTenant(tenant);
                    SecurityContext.AuthenticateMe(ASC.Core.Configuration.Constants.CoreSystem);

                    var user = CoreContext.UserManager.GetUsers(responsibleID);

                    if (!(!Constants.LostUser.Equals(user) && user.Status == EmployeeStatus.Active))
                    {
                        continue;
                    }

                    SecurityContext.AuthenticateMe(user.ID);

                    Thread.CurrentThread.CurrentCulture   = user.GetCulture();
                    Thread.CurrentThread.CurrentUICulture = user.GetCulture();

                    var dao  = new DaoFactory(tenantId, CRMConstants.StorageModule);
                    var task = dao.GetTaskDao().GetByID(taskId);

                    if (task == null)
                    {
                        continue;
                    }

                    ASC.CRM.Core.Entities.Contact taskContact = null;
                    ASC.CRM.Core.Entities.Cases   taskCase    = null;
                    ASC.CRM.Core.Entities.Deal    taskDeal    = null;

                    if (task.ContactID > 0)
                    {
                        taskContact = dao.GetContactDao().GetByID(task.ContactID);
                    }

                    if (task.EntityID > 0)
                    {
                        switch (task.EntityType)
                        {
                        case EntityType.Case:
                            taskCase = dao.GetCasesDao().GetByID(task.EntityID);
                            break;

                        case EntityType.Opportunity:
                            taskDeal = dao.GetDealDao().GetByID(task.EntityID);
                            break;
                        }
                    }

                    var listItem = dao.GetListItemDao().GetByID(task.CategoryID);

                    NotifyClient.Instance.SendTaskReminder(task, listItem != null ? listItem.Title : string.Empty, taskContact, taskCase, taskDeal);
                }
                catch (Exception ex)
                {
                    LogManager.GetLogger("ASC.CRM.Tasks").Error("SendAutoReminderAboutTask, tenant: " + tenant.TenantDomain, ex);
                }
            }

            defaultDao.GetTaskDao().ExecAlert(execAlert);
        }
Пример #33
0
 public static Dictionary<Guid, string> GetAccessSubjectTo(Contact contact, EmployeeStatus employeeStatus)
 {
     return GetAccessSubjectTo((ISecurityObjectId)contact, employeeStatus);
 }
Пример #34
0
 protected ContactWrapper(Contact contact)
     : base(contact)
 {
     CreateBy = EmployeeWraper.Get(contact.CreateBy);
     Created = (ApiDateTime)contact.CreateOn;
     About = contact.About;
     Industry = contact.Industry;
 }
Пример #35
0
        public void SendAutoReminderAboutTask(DateTime scheduleDate)
        {
            using var scope = _serviceProvider.CreateScope();

            var defaultDao      = scope.ServiceProvider.GetService <DaoFactory>();
            var tenantManager   = scope.ServiceProvider.GetService <TenantManager>();
            var userManager     = scope.ServiceProvider.GetService <UserManager>();
            var securityContext = scope.ServiceProvider.GetService <SecurityContext>();
            var paymentManager  = scope.ServiceProvider.GetService <PaymentManager>();
            var logger          = scope.ServiceProvider.GetService <IOptionsMonitor <ILog> >().Get("ASC.CRM");
            var coreSettings    = scope.ServiceProvider.GetService <CoreSettings>();

            var execAlert = new List <int>();

            foreach (var row in defaultDao.GetTaskDao()
                     .GetInfoForReminder(scheduleDate))
            {
                var tenantId      = Convert.ToInt32(row[0]);
                var taskId        = Convert.ToInt32(row[1]);
                var deadline      = Convert.ToDateTime(row[2]);
                var alertValue    = Convert.ToInt32(row[3]);
                var responsibleID = !string.IsNullOrEmpty(Convert.ToString(row[4]))
                    ? new Guid(Convert.ToString(row[4]))
                    : Guid.Empty;

                var deadlineReminderDate = deadline.AddMinutes(-alertValue);

                if (deadlineReminderDate.Subtract(scheduleDate).Minutes > 1)
                {
                    continue;
                }

                execAlert.Add(taskId);

                var tenant = tenantManager.GetTenant(tenantId);
                if (tenant == null ||
                    tenant.Status != TenantStatus.Active ||
                    TariffState.NotPaid <= paymentManager.GetTariff(tenant.TenantId).State)
                {
                    continue;
                }

                try
                {
                    tenantManager.SetCurrentTenant(tenant);
                    securityContext.AuthenticateMeWithoutCookie(ASC.Core.Configuration.Constants.CoreSystem);

                    var user = userManager.GetUsers(responsibleID);

                    if (!(!Constants.LostUser.Equals(user) && user.Status == EmployeeStatus.Active))
                    {
                        continue;
                    }

                    securityContext.AuthenticateMeWithoutCookie(user.ID);

                    Thread.CurrentThread.CurrentCulture   = user.GetCulture();
                    Thread.CurrentThread.CurrentUICulture = user.GetCulture();

                    var dao  = defaultDao;
                    var task = dao.GetTaskDao().GetByID(taskId);

                    if (task == null)
                    {
                        continue;
                    }

                    ASC.CRM.Core.Entities.Contact taskContact = null;
                    ASC.CRM.Core.Entities.Cases   taskCase    = null;
                    ASC.CRM.Core.Entities.Deal    taskDeal    = null;

                    if (task.ContactID > 0)
                    {
                        taskContact = dao.GetContactDao().GetByID(task.ContactID);
                    }

                    if (task.EntityID > 0)
                    {
                        switch (task.EntityType)
                        {
                        case EntityType.Case:
                            taskCase = dao.GetCasesDao().GetByID(task.EntityID);
                            break;

                        case EntityType.Opportunity:
                            taskDeal = dao.GetDealDao().GetByID(task.EntityID);
                            break;
                        }
                    }

                    var listItem = dao.GetListItemDao().GetByID(task.CategoryID);

                    SendTaskReminder(task,
                                     listItem != null ? listItem.Title : string.Empty,
                                     taskContact, taskCase, taskDeal);
                }
                catch (Exception ex)
                {
                    logger.Error("SendAutoReminderAboutTask, tenant: " + tenant.GetTenantDomain(coreSettings), ex);
                }
            }

            defaultDao.GetTaskDao().ExecAlert(execAlert);
        }
Пример #36
0
        public ContactBaseWrapper(Contact contact)
            : base(contact.ID)
        {
            DisplayName = contact.GetTitle();
            IsPrivate = CRMSecurity.IsPrivate(contact);
            IsShared = contact.ShareType == ShareType.ReadWrite || contact.ShareType == ShareType.Read;
            ShareType = contact.ShareType;

            if (IsPrivate)
            {
                AccessList = CRMSecurity.GetAccessSubjectTo(contact)
                                        .Select(item => EmployeeWraper.Get(item.Key));
            }
            Currency = !String.IsNullOrEmpty(contact.Currency) ?
                new CurrencyInfoWrapper(CurrencyProvider.Get(contact.Currency)) :
                null;

            SmallFotoUrl = String.Format("{0}HttpHandlers/filehandler.ashx?action=contactphotoulr&cid={1}&isc={2}&ps=1", PathProvider.BaseAbsolutePath, contact.ID, contact is Company).ToLower();
            MediumFotoUrl = String.Format("{0}HttpHandlers/filehandler.ashx?action=contactphotoulr&cid={1}&isc={2}&ps=2", PathProvider.BaseAbsolutePath, contact.ID, contact is Company).ToLower();
            IsCompany = contact is Company;
            CanEdit = CRMSecurity.CanEdit(contact);
            CanDelete = CRMSecurity.CanDelete(contact);
        }
Пример #37
0
 public ContactBaseWithEmailWrapper(Contact contact)
     : base(contact)
 {
 }
Пример #38
0
        private void SetAccessToContact(Contact contact, bool isShared, IEnumerable<Guid> managerList, bool isNotify)
        {
            var managerListLocal = managerList != null ? managerList.Distinct().ToList() : new List<Guid>();
            if (managerListLocal.Any())
            {
                if (isNotify)
                {
                    var notifyUsers = managerListLocal.Where(n => n != ASC.Core.SecurityContext.CurrentAccount.ID).ToArray();
                    if (contact is Person)
                        ASC.Web.CRM.Services.NotifyService.NotifyClient.Instance.SendAboutSetAccess(EntityType.Person, contact.ID, notifyUsers);
                    else
                        ASC.Web.CRM.Services.NotifyService.NotifyClient.Instance.SendAboutSetAccess(EntityType.Company, contact.ID, notifyUsers);

                }

                CRMSecurity.SetAccessTo(contact, managerListLocal);
            }
            else
            {
                CRMSecurity.MakePublic(contact);
            }

            DaoFactory.GetContactDao().MakePublic(contact.ID, isShared);
        }
Пример #39
0
 public ContactBaseWithPhoneWrapper(Contact contact)
     : base(contact)
 {
 }
Пример #40
0
 private static ContactBaseWrapper ToContactBaseWrapperQuick(Contact contact)
 {
     return contact == null ? null : ContactBaseWrapper.ToContactBaseWrapperQuick(contact);
 }
Пример #41
0
 public virtual int SaveContact(Contact contact)
 {
     using (var db = GetDb())
     {
         var result = SaveContact(contact, db);
         // Delete relative  keys
         _cache.Insert(_contactCacheKey, String.Empty);
         return result;
     }
 }
Пример #42
0
        private ContactBaseWithPhoneWrapper ToContactBaseWithPhoneWrapper(Contact contact)
        {
            if (contact == null) return null;

            var result = new ContactBaseWithPhoneWrapper(contact);
            var primaryPhone = DaoFactory.GetContactInfoDao().GetList(contact.ID, ContactInfoType.Phone, null, true);
            if (primaryPhone == null || primaryPhone.Count == 0)
            {
                result.Phone = null;
            }
            else
            {
                result.Phone = new ContactInfoWrapper(primaryPhone.FirstOrDefault());
            }
            return result;
        }
Пример #43
0
 public static bool CanEdit(Contact contact)
 {
     return IsAdmin || GetAccessSubjectTo(contact).ContainsKey(SecurityContext.CurrentAccount.ID);
 }