Beispiel #1
0
        public List <ContactInfo> GetList(int contactID, ContactInfoType?infoType, int?categoryID, bool?isPrimary)
        {
            var items = Query(CrmDbContext.ContactsInfo)
                        .AsNoTracking();

            if (contactID > 0)
            {
                items = items.Where(x => x.ContactId == contactID);
            }

            if (infoType.HasValue)
            {
                items = items.Where(x => x.Type == infoType.Value);
            }

            if (categoryID.HasValue)
            {
                items = items.Where(x => x.Category == categoryID.Value);
            }

            if (isPrimary.HasValue)
            {
                items = items.Where(x => x.IsPrimary == isPrimary.Value);
            }

            items = items.OrderBy(x => x.Type);

            return(_mapper.Map <List <DbContactInfo>, List <ContactInfo> >(items.ToList()));
        }
        public virtual List <ContactInfo> GetList(int contactID, ContactInfoType?infoType, int?categoryID, bool?isPrimary)
        {
            SqlQuery sqlQuery = GetSqlQuery(null);

            if (contactID > 0)
            {
                sqlQuery.Where(Exp.Eq("contact_id", contactID));
            }

            if (infoType.HasValue)
            {
                sqlQuery.Where(Exp.Eq("type", infoType.Value));
            }

            if (categoryID.HasValue)
            {
                sqlQuery.Where(Exp.Eq("category", categoryID.Value));
            }

            if (isPrimary.HasValue)
            {
                sqlQuery.Where(Exp.Eq("is_primary", isPrimary.Value));
            }

            sqlQuery.OrderBy("type", true);
            // sqlQuery.OrderBy("category", true);
            //  sqlQuery.OrderBy("is_primary", true);


            using (var db = GetDb())
            {
                return(db.ExecuteList(sqlQuery).ConvertAll(row => ToContactInfo(row)));
            }
        }
Beispiel #3
0
        public ContactInfoWrapper UpdateContactInfo(int id, int contactid, ContactInfoType?infoType, string data, bool?isPrimary, string category)
        {
            if (id <= 0 || string.IsNullOrEmpty(data) || contactid <= 0)
            {
                throw new ArgumentException();
            }

            var contact = DaoFactory.ContactDao.GetByID(contactid);

            if (contact == null || !CRMSecurity.CanEdit(contact))
            {
                throw new ItemNotFoundException();
            }

            var contactInfo = DaoFactory.ContactInfoDao.GetByID(id);

            if (infoType != null)
            {
                var categoryType = ContactInfo.GetCategory(infoType.Value);

                if (!string.IsNullOrEmpty(category) && Enum.IsDefined(categoryType, category))
                {
                    contactInfo.Category = (int)Enum.Parse(categoryType, category);
                }

                contactInfo.InfoType = infoType.Value;
            }

            contactInfo.ContactID = contactid;

            if (isPrimary != null)
            {
                contactInfo.IsPrimary = isPrimary.Value;
            }

            contactInfo.Data = data;

            if (contactInfo.InfoType == ContactInfoType.Address)
            {
                Address res;
                if (!Address.TryParse(contactInfo, out res))
                {
                    throw new ArgumentException();
                }
            }

            DaoFactory.ContactInfoDao.Update(contactInfo);

            var messageAction = contact is Company ? MessageAction.CompanyUpdatedPrincipalInfo : MessageAction.PersonUpdatedPrincipalInfo;

            MessageService.Send(Request, messageAction, MessageTarget.Create(contact.ID), contact.GetTitle());

            var contactInfoWrapper = ToContactInfoWrapper(contactInfo);

            return(contactInfoWrapper);
        }
 public FullFilterContactsExp(int tenant, string user, string searchTerm = null, int?type = null,
                              ContactInfoType?infoType = null, bool?isPrimary             = null, bool?orderAsc = true, int?startIndex = null,
                              int?limit = null)
     : base(tenant, user, orderAsc, startIndex, limit)
 {
     InfoType   = infoType;
     IsPrimary  = isPrimary;
     SearchTerm = searchTerm;
     Type       = type;
 }
Beispiel #5
0
        public ContactInfoWrapper UpdateContactInfo(int id, int contactid, ContactInfoType?infoType, string data, bool?isPrimary, string category)
        {
            if (id <= 0 || string.IsNullOrEmpty(data) || contactid <= 0)
            {
                throw new ArgumentException();
            }

            var contact = DaoFactory.GetContactDao().GetByID(contactid);

            if (contact == null || !CRMSecurity.CanEdit(contact))
            {
                throw new ItemNotFoundException();
            }

            var contactInfo = DaoFactory.GetContactInfoDao().GetByID(id);

            if (infoType != null)
            {
                var categoryType = ContactInfo.GetCategory(infoType.Value);

                if (!string.IsNullOrEmpty(category) && Enum.IsDefined(categoryType, category))
                {
                    contactInfo.Category = (int)Enum.Parse(categoryType, category);
                }

                contactInfo.InfoType = infoType.Value;
            }

            contactInfo.ContactID = contactid;

            if (isPrimary != null)
            {
                contactInfo.IsPrimary = isPrimary.Value;
            }

            contactInfo.Data = data;

            DaoFactory.GetContactInfoDao().Update(contactInfo);

            if (contactInfo.InfoType == ContactInfoType.Email)
            {
                var userIds = CRMSecurity.GetAccessSubjectTo(contact).Keys.ToList();
                var emails  = new[] { contactInfo.Data };
                DaoFactory.GetContactInfoDao().UpdateMailAggregator(emails, userIds);
            }

            var messageAction = contact is Company ? MessageAction.CompanyUpdatedPrincipalInfo : MessageAction.PersonUpdatedPrincipalInfo;

            MessageService.Send(_context, messageAction, contact.GetTitle());

            var contactInfoWrapper = ToContactInfoWrapper(contactInfo);

            return(contactInfoWrapper);
        }
Beispiel #6
0
        public ContactInfoWrapper UpdateContactInfo(
            int id,
            int contactid,
            ContactInfoType?infoType,
            String data,
            bool?isPrimary,
            String category)
        {
            if (id == 0 || String.IsNullOrEmpty(data) || contactid <= 0)
            {
                throw new ArgumentException();
            }

            var contactInfo = DaoFactory.GetContactInfoDao().GetByID(id);

            if (infoType != null)
            {
                var categoryType = ContactInfo.GetCategory(infoType.Value);

                if (!String.IsNullOrEmpty(category) && Enum.IsDefined(categoryType, category))
                {
                    contactInfo.Category = (int)Enum.ToObject(categoryType, category);
                }

                contactInfo.InfoType = infoType.Value;
            }

            contactInfo.ContactID = contactid;

            if (isPrimary != null)
            {
                contactInfo.IsPrimary = isPrimary.Value;
            }

            contactInfo.Data = data;

            DaoFactory.GetContactInfoDao().Update(contactInfo);

            if (contactInfo.InfoType == ContactInfoType.Email)
            {
                var contact = DaoFactory.GetContactDao().GetByID(contactInfo.ContactID);
                var userIds = CRMSecurity.GetAccessSubjectTo(contact).Keys.ToList();
                var emails  = new[] { contactInfo.Data };
                DaoFactory.GetContactInfoDao().UpdateMailAggregator(emails, userIds);
            }

            var contactInfoWrapper = ToContactInfoWrapper(contactInfo);

            return(contactInfoWrapper);
        }
        public ContactInfoWrapper UpdateContactInfo(
            int id,
            int contactid,
            ContactInfoType?infoType,
            String data,
            bool?isPrimary,
            String category)
        {
            if (id == 0 || String.IsNullOrEmpty(data) || contactid <= 0)
            {
                throw new ArgumentException();
            }

            var contactInfo = DaoFactory.GetContactInfoDao().GetByID(id);

            if (infoType != null)
            {
                var categoryType = ContactInfo.GetCategory(infoType.Value);

                if (!String.IsNullOrEmpty(category) && Enum.IsDefined(categoryType, category))
                {
                    contactInfo.Category = (int)Enum.ToObject(categoryType, category);
                }

                contactInfo.InfoType = infoType.Value;
            }

            contactInfo.ContactID = contactid;

            if (isPrimary != null)
            {
                contactInfo.IsPrimary = isPrimary.Value;
            }

            contactInfo.Data = data;

            DaoFactory.GetContactInfoDao().Update(contactInfo);

            var contactInfoWrapper = ToContactInfoWrapper(contactInfo);

            return(contactInfoWrapper);
        }