Ejemplo n.º 1
0
 public static void Task(Task task, String actionText, int actionType, int businessValue, bool withPreview)
 {
     UserActivityPublisher.Publish<TimeLinePublisher>(new TimeLineUserActivity(actionText, actionType, businessValue)
     {
         ContentID = task.ID.ToString(),
         SecurityId = String.Format(SecurityDataPattern, (int)EntityType.Task, task.ID),
         Title = task.Title,
         URL = String.Concat(VirtualPathUtility.ToAbsolute(PathProvider.BaseVirtualPath + "tasks.aspx"), String.Format("?id={0}", task.ID))
     });
 }
Ejemplo n.º 2
0
        public override int SaveOrUpdateTask(Task task)
        {

            if (task != null && task.ID > 0)
            {
                ResetCache(task.ID);
            }

            return base.SaveOrUpdateTask(task);
        }
Ejemplo n.º 3
0
 public TaskWrapper(Task task): base(task.ID)
 {
     CreateBy = EmployeeWraper.Get(task.CreateBy);
     Created = (ApiDateTime)task.CreateOn;
     Title = task.Title;
     Description = task.Description;
     DeadLine = (ApiDateTime)task.DeadLine;
     Responsible = EmployeeWraper.Get(task.ResponsibleID);
     IsClosed = task.IsClosed;
 }
Ejemplo n.º 4
0
 public static bool CanEdit(Task task)
 {
     return (IsAdmin || task.ResponsibleID == SecurityContext.CurrentAccount.ID || task.CreateBy == SecurityContext.CurrentAccount.ID);
 }
Ejemplo n.º 5
0
        public static bool CanAccessTo(Task task)
        {
            if (IsAdmin || task.ResponsibleID == SecurityContext.CurrentAccount.ID ||
                (task.ContactID == 0 && task.EntityID == 0) || task.CreateBy == SecurityContext.CurrentAccount.ID) return true;

            if (task.ContactID > 0)
            {
                var contactObj = Global.DaoFactory.GetContactDao().GetByID(task.ContactID);

                if (contactObj != null) return CanAccessTo(contactObj);

            //    task.ContactID = 0;

            //    Global.DaoFactory.GetTaskDao().SaveOrUpdateTask(task);

            }

            if (task.EntityType == EntityType.Case)
            {
                var caseObj = Global.DaoFactory.GetCasesDao().GetByID(task.EntityID);

                if (caseObj != null) return CanAccessTo(caseObj);

             //   task.EntityType = EntityType.Any;
             //   task.EntityID = 0;

              //  Global.DaoFactory.GetTaskDao().SaveOrUpdateTask(task);

            }

            if (task.EntityType == EntityType.Opportunity)
            {
                var dealObj = Global.DaoFactory.GetDealDao().GetByID(task.EntityID);

                if (dealObj != null) return CanAccessTo(dealObj);

             //   task.EntityType = EntityType.Any;
             //   task.EntityID = 0;

             //   Global.DaoFactory.GetTaskDao().SaveOrUpdateTask(task);
            }

            return false;

        }
Ejemplo n.º 6
0
 public static bool CanGoToFeed(Task task)
 {
     return IsAdmin || task.ResponsibleID == SecurityContext.CurrentAccount.ID || task.CreateBy == SecurityContext.CurrentAccount.ID;
 }
Ejemplo n.º 7
0
        private int SaveTask(Task newTask, DbManager db)
        {
            if (String.IsNullOrEmpty(newTask.Title) || newTask.DeadLine == DateTime.MinValue ||
                newTask.CategoryID == 0)
                throw new ArgumentException();

             return db.ExecuteScalar<int>(
                               Insert("crm_task")
                              .InColumnValue("id", 0)
                              .InColumnValue("title", newTask.Title)
                              .InColumnValue("description", newTask.Description)
                              .InColumnValue("deadline", TenantUtil.DateTimeToUtc(newTask.DeadLine))
                              .InColumnValue("responsible_id", newTask.ResponsibleID)
                              .InColumnValue("contact_id", newTask.ContactID)
                              .InColumnValue("entity_type", (int)newTask.EntityType)
                              .InColumnValue("entity_id", newTask.EntityID)
                              .InColumnValue("is_closed", newTask.IsClosed)
                              .InColumnValue("category_id", newTask.CategoryID)
                              .InColumnValue("create_on", DateTime.UtcNow)
                              .InColumnValue("create_by", ASC.Core.SecurityContext.CurrentAccount.ID)
                              .InColumnValue("last_modifed_on", DateTime.UtcNow)
                              .InColumnValue("last_modifed_by", ASC.Core.SecurityContext.CurrentAccount.ID)
                              .InColumnValue("alert_value", (int)newTask.AlertValue)
                              .Identity(1, 0, true));
        }
Ejemplo n.º 8
0
        public virtual Task SaveOrUpdateTask(Task newTask)
        {
            _cache.Remove(_taskCacheKey);
            _cache.Insert(_taskCacheKey, String.Empty);

            using (var db = GetDb())
            {
                return SaveOrUpdateTask(newTask, db);
            }
        }
Ejemplo n.º 9
0
 private Feed ToFeed(Task task)
 {
     const string itemUrl = "/products/crm/tasks.aspx";
     return new Feed(task.CreateBy, task.CreateOn)
         {
             Item = item,
             ItemId = task.ID.ToString(CultureInfo.InvariantCulture),
             ItemUrl = CommonLinkUtility.ToAbsolute(itemUrl),
             Product = Product,
             Module = Name,
             Title = task.Title,
             Description = Helper.GetHtmlDescription(HttpUtility.HtmlEncode(task.Description)),
             AdditionalInfo = Helper.GetUser(task.ResponsibleID).DisplayName,
             AdditionalInfo2 = task.Contact.GetTitle(),
             Keywords = string.Format("{0} {1}", task.Title, task.Description),
             HasPreview = false,
             CanComment = false,
             GroupId = GetGroupId(item, task.CreateBy)
         };
 }
Ejemplo n.º 10
0
        private int SaveOrUpdateTask(Task newTask, DbManager db)
        {
            if (String.IsNullOrEmpty(newTask.Title) || newTask.DeadLine == DateTime.MinValue ||
                newTask.CategoryID <= 0)
                throw new ArgumentException();

            if (db.ExecuteScalar<int>(Query("crm_task").SelectCount().Where(Exp.Eq("id", newTask.ID))) == 0)
            {
                newTask.ID = db.ExecuteScalar<int>(
                               Insert("crm_task")
                              .InColumnValue("id", 0)
                              .InColumnValue("title", newTask.Title)
                              .InColumnValue("description", newTask.Description)
                              .InColumnValue("deadline", TenantUtil.DateTimeToUtc(newTask.DeadLine))
                              .InColumnValue("responsible_id", newTask.ResponsibleID)
                              .InColumnValue("contact_id", newTask.ContactID)
                              .InColumnValue("entity_type", (int)newTask.EntityType)
                              .InColumnValue("entity_id", newTask.EntityID)
                              .InColumnValue("is_closed", newTask.IsClosed)
                              .InColumnValue("category_id", newTask.CategoryID)
                              .InColumnValue("create_on", DateTime.UtcNow)
                              .InColumnValue("create_by", ASC.Core.SecurityContext.CurrentAccount.ID)
                              .InColumnValue("last_modifed_on", DateTime.UtcNow)
                              .InColumnValue("last_modifed_by", ASC.Core.SecurityContext.CurrentAccount.ID)
                              .InColumnValue("alert_value", newTask.AlertValue)
                              .Identity(1, 0, true));
            }
            else
            {

                var oldTask = db.ExecuteList(GetTaskQuery(Exp.Eq("id", newTask.ID)))
                    .ConvertAll(row => ToTask(row))
                    .FirstOrDefault();


                CRMSecurity.DemandEdit(oldTask);

                db.ExecuteNonQuery(
                     Update("crm_task")
                     .Set("title", newTask.Title)
                     .Set("description", newTask.Description)
                     .Set("deadline", TenantUtil.DateTimeToUtc(newTask.DeadLine))
                     .Set("responsible_id", newTask.ResponsibleID)
                     .Set("contact_id", newTask.ContactID)
                     .Set("entity_type", (int)newTask.EntityType)
                     .Set("entity_id", newTask.EntityID)
                     .Set("category_id", newTask.CategoryID)
                     .Set("last_modifed_on", DateTime.UtcNow)
                     .Set("last_modifed_by", ASC.Core.SecurityContext.CurrentAccount.ID)
                     .Set("alert_value", (int)newTask.AlertValue)
                     .Set("exec_alert", 0)
                     .Where(Exp.Eq("id", newTask.ID)));
            }

            return newTask.ID;
        }
Ejemplo n.º 11
0
 public static void DemandAccessTo(Task task)
 {
     if (!CanAccessTo(task)) throw CreateSecurityException();
 }
Ejemplo n.º 12
0
        public TaskWrapper UpdateTask(
            int taskid,
            String title,
            String description,
            ApiDateTime deadline,
            Guid responsibleid,
            int categoryid,
            int contactid,
            String entityType,
            int entityid,
            bool isNotify,
            int alertValue)
        {

            if (!String.IsNullOrEmpty(entityType) && !(String.Compare(entityType, "opportunity", true) == 0 ||
                String.Compare(entityType, "case", true) == 0))
                throw new ArgumentException();

            var task = new Task
                           {
                               ID = taskid,
                               Title = title,
                               Description = description,
                               DeadLine = deadline,
                               AlertValue = alertValue,
                               ResponsibleID = responsibleid,
                               CategoryID = categoryid,
                               ContactID = contactid,
                               EntityID = entityid,
                               EntityType = ToEntityType(entityType)
                           };



            task.ID =  DaoFactory.GetTaskDao().SaveOrUpdateTask(task);

            if (isNotify) {
                String taskCategory = null;
                String taskContact = null;

                if (task.CategoryID > 0) {
                    var listItem = DaoFactory.GetListItemDao().GetByID(task.CategoryID);
                    if (listItem == null)
                        throw new ItemNotFoundException();
                    taskCategory = listItem.Title;
                }

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

                NotifyClient.Instance.SendAboutResponsibleByTask(task, taskCategory, taskContact, null);
            }

            return ToTaskWrapper(task);
        }
Ejemplo n.º 13
0
 public static Dictionary<Guid, string> GetAccessSubjectTo(Task task)
 {
     return GetAccessSubjectTo((ISecurityObjectId)task);
 }
Ejemplo n.º 14
0
 public static List<Guid> GetAccessSubjectGuidsTo(Task task)
 {
     return GetAccessSubjectGuidsTo((ISecurityObjectId)task);
 }
Ejemplo n.º 15
0
 public static bool IsPrivate(Task task)
 {
     return IsPrivate((ISecurityObjectId)task);
 }
Ejemplo n.º 16
0
 public static void MakePublic(Task task)
 {
     MakePublic((ISecurityObjectId)task);
 }
Ejemplo n.º 17
0
 public static void SetAccessTo(Task task, List<Guid> subjectID)
 {
     SetAccessTo((ISecurityObjectId)task, subjectID);
 }
Ejemplo n.º 18
0
 public static void DemandEdit(Task task)
 {
     if (!CanEdit(task)) throw CreateSecurityException();
 }
Ejemplo n.º 19
0
        private Task FromTaskWrapper(TaskWrapper taskWrapper)
        {
            var task = new Task
                           {
                               ContactID = taskWrapper.Contact.ID,
                               Title = taskWrapper.Title,
                               Description = taskWrapper.Description,
                               DeadLine = taskWrapper.DeadLine,
                               ResponsibleID = taskWrapper.Responsible.Id,
                               IsClosed = taskWrapper.IsClosed,
                               CategoryID = taskWrapper.Category.ID,
                               EntityType = ToEntityType(taskWrapper.Entity.EntityType),
                               EntityID = taskWrapper.Entity.EntityId
                           };

            return task;
        }
Ejemplo n.º 20
0
        private static Task ToTask(object[] r)
        {
            var task = new Task
                {
                    ID = Convert.ToInt32(r[0]),
                    Title = Convert.ToString(r[1]),
                    Description = Convert.ToString(r[2]),
                    DeadLine = Convert.ToDateTime(r[3]),
                    ResponsibleID = new Guid(Convert.ToString(r[4])),
                    ContactID = Convert.ToInt32(r[5]),
                    IsClosed = Convert.ToBoolean(r[6]),
                    EntityType = (EntityType)Convert.ToInt32(r[7]),
                    EntityID = Convert.ToInt32(r[8]),
                    CategoryID = Convert.ToInt32(r[9]),
                    CreateBy = new Guid(Convert.ToString(r[10])),
                    CreateOn = Convert.ToDateTime(r[11]),
                    LastModifedBy = new Guid(Convert.ToString(r[12])),
                    LastModifedOn = Convert.ToDateTime(r[13])
                };

            if (string.IsNullOrEmpty(Convert.ToString(r[14]))) return task;

            var isCompany = Convert.ToBoolean(r[14]);
            if (isCompany)
            {
                task.Contact = new Company
                    {
                        ID = Convert.ToInt32(r[15]),
                        About = Convert.ToString(r[16]),
                        CompanyName = Convert.ToString(r[19]),
                        CreateBy = new Guid(Convert.ToString(r[22])),
                        CreateOn = Convert.ToDateTime(r[23]),
                        LastModifedBy = new Guid(Convert.ToString(r[24])),
                        LastModifedOn = Convert.ToDateTime(r[25])
                    };
            }
            else
            {
                task.Contact = new Person
                    {
                        ID = Convert.ToInt32(r[15]),
                        About = Convert.ToString(r[16]),
                        FirstName = Convert.ToString(r[17]),
                        LastName = Convert.ToString(r[18]),
                        CompanyID = Convert.ToInt32(r[20]),
                        JobTitle = Convert.ToString(r[21]),
                        CreateBy = new Guid(Convert.ToString(r[22])),
                        CreateOn = Convert.ToDateTime(r[23]),
                        LastModifedBy = new Guid(Convert.ToString(r[24])),
                        LastModifedOn = Convert.ToDateTime(r[25])
                    };
            }

            return task;
        }
Ejemplo n.º 21
0
        public List<Task> CreateByTemplate(List<TaskTemplate> templateItems, EntityType entityType, int entityID)
        {

            if (templateItems == null || templateItems.Count == 0) return new List<Task>();

            var result = new List<Task>();

            using (var db = GetDb())
            using (var tx = db.BeginTransaction())
            {
                foreach (var templateItem in templateItems)
                {
                    var task = new Task
                    {
                        ResponsibleID = templateItem.ResponsibleID,
                        Description = templateItem.Description,
                        DeadLine = TenantUtil.DateTimeNow().AddTicks(templateItem.Offset.Ticks),
                        CategoryID = templateItem.CategoryID,
                        Title = templateItem.Title,
                        CreateOn = TenantUtil.DateTimeNow(),
                        CreateBy = templateItem.CreateBy
                    };

                    switch (entityType)
                    {
                        case EntityType.Contact:
                        case EntityType.Person:
                        case EntityType.Company:
                            task.ContactID = entityID;
                            break;
                        case EntityType.Opportunity:
                            task.EntityType = EntityType.Opportunity;
                            task.EntityID = entityID;
                            break;
                        case EntityType.Case:
                            task.EntityType = EntityType.Case;
                            task.EntityID = entityID;
                            break;
                        default:
                            throw new NotImplementedException();
                    }

                    task.ID = SaveOrUpdateTask(task, db);

                    result.Add(task);

                    db.ExecuteNonQuery(Insert("crm_task_template_task")
                                     .InColumnValue("task_id", task.ID)
                                     .InColumnValue("task_template_id", templateItem.ID));

                }

                tx.Commit();
            }

            return result;
        }
Ejemplo n.º 22
0
        public virtual int SaveOrUpdateTask(Task newTask)
        {
            if (String.IsNullOrEmpty(newTask.Title) || newTask.DeadLine == DateTime.MinValue ||
                newTask.CategoryID == 0)
                throw new ArgumentException();

            if (!IsExist(newTask.ID))
            {
                newTask.ID = DbManager.ExecuteScalar<int>(
                               Insert("crm_task")
                              .InColumnValue("id", 0)
                              .InColumnValue("title", newTask.Title)
                              .InColumnValue("description", newTask.Description)
                              .InColumnValue("deadline", TenantUtil.DateTimeToUtc(newTask.DeadLine))
                              .InColumnValue("responsible_id", newTask.ResponsibleID)
                              .InColumnValue("contact_id", newTask.ContactID)
                              .InColumnValue("entity_type", (int)newTask.EntityType)
                              .InColumnValue("entity_id", newTask.EntityID)
                              .InColumnValue("is_closed", false)
                              .InColumnValue("category_id", newTask.CategoryID)
                              .InColumnValue("create_on", DateTime.UtcNow)
                              .InColumnValue("create_by", ASC.Core.SecurityContext.CurrentAccount.ID)
                              .InColumnValue("last_modifed_on", DateTime.UtcNow)
                              .InColumnValue("last_modifed_by", ASC.Core.SecurityContext.CurrentAccount.ID)
                              .Identity(1, 0, true));


            }
            else
            {

                var oldTask = GetByID(newTask.ID);

                CRMSecurity.DemandEdit(oldTask);

                DbManager.ExecuteNonQuery(
                     Update("crm_task")
                     .Set("title", newTask.Title)
                     .Set("description", newTask.Description)
                     .Set("deadline", TenantUtil.DateTimeToUtc(newTask.DeadLine))
                     .Set("responsible_id", newTask.ResponsibleID)
                     .Set("contact_id", newTask.ContactID)
                     .Set("entity_type", (int)newTask.EntityType)
                     .Set("entity_id", newTask.EntityID)
                     .Set("category_id", newTask.CategoryID)
                     .Set("last_modifed_on", DateTime.UtcNow)
                     .Set("last_modifed_by", ASC.Core.SecurityContext.CurrentAccount.ID)
                     .Where(Exp.Eq("id", newTask.ID)));
            }

            return newTask.ID;
        }
Ejemplo n.º 23
0
 public static void Task(Task task, String actionText, int actionType, int businessValue)
 {
     Task(task, actionText, actionType, businessValue, false);
 }
Ejemplo n.º 24
0
        public virtual int SaveTask(Task newTask)
        {
            _cache.Insert(_taskCacheKey, String.Empty);

            using (var db = GetDb())
            {
                return SaveTask(newTask, db);
            }
        }
Ejemplo n.º 25
0
        private TaskWrapper ToTaskWrapper(Task task)
        {
            var result = new TaskWrapper(task);

            if (task.CategoryID > 0)
            {
                result.Category = GetTaskCategoryByID(task.CategoryID);
            }

            if (task.ContactID > 0)
            {
                result.Contact = ToContactBaseWithEmailWrapper(DaoFactory.GetContactDao().GetByID(task.ContactID));
            }

            if (task.EntityID > 0)
            {
                result.Entity = ToEntityWrapper(task.EntityType, task.EntityID);
            }

            result.CanEdit = CRMSecurity.CanEdit(task);

            return result;
        }
Ejemplo n.º 26
0
 public TaskBaseWrapper(Task task) : base(task.ID)
 {
     Title = task.Title;
     Description = task.Description;
     DeadLine = (ApiDateTime)task.DeadLine;
     Responsible = EmployeeWraper.Get(task.ResponsibleID);
     IsClosed = task.IsClosed;
     AlertValue = task.AlertValue;
 }
Ejemplo n.º 27
0
        public void SendAboutResponsibleByTask(Task task, Hashtable fileListInfoHashtable)
        {
            var recipient = ToRecipient(task.ResponsibleID);

            if (recipient == null) return;

            client.SendNoticeToAsync(
               NotifyConstants.Event_ResponsibleForTask,
               null,
               new[] { recipient },
               null,
               new TagValue(NotifyConstants.Tag_EntityTitle, task.Title),
               new TagValue(NotifyConstants.Tag_EntityID, task.ID),
               new TagValue(NotifyConstants.Tag_AdditionalData,
                 new Hashtable { 
                      { "TaskDescription", HttpUtility.HtmlEncode(task.Description) }, 
                      { "Files", fileListInfoHashtable } 
                     }));
        }
Ejemplo n.º 28
0
        private void ImportTaskData()
        {
            using (var CSVFileStream = _dataStore.GetReadStream("temp", _CSVFileURI))
            using (CsvReader csv = ImportFromCSV.CreateCsvReaderInstance(CSVFileStream, _importSettings))
            {
                int currentIndex = 0;

                using (var contactDao = _daoFactory.GetContactDao())
                using (var listItemDao = _daoFactory.GetListItemDao())
                using (var taskDao = _daoFactory.GetTaskDao())
                {
                    var findedTasks = new List<Task>();
                    var taskCategories = listItemDao.GetItems(ListType.TaskCategory);

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

                        var obj = new Task();

                        obj.ID = currentIndex;

                        obj.Title = GetPropertyValue("title");

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

                        obj.Description = GetPropertyValue("description");

                        DateTime deadline;

                        if (DateTime.TryParse(GetPropertyValue("due_date"), out deadline))
                            obj.DeadLine = deadline;
                        else
                            obj.DeadLine = TenantUtil.DateTimeNow();

                        var responsible = ASC.Core.CoreContext.UserManager.Search(GetPropertyValue("responsible"), EmployeeStatus.All).FirstOrDefault();

                        if (responsible != null)
                            obj.ResponsibleID = responsible.ID;
                        else
                            obj.ResponsibleID = Constants.LostUser.ID;

                        var categoryTitle = GetPropertyValue("taskCategory");

                        if (!String.IsNullOrEmpty(categoryTitle))
                        {
                            var findedCategory = taskCategories.Find(item => String.Compare(item.Title, categoryTitle) == 0);

                            if (findedCategory == null)
                            {
                                obj.CategoryID = taskCategories[0].ID;
                            }
                            else
                                obj.CategoryID = findedCategory.ID;
                        }
                        else
                            obj.CategoryID = taskCategories[0].ID;

                        var contactName = GetPropertyValue("contact");

                        if (!String.IsNullOrEmpty(contactName))
                        {
                            var contacts = contactDao.GetContactsByName(contactName);

                            if (contacts.Count > 0)
                                obj.ContactID = contacts[0].ID;
                        }

                        obj.IsClosed = false;

                        var taskStatus = GetPropertyValue("status");
                        
                        if (!String.IsNullOrEmpty(taskStatus))
                        {
                            if (String.Compare(taskStatus, CRMTaskResource.TaskStatus_Closed, true) == 0)
                                obj.IsClosed = true;
                          
                        }

                        findedTasks.Add(obj);

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

                        currentIndex++;

                    }

                    Percentage = 50;

                    var newIDs = taskDao.SaveTaskList(findedTasks);

                    Percentage += 12.5;
                }

                Complete();

            }

        }
Ejemplo n.º 29
0
        public TaskWrapper UpdateTask(
            int taskid,
            string title,
            string description,
            ApiDateTime deadline,
            Guid responsibleid,
            int categoryid,
            int contactid,
            string entityType,
            int entityid,
            bool isNotify,
            int alertValue)
        {
            if (!string.IsNullOrEmpty(entityType) &&
                !(string.Compare(entityType, "opportunity", StringComparison.OrdinalIgnoreCase) == 0 ||
                  string.Compare(entityType, "case", StringComparison.OrdinalIgnoreCase) == 0
                 ) || categoryid <= 0)
                throw new ArgumentException();

            var listItem = DaoFactory.GetListItemDao().GetByID(categoryid);
            if (listItem == null) throw new ItemNotFoundException(CRMErrorsResource.TaskCategoryNotFound);

            var task = new Task
                {
                    ID = taskid,
                    Title = title,
                    Description = description,
                    DeadLine = deadline,
                    AlertValue = alertValue,
                    ResponsibleID = responsibleid,
                    CategoryID = categoryid,
                    ContactID = contactid,
                    EntityID = entityid,
                    EntityType = ToEntityType(entityType)
                };


            task = DaoFactory.GetTaskDao().SaveOrUpdateTask(task);

            if (isNotify)
            {
                string taskContact = null;
                if (task.ContactID > 0)
                {
                    taskContact = DaoFactory.GetContactDao().GetByID(task.ContactID).GetTitle();
                }

                NotifyClient.Instance.SendAboutResponsibleByTask(task, listItem.Title, taskContact, null);
            }

            MessageService.Send(Request, MessageAction.CrmTaskUpdated, task.Title);

            return ToTaskWrapper(task);
        }