示例#1
0
        /// <summary>
        /// Создаем проект и подписывает создателя на все события на доске
        /// </summary>
        public IProject Create(int boardId, string name, IUser creatorUser)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                int?projectsCount = Utility.Tariffs.GetAvailableProjectsCount(boardId);
                if (projectsCount.HasValue && projectsCount.Value <= 0)
                {
                    throw new TariffException("Достигнут лимит количества проектов");
                }

                IProject prj = Repository.Projects.Create(boardId, name);

                //в зависимости от валидности мыла по разному подписываем на событи + при регистрации через ФБ не всегда валидировать мыло сразу
                ReciveType reciveType = creatorUser.EMail.IsValidEmail()
                                            ? ReciveType.All
                                            : ReciveType.NotDefined;

                Repository.Projects.AddProjectsUser(prj.Id, creatorUser.Id, reciveType);

                OnCreate.Invoke(new EventArgs <IProject>(prj));

                scope.Complete();

                return(prj);
            }
        }
示例#2
0
        public PartialViewResult Settings(int boardId, FormCollection collection)
        {
            int projId = collection["project-id"].ToInt();

            // Если нажали на Сохранить
            if (collection.AllKeys.Contains("submit"))
            {
                // проверка прав делается вручную, так как в сигнатуру экшена не удобно добавлять boardId
                //CheckAccess(boardId);

                if (ModelState.IsValid)
                {
                    // Обновление настроек рассылки по проектам
                    bool taskAssigned      = collection["taskAssigned"].StartsWith("true");
                    bool taskStatusChanged = collection["taskStatusChanged"].StartsWith("true");
                    bool taskCreated       = collection["taskCreated"].StartsWith("true");

                    ReciveType type
                        = (taskAssigned ? ReciveType.TaskAssigned : ReciveType.NotDefined)
                          | (taskStatusChanged ? ReciveType.TaskStatusChanged : ReciveType.NotDefined)
                          | (taskCreated ? ReciveType.TaskCreated : ReciveType.NotDefined);

                    Utility.Projects.Update(projId, Utility.Authentication.UserId, type);
                }
            }

            return(Settings(boardId, projId));
        }
示例#3
0
        /// <summary>
        /// Создание сообщения по задаче
        /// </summary>
        /// <param name="reciveType"></param>
        /// <param name="template">
        /// {0} - проект
        /// {1} - урл на задачу
        /// {2} - название задачи</param>
        /// <param name="task"></param>
        void TaskMessage(ITask task, ReciveType reciveType, string template)
        {
            // Все пользователи в проекте
            List <IUser> users = Utility.Users.GetByProject(task.ProjectId);
            IProject     proj  = Utility.Projects.Get(task.BoardId, task.ProjectId);

            if (proj != null && users != null && users.Count > 0)
            {
                string url = Url.Action("Details", "Tasks", new { boardId = task.BoardId, id = task.Id }, "http");

                foreach (var user in users)
                {
                    if (CheckSettings(reciveType, task, user))
                    {
                        SendMail(user,
                                 "timez.org", template.Params
                                 (
                                     proj.Name,                      // 0
                                     url,                            // 1
                                     task.Name)                      // 2
                                 );
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// bla
        /// </summary>
        /// <returns></returns>
        public IProjectsUser AddProjectsUser(int projId, int userId, ReciveType type)
        {
            var          proj = _Get(_Context, projId);
            ProjectsUser pu   = new ProjectsUser
            {
                ProjectId   = projId,
                BoardId     = proj.BoardId,
                ReciveEMail = (int)type,
                UserId      = userId
            };

            _Context.ProjectsUsers.InsertOnSubmit(pu);
            _Context.SubmitChanges();

            return(pu);
        }
示例#5
0
        /// <summary>
        /// Проверка настроек уведомлений для пользователя в проекте
        /// </summary>
        /// <param name="reciveType">какой тип уведомлений требуется</param>
        /// <param name="task">проверяемая задача</param>
        /// <param name="user">проверяемый пользователь</param>
        /// <returns></returns>
        bool CheckSettings(ReciveType reciveType, ITask task, IUser user)
        {
            // Текущий пользователь является инициатором сообщения
            if (!user.RecievOwnEvents && Utility.Authentication.UserId == user.Id)
            {
                // текущий пользователь не хочет получать свои сообщения
                return(false);
            }

            IProjectsUser setting = Utility.Projects.GetSettings(user.Id)
                                    .FirstOrDefault(x => x.ProjectId == task.ProjectId);

            bool isSet = setting != null && setting.ReciveEMail.HasTheFlag((int)reciveType);

            if (isSet && reciveType == ReciveType.TaskAssigned)
            {
                return(task.ExecutorUserId == user.Id);
            }

            return(isSet);
        }
示例#6
0
        /// <summary>
        /// Установка рассылки для пользователя в проекте
        /// </summary>
        public void Update(int projId, int userId, ReciveType type)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                var setting = Repository.Projects.GetProjectsUser(projId, userId);
                if (setting == null)
                {
                    Repository.Projects.AddProjectsUser(projId, userId, type);
                }
                else
                {
                    if (setting.ReciveEMail != (int)type)
                    {
                        setting.ReciveEMail = (int)type;
                        Repository.SubmitChanges();
                    }
                }

                OnUpdateUserSettings.Invoke(new EventArgs <IProjectsUser>(setting));

                scope.Complete();
            }
        }
示例#7
0
        public object Num;              // playername or roomidx
        //public MsgSys msgContent;

        public Message()
        {
            // 默认的消息是全局广播消息
            reciType = ReciveType.ALL;
            Num      = null;
        }