public FileWrapper DeleteCRMFile(int fileid)
        {
            if (fileid < 0)
            {
                throw new ArgumentException();
            }

            var file = FilesDaoFactory.GetFileDao().GetFile(fileid);

            if (file == null)
            {
                throw new ItemNotFoundException();
            }
            var result = new FileWrapper(file);

            var _eventsDao = DaoFactory.RelationshipEventDao;
            var eventIDs   = _eventsDao.RemoveFile(file);
            var events     = new List <RelationshipEvent>();

            eventIDs.ForEach(id => events.Add(_eventsDao.GetByID(id)));

            foreach (var evt in events)
            {
                DomainObject entityObj;
                var          entityTitle = evt.ContactID > 0
                                  ? GetEntityTitle(EntityType.Contact, evt.ContactID, false, out entityObj)
                                  : GetEntityTitle(evt.EntityType, evt.EntityID, false, out entityObj);
                var messageAction = GetFilesDetachAction(evt.EntityType, evt.ContactID);

                MessageService.Send(Request, messageAction, MessageTarget.Create(file.ID), entityTitle, file.Title);
            }

            return(result);
        }
Exemplo n.º 2
0
        public RelationshipEventWrapper AttachFiles(string entityType, int entityid, IEnumerable <int> fileids)
        {
            if (entityid <= 0 || fileids == null)
            {
                throw new ArgumentException();
            }

            var files = FilesDaoFactory.GetFileDao().GetFiles(fileids.Cast <object>().ToArray());

            var entityTypeObj = ToEntityType(entityType);
            var entityTitle   = GetEntityTitle(entityTypeObj, entityid, true);

            switch (entityTypeObj)
            {
            case EntityType.Contact:
                var relationshipEvent1 = DaoFactory.GetRelationshipEventDao().AttachFiles(entityid, EntityType.Any, 0, fileids.ToArray());
                var entity1            = DaoFactory.GetContactDao().GetByID(entityid);
                var messageAction      = entity1 is Company ? MessageAction.CompanyAttachedFiles : MessageAction.PersonAttachedFiles;
                MessageService.Send(Request, messageAction, MessageTarget.Create(entityid), entityTitle, files.Select(x => x.Title));
                return(ToRelationshipEventWrapper(relationshipEvent1));

            case EntityType.Opportunity:
                var relationshipEvent2 = DaoFactory.GetRelationshipEventDao().AttachFiles(0, entityTypeObj, entityid, fileids.ToArray());
                MessageService.Send(Request, MessageAction.OpportunityAttachedFiles, MessageTarget.Create(entityid), entityTitle, files.Select(x => x.Title));
                return(ToRelationshipEventWrapper(relationshipEvent2));

            case EntityType.Case:
                var relationshipEvent3 = DaoFactory.GetRelationshipEventDao().AttachFiles(0, entityTypeObj, entityid, fileids.ToArray());
                MessageService.Send(Request, MessageAction.CaseAttachedFiles, MessageTarget.Create(entityid), entityTitle, files.Select(x => x.Title));
                return(ToRelationshipEventWrapper(relationshipEvent3));

            default:
                throw new ArgumentException();
            }
        }
        public FileWrapper DeleteCRMFile(int fileid)
        {
            if (fileid < 0)
            {
                throw new ArgumentException();
            }

            var file = FilesDaoFactory.GetFileDao().GetFile(fileid);

            if (file == null)
            {
                throw new ItemNotFoundException();
            }
            var result = new FileWrapper(file);

            var _eventsDao = DaoFactory.GetRelationshipEventDao();
            var eventIDs   = _eventsDao.RemoveFile(file);
            var events     = new List <RelationshipEvent>();

            eventIDs.ForEach(id => events.Add(_eventsDao.GetByID(id)));
            //events for audit log

            MessageService.Send(_context, MessageAction.CrmEntityDetachedFile, file.Title);

            return(result);
        }
Exemplo n.º 4
0
        public FileWrapper DeleteCRMFile(int fileid)
        {
            if (fileid < 0)
            {
                throw new ArgumentException();
            }

            var file = FilesDaoFactory.GetFileDao().GetFile(fileid);

            if (file == null)
            {
                throw new ItemNotFoundException();
            }

            var result = new FileWrapper(file);

            DaoFactory.GetRelationshipEventDao().RemoveFile(file);

            return(result);
        }
        public RelationshipEventWrapper AddHistoryTo(
            string entityType,
            int entityId,
            int contactId,
            string content,
            int categoryId,
            ApiDateTime created,
            IEnumerable <int> fileId,
            IEnumerable <Guid> notifyUserList)
        {
            if (!string.IsNullOrEmpty(entityType) &&
                !(
                    string.Compare(entityType, "opportunity", StringComparison.OrdinalIgnoreCase) == 0 ||
                    string.Compare(entityType, "case", StringComparison.OrdinalIgnoreCase) == 0)
                )
            {
                throw new ArgumentException();
            }

            var entityTypeObj = ToEntityType(entityType);

            var entityTitle = "";

            if (contactId > 0)
            {
                var contact = DaoFactory.ContactDao.GetByID(contactId);
                if (contact == null || !CRMSecurity.CanAccessTo(contact))
                {
                    throw new ArgumentException();
                }
                entityTitle = contact.GetTitle();
            }

            if (entityTypeObj == EntityType.Case)
            {
                var cases = DaoFactory.CasesDao.GetByID(entityId);
                if (cases == null || !CRMSecurity.CanAccessTo(cases))
                {
                    throw new ArgumentException();
                }
                if (contactId <= 0)
                {
                    entityTitle = cases.Title;
                }
            }
            if (entityTypeObj == EntityType.Opportunity)
            {
                var deal = DaoFactory.DealDao.GetByID(entityId);
                if (deal == null || !CRMSecurity.CanAccessTo(deal))
                {
                    throw new ArgumentException();
                }
                if (contactId <= 0)
                {
                    entityTitle = deal.Title;
                }
            }

            var relationshipEvent = new RelationshipEvent
            {
                CategoryID = categoryId,
                EntityType = entityTypeObj,
                EntityID   = entityId,
                Content    = content,
                ContactID  = contactId,
                CreateOn   = created,
                CreateBy   = Core.SecurityContext.CurrentAccount.ID
            };

            var category = DaoFactory.ListItemDao.GetByID(categoryId);

            if (category == null)
            {
                throw new ArgumentException();
            }

            var item = DaoFactory.RelationshipEventDao.CreateItem(relationshipEvent);


            notifyUserList = notifyUserList != null?notifyUserList.ToList() : new List <Guid>();

            var needNotify = notifyUserList.Any();

            var fileListInfoHashtable = new Hashtable();

            if (fileId != null)
            {
                var fileIds = fileId.ToList();
                var files   = FilesDaoFactory.GetFileDao().GetFiles(fileIds.Cast <object>().ToArray());

                if (needNotify)
                {
                    foreach (var file in files)
                    {
                        var extension = Path.GetExtension(file.Title);
                        if (extension == null)
                        {
                            continue;
                        }

                        var fileInfo = string.Format("{0} ({1})", file.Title, extension.ToUpper());
                        if (!fileListInfoHashtable.ContainsKey(fileInfo))
                        {
                            fileListInfoHashtable.Add(fileInfo, file.DownloadUrl);
                        }
                        else
                        {
                            fileInfo = string.Format("{0} ({1}, {2})", file.Title, extension.ToUpper(), file.UniqID);
                            fileListInfoHashtable.Add(fileInfo, file.DownloadUrl);
                        }
                    }
                }

                DaoFactory.RelationshipEventDao.AttachFiles(item.ID, fileIds.ToArray());

                if (files.Any())
                {
                    var fileAttachAction = GetFilesAttachAction(entityTypeObj, contactId);
                    MessageService.Send(Request, fileAttachAction, MessageTarget.Create(item.ID), entityTitle, files.Select(x => x.Title));
                }
            }

            if (needNotify)
            {
                NotifyClient.Instance.SendAboutAddRelationshipEventAdd(item, fileListInfoHashtable, DaoFactory, notifyUserList.ToArray());
            }

            var wrapper = ToRelationshipEventWrapper(item);

            var historyCreatedAction = GetHistoryCreatedAction(entityTypeObj, contactId);

            MessageService.Send(Request, historyCreatedAction, MessageTarget.Create(item.ID), entityTitle, category.Title);

            return(wrapper);
        }
Exemplo n.º 6
0
        public RelationshipEventWrapper AddHistoryTo(
            String entityType,
            int entityId,
            int contactId,
            String content,
            int categoryId,
            ApiDateTime created,
            IEnumerable <int> fileId,
            IEnumerable <Guid> notifyUserList)
        {
            if (!String.IsNullOrEmpty(entityType) &&
                !(String.Compare(entityType, "opportunity", true) == 0 ||
                  String.Compare(entityType, "case", true) == 0))
            {
                throw new ArgumentException();
            }

            var relationshipEvent = new RelationshipEvent
            {
                CategoryID = categoryId,
                EntityType = ToEntityType(entityType),
                EntityID   = entityId,
                Content    = content,
                ContactID  = contactId,
                CreateOn   = created,
                CreateBy   = Core.SecurityContext.CurrentAccount.ID
            };



            if (DaoFactory.GetListItemDao().GetByID(categoryId) == null)
            {
                throw new ArgumentException();
            }

            var item = DaoFactory.GetRelationshipEventDao().CreateItem(relationshipEvent);

            var fileListInfoHashtable = new Hashtable();

            if (fileId != null)
            {
                var fileIds = fileId.ToList();

                var files = FilesDaoFactory.GetFileDao().GetFiles(fileIds.Cast <object>().ToArray());

                foreach (var file in files)
                {
                    var fileInfo = String.Format("{0} ({1})", file.Title, Path.GetExtension(file.Title).ToUpper());
                    fileListInfoHashtable.Add(fileInfo, file.ViewUrl);
                }

                DaoFactory.GetRelationshipEventDao().AttachFiles(item.ID, fileIds.ToArray());
            }

            if (notifyUserList != null && notifyUserList.Count() > 0)
            {
                NotifyClient.Instance.SendAboutAddRelationshipEventAdd(item, fileListInfoHashtable, notifyUserList.ToArray());
            }

            return(ToRelationshipEventWrapper(item));
        }