示例#1
0
        public void SaveContactTwitterRelation(ContactRelationTwitterSettings settings)
        {
            try
            {
                //Process authorization
                if (!ProcessAuthorization(HttpContext.Current))
                {
                    AccessDenied(HttpContext.Current);
                    return;
                }

                if (settings == null)
                {
                    throw new ArgumentNullException("Settings can not be null");
                }

                if (settings.RelateAccount == false && settings.RelateAvatar == false)
                {
                    return;
                }

                var contact = Global.DaoFactory.GetContactDao().GetByID(settings.ContactID);

                if (contact == null)
                {
                    throw new Exception("Specified contact not found");
                }

                if (settings.RelateAccount)
                {
                    var twitterAccounts = Global.DaoFactory.GetContactInfoDao().GetListData(contact.ID, ContactInfoType.Twitter);

                    if (!twitterAccounts.Contains(settings.TwitterScreenName))
                    {
                        Global.DaoFactory.GetContactInfoDao().Save(new ContactInfo
                        {
                            ContactID = contact.ID,
                            Category  = (int)ContactInfoBaseCategory.Other,
                            InfoType  = ContactInfoType.Twitter,
                            Data      = settings.TwitterScreenName
                        });
                    }
                }

                if (settings.RelateAvatar)
                {
                    SaveAvatar(contact.ID, settings.UserAvatarUrl);
                }
            }
            catch (Exception ex)
            {
                _logger.Error("ASC.Web.CRM.SocialMediaUI.SaveContactSocialMediaRelation error:", ex);
                throw new Exception(ASC.Web.UserControls.SocialMedia.Resources.SocialMediaResource.ErrorInternalServer);
            }
        }
        public void SaveContactTwitterRelation(ContactRelationTwitterSettings settings)
        {
            try
            {
                //Process authorization
                if (!ProcessAuthorization(HttpContext.Current))
                {
                    AccessDenied(HttpContext.Current);
                    return;
                }

                if (settings == null)
                    throw new ArgumentNullException("Settings can not be null");

                if (settings.RelateAccount == false && settings.RelateAvatar == false)
                    return;

                var contact = Global.DaoFactory.GetContactDao().GetByID(settings.ContactID);

                if (contact == null)
                    throw new Exception("Specified contact not found");

                if (settings.RelateAccount)
                {

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

                    if (!twitterAccounts.Contains(settings.TwitterScreenName))
                        Global.DaoFactory.GetContactInfoDao().Save(new ContactInfo
                                                                                  {
                                                                                      ContactID = contact.ID,
                                                                                      Category = (int)ContactInfoBaseCategory.Other,
                                                                                      InfoType = ContactInfoType.Twitter,
                                                                                      Data = settings.TwitterScreenName
                                                                                  });

                }

                if (settings.RelateAvatar)
                    SaveAvatar(contact.ID, settings.UserAvatarUrl);

            }
            catch (Exception ex)
            {
                _logger.Error("ASC.Web.CRM.SocialMediaUI.SaveContactSocialMediaRelation error:", ex);
                throw new Exception(ASC.Web.UserControls.SocialMedia.Resources.SocialMediaResource.ErrorInternalServer);
            }
        }