コード例 #1
0
ファイル: CasesDao.cs プロジェクト: vipwan/CommunityServer
        public override void UpdateCases(Cases cases)
        {
            if (cases != null && cases.ID > 0)
                ResetCache(cases.ID);

            base.UpdateCases(cases);
        }
コード例 #2
0
        protected void SetPermission(ASC.CRM.Core.Entities.Cases caseItem)
        {
            if (CRMSecurity.IsAdmin || caseItem.CreateBy == SecurityContext.CurrentAccount.ID)
            {
                var isPrivate          = Convert.ToBoolean(Request["isPrivateCase"]);
                var notifyPrivateUsers = Convert.ToBoolean(Request.Form["notifyPrivateUsers"]);

                if (isPrivate)
                {
                    var selectedUserList = Request["selectedUsersCase"]
                                           .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                           .Select(item => new Guid(item)).ToList();

                    selectedUserList.Add(ASC.Core.SecurityContext.CurrentAccount.ID);

                    CRMSecurity.SetAccessTo(caseItem, selectedUserList);

                    if (notifyPrivateUsers)
                    {
                        ASC.Web.CRM.Services.NotifyService.NotifyClient.Instance.SendAboutSetAccess(EntityType.Case, caseItem.ID, selectedUserList.ToArray());
                    }
                }
                else
                {
                    CRMSecurity.MakePublic(caseItem);
                }
            }
        }
コード例 #3
0
 public static void Cases(Entities.Cases cases, String actionText, int actionType, int businessValue)
 {
     UserActivityPublisher.Publish <TimeLinePublisher>(new TimeLineUserActivity(actionText, actionType, businessValue)
     {
         ContentID  = cases.ID.ToString(),
         Title      = cases.Title,
         SecurityId = String.Format(SecurityDataPattern, (int)EntityType.Case, cases.SecurityId),
         URL        = String.Concat(VirtualPathUtility.ToAbsolute(PathProvider.BaseVirtualPath + "cases.aspx"), String.Format("?id={0}", cases.ID))
     });
 }
コード例 #4
0
        public static void DataCasesActionView(BasePage page, ASC.CRM.Core.Entities.Cases targetCase)
        {
            var daoFactory      = page.DaoFactory;
            var customFieldList = targetCase != null
                ? daoFactory.CustomFieldDao.GetEnityFields(EntityType.Case, targetCase.ID, true)
                : daoFactory.CustomFieldDao.GetFieldsDescription(EntityType.Case);

            var tags = targetCase != null?daoFactory.TagDao.GetEntityTags(EntityType.Case, targetCase.ID) : new string[]
            {
            };
            var availableTags = daoFactory.TagDao.GetAllTags(EntityType.Case).Where(item => !tags.Contains(item));


            var presetContactsJson = "";
            var selectedContacts   = new List <Contact>();

            if (targetCase != null)
            {
                selectedContacts = daoFactory.ContactDao.GetContacts(daoFactory.CasesDao.GetMembers(targetCase.ID));
            }
            else
            {
                var URLContactID = UrlParameters.ContactID;
                if (URLContactID != 0)
                {
                    var target = daoFactory.ContactDao.GetByID(URLContactID);
                    if (target != null)
                    {
                        selectedContacts.Add(target);
                    }
                }
            }

            if (selectedContacts.Count > 0)
            {
                presetContactsJson = JsonConvert.SerializeObject(selectedContacts.ConvertAll(item => new
                {
                    id           = item.ID,
                    displayName  = item.GetTitle().HtmlEncode().ReplaceSingleQuote().Replace(@"\", @"\\"),
                    smallFotoUrl = ContactPhotoManager.GetSmallSizePhoto(item.ID, item is Company)
                }));
            }

            var script = String.Format(@"
                                        var casesActionTags = {0};
                                        var casesActionAvailableTags = {1};
                                        var casesActionSelectedContacts = '{2}'; ",
                                       JsonConvert.SerializeObject(tags.ToList().ConvertAll(t => t.HtmlEncode())),
                                       JsonConvert.SerializeObject(availableTags.ToList().ConvertAll(t => t.HtmlEncode())),
                                       presetContactsJson
                                       );

            page.RegisterInlineScript(script, onReady: false);
            page.JsonPublisher(customFieldList, "casesEditCustomFieldList");
        }
コード例 #5
0
        public CasesWrapper(Cases cases)
            : base(cases.ID)
        {
            CreateBy = EmployeeWraper.Get(cases.CreateBy);
            Created = (ApiDateTime)cases.CreateOn;
            Title = cases.Title;
            IsClosed = cases.IsClosed;

            IsPrivate = CRMSecurity.IsPrivate(cases);

            if (IsPrivate)
            {
                AccessList = CRMSecurity.GetAccessSubjectTo(cases)
                                        .SkipWhile(item => item.Key == Core.Users.Constants.GroupEveryone.ID)
                                        .Select(item => EmployeeWraper.Get(item.Key));
            }
            CanEdit = CRMSecurity.CanEdit(cases);
        }
コード例 #6
0
        protected void SetPermission(ASC.CRM.Core.Entities.Cases targetCase, bool isPrivate, string selectedUsers)
        {
            if (isPrivate)
            {
                var selectedUserList = selectedUsers
                                       .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                       .Select(item => new Guid(item)).ToList();

                CRMSecurity.MakePublic(targetCase);

                if (selectedUserList.Count > 0)
                {
                    CRMSecurity.SetAccessTo(targetCase, selectedUserList);
                }
            }
            else
            {
                CRMSecurity.MakePublic(targetCase);
            }
        }
コード例 #7
0
        public static void DataCasesFullCardView(BasePage page, ASC.CRM.Core.Entities.Cases targetCase)
        {
            var customFieldList = Global.DaoFactory.GetCustomFieldDao().GetEnityFields(EntityType.Case, targetCase.ID, false);
            var tags = Global.DaoFactory.GetTagDao().GetEntityTags(EntityType.Case, targetCase.ID);
            var availableTags = Global.DaoFactory.GetTagDao().GetAllTags(EntityType.Case).Where(item => !tags.Contains(item));
            var responsibleIDs = new List<Guid>();
            if (CRMSecurity.IsPrivate(targetCase)) {
                responsibleIDs = CRMSecurity.GetAccessSubjectGuidsTo(targetCase);
            }
            var script = String.Format(@"
                                        var caseTags = {0};
                                        var caseAvailableTags = {1};
                                        var caseResponsibleIDs = {2}; ",
                                    JsonConvert.SerializeObject(tags),
                                    JsonConvert.SerializeObject(availableTags),
                                    JsonConvert.SerializeObject(responsibleIDs));

            page.RegisterInlineScript(script, onReady: false);
            page.JsonPublisher(customFieldList, "casesCustomFieldList");
        }
コード例 #8
0
        public void SendTaskReminder(Task task, String taskCategoryTitle, Contact taskContact, ASC.CRM.Core.Entities.Cases taskCase, ASC.CRM.Core.Entities.Deal taskDeal)
        {
            var recipient = ToRecipient(task.ResponsibleID);

            if (recipient == null)
            {
                return;
            }

            var deadLineString = task.DeadLine.Hour == 0 && task.DeadLine.Minute == 0
                ? task.DeadLine.ToShortDateString()
                : task.DeadLine.ToString(CultureInfo.InvariantCulture);

            string taskContactRelativeUrl = null;
            string taskContactTitle       = null;

            string taskCaseRelativeUrl = null;
            string taskCaseTitle       = null;

            string taskDealRelativeUrl = null;
            string taskDealTitle       = null;

            if (taskContact != null)
            {
                taskContactRelativeUrl = String.Format("Products/CRM/Default.aspx?id={0}{1}", taskContact.ID, taskContact is Person ? "&type=people" : "");
                taskContactTitle       = taskContact.GetTitle();
            }

            if (taskCase != null)
            {
                taskCaseRelativeUrl = String.Format("Products/CRM/Cases.aspx?id={0}", taskCase.ID);
                taskCaseTitle       = taskCase.Title.HtmlEncode();
            }

            if (taskDeal != null)
            {
                taskDealRelativeUrl = String.Format("Products/CRM/Deals.aspx?id={0}", taskDeal.ID);
                taskDealTitle       = taskDeal.Title.HtmlEncode();
            }


            client.SendNoticeToAsync(
                NotifyConstants.Event_TaskReminder,
                null,
                new[] { recipient },
                true,
                new TagValue(NotifyConstants.Tag_EntityTitle, task.Title),
                new TagValue(NotifyConstants.Tag_AdditionalData,
                             new Hashtable {
                { "TaskDescription", HttpUtility.HtmlEncode(task.Description) },
                { "TaskCategory", taskCategoryTitle },

                { "ContactRelativeUrl", taskContactRelativeUrl },
                { "ContactTitle", taskContactTitle },

                { "CaseRelativeUrl", taskCaseRelativeUrl },
                { "CaseTitle", taskCaseTitle },

                { "DealRelativeUrl", taskDealRelativeUrl },
                { "DealTitle", taskDealTitle },

                { "DueDate", deadLineString }
            })
                );
        }
コード例 #9
0
        private CasesWrapper ToCasesWrapper(Cases cases)
        {
            var casesWrapper = new CasesWrapper(cases)
                {
                    CustomFields = DaoFactory
                        .GetCustomFieldDao()
                        .GetEnityFields(EntityType.Case, cases.ID, false)
                        .ConvertAll(item => new CustomFieldBaseWrapper(item))
                        .ToSmartList(),
                    Members = new List<ContactBaseWrapper>()
                };

            var memberIDs = DaoFactory.GetCasesDao().GetMembers(cases.ID);
            var membersList = DaoFactory.GetContactDao().GetContacts(memberIDs);

            var membersWrapperList = new List<ContactBaseWrapper>();

            foreach (var member in membersList)
            {
                if (member == null) continue;
                membersWrapperList.Add(ToContactBaseWrapper(member));
            }

            casesWrapper.Members = membersWrapperList;
            return casesWrapper;
        }
コード例 #10
0
        private CasesWrapper SetAccessToCases(Cases cases, bool isPrivate, IEnumerable<Guid> accessList)
        {
            var accessListLocal = accessList.ToList();

            if (isPrivate && accessListLocal.Count > 0)
            {
                CRMSecurity.SetAccessTo(cases, accessListLocal);

                var users = CoreContext.UserManager.GetUsers(accessListLocal).Select(x => x.DisplayUserName(false));
                MessageService.Send(_context, MessageAction.CaseRestrictedAccess, cases.Title, users);
            }
            else
            {
                CRMSecurity.MakePublic(cases);
                MessageService.Send(_context, MessageAction.CaseOpenedAccess, cases.Title);
            }

            return ToCasesWrapper(cases);
        }
コード例 #11
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);
        }
コード例 #12
0
 public static void MakePublic(Cases cases)
 {
     MakePublic((ISecurityObjectId)cases);
 }
コード例 #13
0
 public static bool CanEdit(Cases cases)
 {
     return (IsAdmin || cases.CreateBy == SecurityContext.CurrentAccount.ID || 
         !CRMSecurity.IsPrivate(cases) || GetAccessSubjectTo(cases).ContainsKey(SecurityContext.CurrentAccount.ID));
 }
コード例 #14
0
ファイル: CasesDao.cs プロジェクト: vipwan/CommunityServer
        public virtual void UpdateCases(Cases cases)
        {
            CRMSecurity.DemandEdit(cases);

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

            using (var db = GetDb())
            {
                db.ExecuteNonQuery(
                     Update("crm_case")
                    .Set("title", cases.Title)
                    .Set("is_closed", cases.IsClosed)
                    .Set("last_modifed_on", TenantUtil.DateTimeToUtc(TenantUtil.DateTimeNow()))
                    .Set("last_modifed_by", SecurityContext.CurrentAccount.ID)
                    .Where("id", cases.ID)
                );
            }
        }
コード例 #15
0
 public static bool CanAccessTo(Cases cases)
 {
     return CanAccessTo((ISecurityObjectId)cases);
 }
コード例 #16
0
        private CasesWrapper SetAccessToCases(Cases cases, bool isPrivate, IEnumerable<Guid> accessList, bool isNotify, bool isMessageServicSende)
        {
            var accessListLocal = accessList != null ? accessList.Distinct().ToList() : new List<Guid>();
            if (isPrivate && accessListLocal.Any())
            {
                if (isNotify)
                {
                    accessListLocal = accessListLocal.Where(u => u != SecurityContext.CurrentAccount.ID).ToList();
                    ASC.Web.CRM.Services.NotifyService.NotifyClient.Instance.SendAboutSetAccess(EntityType.Case, cases.ID, accessListLocal.ToArray());
                }

                if (!accessListLocal.Contains(SecurityContext.CurrentAccount.ID))
                {
                    accessListLocal.Add(SecurityContext.CurrentAccount.ID);
                }

                CRMSecurity.SetAccessTo(cases, accessListLocal);
                if (isMessageServicSende)
                {
                    var users = GetUsersByIdList(accessListLocal).Select(x => x.DisplayUserName(false));
                    MessageService.Send(Request, MessageAction.CaseRestrictedAccess, cases.Title, users);
                }
            }
            else
            {
                CRMSecurity.MakePublic(cases);
                if (isMessageServicSende)
                {
                    MessageService.Send(Request, MessageAction.CaseOpenedAccess, cases.Title);
                }
            }

            return ToCasesWrapper(cases);
        }
コード例 #17
0
ファイル: ImportCases.cs プロジェクト: vipwan/CommunityServer
        private void ImportCaseData()
        {
            using (var CSVFileStream = _dataStore.GetReadStream("temp", _CSVFileURI))
            using (CsvReader csv = ImportFromCSV.CreateCsvReaderInstance(CSVFileStream, _importSettings))
            {
                int currentIndex = 0;

                var casesDao = _daoFactory.GetCasesDao();
                var customFieldDao = _daoFactory.GetCustomFieldDao();
                var tagDao = _daoFactory.GetTagDao();

                var findedTags = new Dictionary<int, List<String>>();
                var findedCustomField = new List<CustomField>();
                var findedCases = new List<ASC.CRM.Core.Entities.Cases>();
                var findedCasesMembers = new Dictionary<int, List<int>>();

                while (csv.ReadNextRecord())
                {
                    _columns = csv.GetCurrentRowFields(false);

                    var objCases = new ASC.CRM.Core.Entities.Cases();

                    objCases.ID = currentIndex;

                    objCases.Title = GetPropertyValue("title");

                    if (String.IsNullOrEmpty(objCases.Title)) continue;

                    foreach (JProperty jToken in _importSettings.ColumnMapping.Children())
                    {
                        var propertyValue = GetPropertyValue(jToken.Name);

                        if (String.IsNullOrEmpty(propertyValue)) continue;

                        if (!jToken.Name.StartsWith("customField_")) continue;

                        var fieldID = Convert.ToInt32(jToken.Name.Split(new[] { '_' })[1]);

                        var field = customFieldDao.GetFieldDescription(fieldID);

                        if (field != null)
                        {
                            findedCustomField.Add(new CustomField
                            {
                                EntityID = objCases.ID,
                                EntityType = EntityType.Case,
                                ID = fieldID,
                                Value = field.FieldType == CustomFieldType.CheckBox ? (propertyValue == "on" || propertyValue == "true" ? "true" : "false") : propertyValue
                            });
                        }

                    }

                    var tag = GetPropertyValue("tag");

                    if (!String.IsNullOrEmpty(tag))
                    {
                        var tagList = tag.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        tagList.AddRange(_importSettings.Tags);
                        tagList = tagList.Distinct().ToList();
                        findedTags.Add(objCases.ID, tagList);
                    }
                    else if (_importSettings.Tags.Count != 0)
                    {
                        findedTags.Add(objCases.ID, _importSettings.Tags);
                    }

                    var localMembersCases = new List<int>();

                    var members = GetPropertyValue("member");

                    if (!String.IsNullOrEmpty(members))
                    {
                        var membersList = members.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                        foreach (var item in membersList)
                        {
                            var findedMember = _daoFactory.GetContactDao().GetContactsByName(item, true);

                            if (findedMember.Count > 0)
                            {
                                localMembersCases.Add(findedMember[0].ID);
                            }
                            else
                            {
                                findedMember = _daoFactory.GetContactDao().GetContactsByName(item, false);
                                if (findedMember.Count > 0)
                                {
                                    localMembersCases.Add(findedMember[0].ID);
                                }
                            }

                        }
                    }

                    if (localMembersCases.Count > 0)
                        findedCasesMembers.Add(objCases.ID, localMembersCases);

                    objCases.ID = currentIndex;

                    findedCases.Add(objCases);

                    if (currentIndex + 1 > ImportFromCSV.MaxRoxCount) break;

                    currentIndex++;
                }

                Percentage = 62.5;

                var newIDs = casesDao.SaveCasesList(findedCases);
                findedCases.ForEach(d => d.ID = newIDs[d.ID]);

                findedCustomField.ForEach(item => item.EntityID = newIDs[item.EntityID]);

                customFieldDao.SaveList(findedCustomField);

                Percentage += 12.5;

                foreach (var findedCasesMemberKey in findedCasesMembers.Keys)
                {
                    _daoFactory.GetDealDao().SetMembers(newIDs[findedCasesMemberKey], findedCasesMembers[findedCasesMemberKey].ToArray());
                }

                Percentage += 12.5;

                foreach (var findedTagKey in findedTags.Keys)
                {
                    tagDao.SetTagToEntity(EntityType.Case, newIDs[findedTagKey], findedTags[findedTagKey].ToArray());
                }

                if (_importSettings.IsPrivate)
                    findedCases.ForEach(dealItem => CRMSecurity.SetAccessTo(dealItem, _importSettings.AccessList));


                Percentage += 12.5;
            }

            Complete();
        }
コード例 #18
0
        private CasesWrapper SetAccessToCases(
          Cases cases,
          bool isPrivate,
          IEnumerable<Guid> accessList)
        {

            var accessListLocal = accessList.ToList();

            if (isPrivate && accessListLocal.Count > 0)
                CRMSecurity.SetAccessTo(cases, accessListLocal);
            else
                CRMSecurity.MakePublic(cases);

            return ToCasesWrapper(cases);
        }
コード例 #19
0
        public CasesWrapper CreateCases(
                                      String title,
                                      IEnumerable<int> members,
                                      IEnumerable<ItemKeyValuePair<int, String>> customFieldList,
                                      bool isPrivate,
                                      IEnumerable<Guid> accessList)
        {
            if (String.IsNullOrEmpty(title))
                throw new ArgumentException();

            int casesID = DaoFactory.GetCasesDao().CreateCases(title);

            var cases = new Cases
            {
                ID = casesID,
                Title = title
            };

            var accessListLocal = accessList.ToList();

            if (isPrivate && accessListLocal.Count > 0)
                CRMSecurity.SetAccessTo(cases, accessListLocal);
            else
                CRMSecurity.MakePublic(cases);

            if (members != null && members.Count() > 0)
                DaoFactory.GetDealDao().SetMembers(cases.ID, members.ToArray());

            foreach (var field in customFieldList)
            {
                if (String.IsNullOrEmpty(field.Value)) continue;

                DaoFactory.GetCustomFieldDao().SetFieldValue(EntityType.Case, cases.ID, field.Key, field.Value);
            }

            return ToCasesWrapper(DaoFactory.GetCasesDao().GetByID(casesID));
        }
コード例 #20
0
 public static void DemandDelete(Cases cases)
 {
     if (!CanDelete(cases)) throw CreateSecurityException();
 }
コード例 #21
0
 public static void DemandEdit(Cases cases)
 {
     if (!CanEdit(cases)) throw CreateSecurityException();
 }
コード例 #22
0
 public static bool CanDelete(Cases cases)
 {
     return CanEdit(cases);
 }
コード例 #23
0
        public CasesWrapper CreateCases(
            string title,
            IEnumerable<int> members,
            IEnumerable<ItemKeyValuePair<int, string>> customFieldList,
            bool isPrivate,
            IEnumerable<Guid> accessList,
            bool isNotify)
        {
            if (string.IsNullOrEmpty(title)) throw new ArgumentException();

            var casesID = DaoFactory.GetCasesDao().CreateCases(title);

            var cases = new Cases
                {
                    ID = casesID,
                    Title = title,
                    CreateBy = SecurityContext.CurrentAccount.ID,
                    CreateOn = DateTime.UtcNow
                };

            SetAccessToCases(cases, isPrivate, accessList, isNotify, false);

            var membersList = members != null ? members.ToList() : new List<int>();
            if (membersList.Any())
            {
                var contacts = DaoFactory.GetContactDao().GetContacts(membersList.ToArray()).Where(CRMSecurity.CanAccessTo).ToList();
                membersList = contacts.Select(m => m.ID).ToList();
                DaoFactory.GetCasesDao().SetMembers(cases.ID, membersList.ToArray());
            }

            if (customFieldList != null)
            {
                var existingCustomFieldList = DaoFactory.GetCustomFieldDao().GetFieldsDescription(EntityType.Case).Select(fd => fd.ID).ToList();
                foreach (var field in customFieldList)
                {
                    if (string.IsNullOrEmpty(field.Value) || !existingCustomFieldList.Contains(field.Key)) continue;
                    DaoFactory.GetCustomFieldDao().SetFieldValue(EntityType.Case, cases.ID, field.Key, field.Value);
                }
            }

            return ToCasesWrapper(DaoFactory.GetCasesDao().GetByID(casesID));
        }
コード例 #24
0
 public static Dictionary<Guid, string> GetAccessSubjectTo(Cases cases)
 {
     return GetAccessSubjectTo((ISecurityObjectId)cases);
 }
コード例 #25
0
 public static void SetAccessTo(Cases cases, List<Guid> subjectID)
 {
     SetAccessTo((ISecurityObjectId)cases, subjectID);
 }
コード例 #26
0
 public static void DemandAccessTo(Cases cases)
 {
     if (!CanAccessTo(cases)) throw CreateSecurityException();
 }
コード例 #27
0
 public static bool IsPrivate(Cases cases)
 {
     return IsPrivate((ISecurityObjectId)cases);
 }
コード例 #28
0
 public static void SetAccessTo(Cases cases, List<Guid> subjectID)
 {
     if (IsAdmin || cases.CreateBy == SecurityContext.CurrentAccount.ID)
     {
         SetAccessTo((ISecurityObjectId)cases, subjectID);
     }
 }
コード例 #29
0
 public static List<Guid> GetAccessSubjectGuidsTo(Cases cases)
 {
     return GetAccessSubjectGuidsTo((ISecurityObjectId)cases);
 }
コード例 #30
0
ファイル: CasesDao.cs プロジェクト: ridhouan/teamlab.v6.5
        public virtual void UpdateCases(Cases cases)
        {
            CRMSecurity.DemandAccessTo(cases);

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

            DbManager.ExecuteNonQuery(
                     Update("crm_case")
                    .Set("title", cases.Title)
                    .Set("is_closed", cases.IsClosed)
                    .Set("last_modifed_on", TenantUtil.DateTimeToUtc(TenantUtil.DateTimeNow()))
                    .Set("last_modifed_by", ASC.Core.SecurityContext.CurrentAccount.ID)
                    .Where(Exp.Eq("id", cases.ID))
                );
        }
コード例 #31
0
        private void ImportCaseData()
        {
            using (var CSVFileStream = _dataStore.GetReadStream("temp", _CSVFileURI))
                using (CsvReader csv = ImportFromCSV.CreateCsvReaderInstance(CSVFileStream, _importSettings))
                {
                    int currentIndex = 0;

                    var casesDao       = _daoFactory.GetCasesDao();
                    var customFieldDao = _daoFactory.GetCustomFieldDao();
                    var tagDao         = _daoFactory.GetTagDao();

                    var findedTags         = new Dictionary <int, List <String> >();
                    var findedCustomField  = new List <CustomField>();
                    var findedCases        = new List <ASC.CRM.Core.Entities.Cases>();
                    var findedCasesMembers = new Dictionary <int, List <int> >();

                    while (csv.ReadNextRecord())
                    {
                        _columns = csv.GetCurrentRowFields(false);

                        var objCases = new ASC.CRM.Core.Entities.Cases();

                        objCases.ID = currentIndex;

                        objCases.Title = GetPropertyValue("title");

                        if (String.IsNullOrEmpty(objCases.Title))
                        {
                            continue;
                        }

                        foreach (JProperty jToken in _importSettings.ColumnMapping.Children())
                        {
                            var propertyValue = GetPropertyValue(jToken.Name);

                            if (String.IsNullOrEmpty(propertyValue))
                            {
                                continue;
                            }

                            if (!jToken.Name.StartsWith("customField_"))
                            {
                                continue;
                            }

                            var fieldID = Convert.ToInt32(jToken.Name.Split(new[] { '_' })[1]);

                            var field = customFieldDao.GetFieldDescription(fieldID);

                            if (field != null)
                            {
                                findedCustomField.Add(new CustomField
                                {
                                    EntityID   = objCases.ID,
                                    EntityType = EntityType.Case,
                                    ID         = fieldID,
                                    Value      = field.FieldType == CustomFieldType.CheckBox ? (propertyValue == "on" || propertyValue == "true" ? "true" : "false") : propertyValue
                                });
                            }
                        }

                        var tag = GetPropertyValue("tag");

                        if (!String.IsNullOrEmpty(tag))
                        {
                            var tagList = tag.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                            tagList.AddRange(_importSettings.Tags);
                            tagList = tagList.Distinct().ToList();
                            findedTags.Add(objCases.ID, tagList);
                        }
                        else if (_importSettings.Tags.Count != 0)
                        {
                            findedTags.Add(objCases.ID, _importSettings.Tags);
                        }

                        var localMembersCases = new List <int>();

                        var members = GetPropertyValue("member");

                        if (!String.IsNullOrEmpty(members))
                        {
                            var membersList = members.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                            foreach (var item in membersList)
                            {
                                var findedMember = _daoFactory.GetContactDao().GetContactsByName(item, true);

                                if (findedMember.Count > 0)
                                {
                                    localMembersCases.Add(findedMember[0].ID);
                                }
                                else
                                {
                                    findedMember = _daoFactory.GetContactDao().GetContactsByName(item, false);
                                    if (findedMember.Count > 0)
                                    {
                                        localMembersCases.Add(findedMember[0].ID);
                                    }
                                }
                            }
                        }

                        if (localMembersCases.Count > 0)
                        {
                            findedCasesMembers.Add(objCases.ID, localMembersCases);
                        }

                        objCases.ID = currentIndex;

                        findedCases.Add(objCases);

                        if (currentIndex + 1 > ImportFromCSV.MaxRoxCount)
                        {
                            break;
                        }

                        currentIndex++;
                    }

                    Percentage = 62.5;

                    if (ImportDataCache.CheckCancelFlag(EntityType.Case))
                    {
                        ImportDataCache.ResetAll(EntityType.Case);

                        throw new OperationCanceledException();
                    }

                    ImportDataCache.Insert(EntityType.Case, (ImportDataOperation)Clone());

                    var newIDs = casesDao.SaveCasesList(findedCases);
                    findedCases.ForEach(d => d.ID = newIDs[d.ID]);

                    findedCustomField.ForEach(item => item.EntityID = newIDs[item.EntityID]);

                    customFieldDao.SaveList(findedCustomField);

                    Percentage += 12.5;

                    if (ImportDataCache.CheckCancelFlag(EntityType.Case))
                    {
                        ImportDataCache.ResetAll(EntityType.Case);

                        throw new OperationCanceledException();
                    }

                    ImportDataCache.Insert(EntityType.Case, (ImportDataOperation)Clone());

                    foreach (var findedCasesMemberKey in findedCasesMembers.Keys)
                    {
                        _daoFactory.GetDealDao().SetMembers(newIDs[findedCasesMemberKey], findedCasesMembers[findedCasesMemberKey].ToArray());
                    }

                    Percentage += 12.5;

                    if (ImportDataCache.CheckCancelFlag(EntityType.Case))
                    {
                        ImportDataCache.ResetAll(EntityType.Case);

                        throw new OperationCanceledException();
                    }

                    ImportDataCache.Insert(EntityType.Case, (ImportDataOperation)Clone());


                    foreach (var findedTagKey in findedTags.Keys)
                    {
                        tagDao.SetTagToEntity(EntityType.Case, newIDs[findedTagKey], findedTags[findedTagKey].ToArray());
                    }

                    if (_importSettings.IsPrivate)
                    {
                        findedCases.ForEach(dealItem => CRMSecurity.SetAccessTo(dealItem, _importSettings.AccessList));
                    }


                    Percentage += 12.5;

                    if (ImportDataCache.CheckCancelFlag(EntityType.Case))
                    {
                        ImportDataCache.ResetAll(EntityType.Case);

                        throw new OperationCanceledException();
                    }

                    ImportDataCache.Insert(EntityType.Case, (ImportDataOperation)Clone());
                }

            Complete();
        }
コード例 #32
0
        private static Cases ToCases(object[] r)
        {
            var cases = new Cases
                {
                    ID = Convert.ToInt32(r[0]),
                    Title = Convert.ToString(r[1]),
                    IsClosed = Convert.ToBoolean(r[2]),
                    CreateBy = new Guid(Convert.ToString(r[3])),
                    CreateOn = Convert.ToDateTime(r[4]),
                    LastModifedBy = new Guid(Convert.ToString(r[5])),
                    LastModifedOn = Convert.ToDateTime(r[6])
                };

            var members = Convert.ToString(r[7]);
            if (!string.IsNullOrEmpty(members))
            {
                cases.Members = new HashSet<int>(
                    members.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries)
                           .Select(x => Convert.ToInt32(x))
                    );
            }

            return cases;
        }
コード例 #33
0
        private Feed ToFeed(Cases cases)
        {
            var dao = new DaoFactory(Tenant, DbId).GetContactDao();
            var contactsString = Helper.GetContactsString(cases.Members, dao);

            var itemUrl = "/products/crm/cases.aspx?id=" + cases.ID + "#profile";
            return new Feed(cases.CreateBy, cases.CreateOn)
                {
                    Item = item,
                    ItemId = cases.ID.ToString(CultureInfo.InvariantCulture),
                    ItemUrl = CommonLinkUtility.ToAbsolute(itemUrl),
                    Product = Product,
                    Module = Name,
                    Title = cases.Title,
                    AdditionalInfo = contactsString,
                    Keywords = cases.Title,
                    HasPreview = false,
                    CanComment = false,
                    GroupId = string.Format("{0}_{1}", item, cases.ID)
                };
        }
コード例 #34
0
        public CasesWrapper CreateCases(
            string title,
            IEnumerable<int> members,
            IEnumerable<ItemKeyValuePair<int, string>> customFieldList,
            bool isPrivate,
            IEnumerable<Guid> accessList)
        {
            if (string.IsNullOrEmpty(title)) throw new ArgumentException();

            var casesID = DaoFactory.GetCasesDao().CreateCases(title);

            var cases = new Cases
                {
                    ID = casesID,
                    Title = title
                };

            var accessListLocal = accessList.ToList();

            if (isPrivate && accessListLocal.Count > 0)
            {
                CRMSecurity.SetAccessTo(cases, accessListLocal);
            }
            else
            {
                CRMSecurity.MakePublic(cases);
            }

            var membersList = members.ToList();
            if (members != null && membersList.Any())
            {
                var contacts = DaoFactory.GetContactDao().GetContacts(membersList.ToArray()).Where(CRMSecurity.CanAccessTo).ToList();
                membersList = contacts.Select(m => m.ID).ToList();

                DaoFactory.GetCasesDao().SetMembers(cases.ID, membersList.ToArray());
            }

            var existingCustomFieldList = DaoFactory.GetCustomFieldDao().GetFieldsDescription(EntityType.Case).Select(fd => fd.ID).ToList();

            foreach (var field in customFieldList)
            {
                if (string.IsNullOrEmpty(field.Value) || !existingCustomFieldList.Contains(field.Key)) continue;
                DaoFactory.GetCustomFieldDao().SetFieldValue(EntityType.Case, cases.ID, field.Key, field.Value);
            }

            return ToCasesWrapper(DaoFactory.GetCasesDao().GetByID(casesID));
        }
コード例 #35
0
        public void SendAboutResponsibleByTask(Task task, String taskCategoryTitle, Contact taskContact, ASC.CRM.Core.Entities.Cases taskCase, ASC.CRM.Core.Entities.Deal taskDeal, Hashtable fileListInfoHashtable)
        {
            var recipient = ToRecipient(task.ResponsibleID);

            if (recipient == null)
            {
                return;
            }

            task.DeadLine = TenantUtil.DateTimeFromUtc(task.DeadLine);
            var deadLineString = task.DeadLine.Hour == 0 && task.DeadLine.Minute == 0
                ? task.DeadLine.ToShortDateString()
                : task.DeadLine.ToString();


            string taskContactRelativeUrl = null;
            string taskContactTitle       = null;

            string taskCaseRelativeUrl = null;
            string taskCaseTitle       = null;

            string taskDealRelativeUrl = null;
            string taskDealTitle       = null;

            if (taskContact != null)
            {
                taskContactRelativeUrl = String.Format("products/crm/default.aspx?id={0}{1}", taskContact.ID, taskContact is Person ? "&type=people" : "");
                taskContactTitle       = taskContact.GetTitle();
            }

            if (taskCase != null)
            {
                taskCaseRelativeUrl = String.Format("products/crm/cases.aspx?id={0}", taskCase.ID);
                taskCaseTitle       = taskCase.Title.HtmlEncode();
            }

            if (taskDeal != null)
            {
                taskDealRelativeUrl = String.Format("products/crm/deals.aspx?id={0}", taskDeal.ID);
                taskDealTitle       = taskDeal.Title.HtmlEncode();
            }

            client.SendNoticeToAsync(
                NotifyConstants.Event_ResponsibleForTask,
                null,
                new[] { recipient },
                true,
                new TagValue(NotifyConstants.Tag_EntityTitle, task.Title),
                new TagValue(NotifyConstants.Tag_AdditionalData,
                             new Hashtable {
                { "TaskDescription", HttpUtility.HtmlEncode(task.Description) },
                { "Files", fileListInfoHashtable },
                { "TaskCategory", taskCategoryTitle },

                { "ContactRelativeUrl", taskContactRelativeUrl },
                { "ContactTitle", taskContactTitle },

                { "CaseRelativeUrl", taskCaseRelativeUrl },
                { "CaseTitle", taskCaseTitle },

                { "DealRelativeUrl", taskDealRelativeUrl },
                { "DealTitle", taskDealTitle },

                { "DueDate", deadLineString }
            })
                );
        }
コード例 #36
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);
        }