/// <summary> /// Обновляет денормализованную инфу о цвете в задачах /// </summary> public void UpdateColorPosition(IBoardsColor color) { // Масимально быстрое обновление, так как задач может быть много _Context.ExecuteCommand(@"UPDATE Tasks SET ColorPosition = {0} WHERE ColorId = {1}", color.Position, color.Id); }
public IBoardsColor AddColor(int boardId, string name, string color) { IBoardsColor boardsColor = AddColor(boardId, name, color, false); OnCreateColor.Invoke(new EventArgs <IBoardsColor>(boardsColor)); return(boardsColor); }
/// <summary> /// Обновляет денормализованную инфу о цвете в задачах /// </summary> public void UpdateColor(IBoardsColor color) { // Масимально быстрое обновление, так как задач может быть много _Context.ExecuteCommand(@"UPDATE Tasks SET ColorHEX = {0}, ColorName = {1} WHERE ColorId = {2}", color.Color, color.Name, color.Id); }
public ActionResult SetColor(int taskId, int colorId, int boardId) { return(TaskAction(taskId, null, delegate { IBoardsColor color = Utility.Tasks.SetColor(taskId, colorId, boardId); return Content(color != null ? color.Color : string.Empty); })); }
/// <summary> /// Делает цвет цветом поумолчанию /// </summary> public void MakeDefault(IBoardsColor color) { // TODO: какая-то хенря. // если все сделать через нейтивный скл, то контекст становится невалидным, по этому часть через SubmitChanges _Context.ExecuteCommand(@"UPDATE BoardsColors SET IsDefault = 0 WHERE BoardId = {0}", color.BoardId); color.IsDefault = true; _Context.SubmitChanges(); }
public void DeleteColor(int colorId) { IBoardsColor boardsColor = Repository.BoardsColors.DeleteColor(colorId); if (boardsColor != null) { OnDeleteColor.Invoke(new EventArgs <IBoardsColor>(boardsColor)); } }
public TimezBoardsColor(IBoardsColor color) { Id = color.Id; Position = color.Position; BoardId = color.BoardId; Color = color.Color; Name = color.Name; IsDefault = color.IsDefault; }
/// <summary> /// Создание задачи /// </summary> /// <exception cref="PlanningTimeRequered"></exception> /// <exception cref="PlanningTimeIsExceeded"></exception> public ITask Create(string name, string desc, int executorId, int projectId, int colorId, int statusId, int boardId, int?planingTime = null, Limits checkLimits = Limits.NoLimits) { if (name.IsNullOrEmpty()) { throw new ArgumentException("Name"); } IBoardsColor color = Utility.Boards.GetColor(boardId, colorId); IProject project = Utility.Projects.Get(boardId, projectId); IUser executor = Utility.Users.Get(executorId); ITasksStatus status = Utility.Statuses.Get(boardId, statusId); int creatorUserId = Utility.Authentication.UserId; // Передаем данные о создаваемой задаче, что бы проверить по ней ограничения CheckTaskLimits(status, executorId, checkLimits, new TimezTask { Name = name, Description = desc, ExecutorUserId = executor.Id, ExecutorNick = executor.Nick, ExecutorEmail = executor.EMail, BoardId = boardId, ColorHEX = color.Color, ColorId = color.Id, ColorName = color.Name, ColorPosition = color.Position, CreationDateTime = DateTimeOffset.Now, CreatorUserId = creatorUserId, Id = 0, PlanningTime = planingTime, ProjectId = project.Id, ProjectName = project.Name, StatusChangeDateTime = DateTimeOffset.Now, TaskStatusId = status.Id, TaskStatusPosition = status.Position }); CheckStatusLimits(status, planingTime); //using (TransactionScope scope = new TransactionScope()) { ITask task = Repository.Tasks.Create(name, desc, executor, project, color, status, planingTime, creatorUserId); OnCreate.Invoke(new EventArgs <ITask>(task)); OnTaskAssigned.Invoke(new UpdateEventArgs <ITask>(null, task)); //scope.Complete(); return(task); } }
public string Test(int boardId, int userId) { StringBuilder sb = new StringBuilder(); Stopwatch sw = new Stopwatch(); sw.Start(); Utility.Authentication.SignIn(userId, false); var participants = Utility.Boards.GetExecutorsToAssing(boardId); userId = participants[_Random.Next(participants.Count)].Id; Utility.Authentication.SignIn(userId, false); if (_Random.Next(1000) < 50) { int count; Utility.Events.Get(new EventDataFilter { BoardId = boardId }, out count); sb.AppendLine("Events"); } if (_Random.Next(1000) < 10) { new CacheService().ClearAll(); sb.AppendLine("Cache clear"); } List <ITask> tasks = Utility.Tasks.Get(Utility.Tasks.CreateFilter(boardId)); ITask task = tasks[_Random.Next(tasks.Count)]; List <ITasksStatus> statuses = Utility.Statuses.GetByBoard(boardId); Utility.Tasks.UpdateStatus(task.Id, statuses[_Random.Next(statuses.Count)].Id, Limits.NoLimits); if (_Random.Next(1000) < 100) { IProject project = Utility.Projects.GetByBoard(boardId).First(); IBoardsColor color = Utility.Boards.GetColors(boardId).First(); Utility.Tasks.Delete(task); Utility.Tasks.Create("Test " + DateTime.Now.ToString(), "", userId, project.Id, color.Id , statuses[_Random.Next(statuses.Count)].Id, boardId, 60); sb.AppendLine("Create delete"); } sw.Stop(); sb.AppendLine("Time: " + sw.ElapsedMilliseconds.ToString()); return(sb.ToString().Replace(Environment.NewLine, "<br>")); }
public PartialViewResult EditColor(int boardId, int?id) { if (id.HasValue) { IBoardsColor color = Utility.Boards.GetColor(boardId, id.Value); ViewData.Add("Id", color.Id); ViewData.Add("Color", color.Color); ViewData.Model = color; } else { Random randomclr = new Random(); Color color = Color.FromArgb(0, randomclr.Next(256), randomclr.Next(256), randomclr.Next(256)); ViewData.Add("Color", "#" + color.Name); } return(PartialView()); }
public int FillTestDB(int count, int userId, int?boardId = null) { IUser user = Utility.Users.Get(userId); Utility.Authentication.SignIn(user.Id, false); IBoard board = boardId.HasValue ? Utility.Boards.Get(boardId.Value) : Utility.Boards.Create("Test_" + DateTime.Now.ToString(), "", user); IProject project = Utility.Projects.GetByBoard(board.Id).First(); IBoardsColor color = Utility.Boards.GetColors(board.Id).First(); List <ITasksStatus> statuses = Utility.Statuses.GetByBoard(board.Id); for (int i = 0; i < count; i++) { Utility.Tasks.Create("Test " + i, "", userId, project.Id, color.Id, statuses[_Random.Next(statuses.Count)].Id, board.Id, 60); } return(board.Id); }
public IBoardsColor SetColor(int taskId, int colorId, int boardId) { IBoardsColor color = Utility.Boards.GetColor(boardId, colorId); ITask task = _Get(taskId); if (task.ColorId != color.Id) { ITask oldTask = new TimezTask(task); task.ColorId = color.Id; task.ColorHEX = color.Color; task.ColorName = color.Name; task.ColorPosition = color.Position; Repository.SubmitChanges(); OnUpdateColor.Invoke(new UpdateEventArgs <ITask>(oldTask, task)); } return(color); }
public ITask Create(string name, string desc, IUser user, IProject project, IBoardsColor color, ITasksStatus status, int?planingTime, int creatorUserId) { Task task = new Task { BoardId = project.BoardId, ColorId = color.Id, ColorHEX = color.Color, ColorName = color.Name, ColorPosition = color.Position, CreationDateTime = DateTimeOffset.Now, Description = desc, ExecutorUserId = user.Id, ExecutorEmail = user.EMail, ExecutorNick = user.Nick, Name = name, ProjectId = project.Id, ProjectName = project.Name, StatusChangeDateTime = DateTimeOffset.Now, TaskStatusId = status.Id, TaskStatusPosition = status.Position, TaskStatusName = status.Name, PlanningTime = planingTime, CreatorUserId = creatorUserId }; const string sql = @" INSERT INTO [dbo].[Tasks] ([Name] ,[Description] ,[BoardId] ,[CreatorUserId] ,[CreationDateTime] ,[StatusChangeDateTime] ,[PlanningTime] ,[ColorId] ,[ColorHEX] ,[ColorName] ,[ColorPosition] ,[ProjectId] ,[ProjectName] ,[ExecutorUserId] ,[ExecutorNick] ,[ExecutorEmail] ,[TaskStatusId] ,[TaskStatusPosition] ,[TaskStatusName] ,[IsDeleted]) VALUES (@Name ,@Description ,@BoardId ,@CreatorUserId ,@CreationDateTime ,@StatusChangeDateTime ,@PlanningTime ,@ColorId ,@ColorHEX ,@ColorName ,@ColorPosition ,@ProjectId ,@ProjectName ,@ExecutorUserId ,@ExecutorNick ,@ExecutorEmail ,@TaskStatusId ,@TaskStatusPosition ,@TaskStatusName ,@IsDeleted); SELECT CAST(@@IDENTITY AS INT)" ; using (DbCommand command = _Context.Connection.CreateCommand()) { command.CommandText = sql; command.Parameters.Add(new SqlParameter("@Name", task.Name)); command.Parameters.Add(new SqlParameter("@Description", task.Description)); command.Parameters.Add(new SqlParameter("@BoardId", task.BoardId)); command.Parameters.Add(new SqlParameter("@CreatorUserId", task.CreatorUserId)); command.Parameters.Add(new SqlParameter("@CreationDateTime", task.CreationDateTime)); command.Parameters.Add(new SqlParameter("@StatusChangeDateTime", task.StatusChangeDateTime)); command.Parameters.Add(new SqlParameter("@PlanningTime", task.PlanningTime ?? (object)DBNull.Value)); command.Parameters.Add(new SqlParameter("@ColorId", task.ColorId)); command.Parameters.Add(new SqlParameter("@ColorHEX", task.ColorHEX)); command.Parameters.Add(new SqlParameter("@ColorName", task.ColorName)); command.Parameters.Add(new SqlParameter("@ColorPosition", task.ColorPosition)); command.Parameters.Add(new SqlParameter("@ProjectId", task.ProjectId)); command.Parameters.Add(new SqlParameter("@ProjectName", task.ProjectName)); command.Parameters.Add(new SqlParameter("@ExecutorUserId", task.ExecutorUserId)); command.Parameters.Add(new SqlParameter("@ExecutorNick", task.ExecutorNick)); command.Parameters.Add(new SqlParameter("@ExecutorEmail", task.ExecutorEmail)); command.Parameters.Add(new SqlParameter("@TaskStatusId", task.TaskStatusId)); command.Parameters.Add(new SqlParameter("@TaskStatusPosition", task.TaskStatusPosition)); command.Parameters.Add(new SqlParameter("@TaskStatusName", task.TaskStatusName)); command.Parameters.Add(new SqlParameter("@IsDeleted", task.IsDeleted)); _Context.Connection.Open(); task.Id = (int)command.ExecuteScalar(); _Context.Connection.Close(); } //task.Id = _Context.ExecuteQuery<int>(sql //, task.Name //, task.Description //, task.BoardId //, task.CreatorUserId //, task.CreationDateTime //, task.StatusChangeDateTime //, task.PlanningTime ?? (object)DBNull.Value //, task.ColorId //, task.ColorHEX //, task.ColorName //, task.ColorPosition //, task.ProjectId //, task.ProjectName //, task.ExecutorUserId //, task.ExecutorNick //, task.ExecutorEmail //, task.TaskStatusId //, task.TaskStatusPosition //, task.TaskStatusName //, task.IsDeleted) //.First(); return(task); }
/// <summary> /// Обновлеяе основные параметры задачи /// Кроме статуса! Так как там сложная логика /// Обновление задачи, если задача была в кеше, то обновление происходит асинхронно /// Если в кеше задачи не было, то обновление синхронное и после задача добавляется в кеш /// </summary> public ITask Update(int boardId, int taskId, string name, string description, int userId, int projectId, int colorId, int?planingTime, Limits limits) { if (name.IsNullOrEmpty()) { throw new ArgumentException("Name"); } // TODO: Не вызывать апдейт, если ничиго не поменялось // TODO: Добавить колонку с временем обновления для поддержки версионности ITask task = _Get(taskId); TimezTask oldTask = new TimezTask(task); IProject project = Utility.Projects.Get(boardId, projectId); IBoardsColor color = Utility.Boards.GetColor(project.BoardId, colorId); IUser executor = Utility.Users.Get(userId); ITasksStatus status = Utility.Statuses.Get(boardId, task.TaskStatusId); CheckTaskLimits(status, userId, limits, task); bool taskAssigned = task.ExecutorUserId != executor.Id; bool colorChanged = task.ColorId != color.Id; bool projectChanged = task.ProjectId != project.Id; bool planingTimeChanged = task.PlanningTime != planingTime; task.Name = name; task.Description = description; task.ExecutorUserId = executor.Id; task.ExecutorEmail = executor.EMail; task.ExecutorNick = executor.Nick; task.ProjectId = project.Id; task.ProjectName = project.Name; task.ColorId = color.Id; task.ColorHEX = color.Color; task.ColorName = color.Name; task.ColorPosition = color.Position; task.PlanningTime = planingTime; using (TransactionScope scope = new TransactionScope()) { Repository.SubmitChanges(); OnUpdate.Invoke(new UpdateEventArgs <ITask>(oldTask, task)); if (taskAssigned) { OnTaskAssigned.Invoke(new UpdateEventArgs <ITask>(oldTask, task)); } if (colorChanged) { OnUpdateColor.Invoke(new UpdateEventArgs <ITask>(oldTask, task)); } if (projectChanged) { OnUpdateProject.Invoke(new UpdateEventArgs <ITask>(oldTask, task)); } if (planingTimeChanged) { OnUpdatePlaningTime.Invoke(new UpdateEventArgs <ITask>(oldTask, task)); } scope.Complete(); } return(task); }
internal override void Init() { #region // Следим за другими утилитами, что б поддерживать кеш задач в валидном состоянии Utility.Projects.OnDelete += ProjectsUtility_OnDelete; // Удаляем из кеша все задачи удаленного пользователя Utility.Boards.OnRemoveUserFromBoard += BoardsUtility_OnRemoveUserFromBoard; // Обновляем цвета у задач Utility.Boards.OnUpdateColor += (s, e) => { IBoardsColor color = e.Data; HashSet <ITask> cache = GetTasksCache(color.BoardId); if (cache != null) { using (new UpdateLock(color.BoardId)) { ITask[] tasks = cache .Where(x => x.ColorId == color.Id) .ToArray(); foreach (var item in tasks) { item.ColorHEX = color.Color; item.ColorPosition = color.Position; item.ColorName = color.Name; } } } }; Utility.Boards.OnDeleteColor += (s, e) => { IBoardsColor color = e.Data; var key = GetAllTasksKey(color.BoardId); Cache.Clear(key); }; #endregion #region Обновляем имена проектов в задачах Utility.Projects.OnUpdate.Add( (sender, e) => { IProject project = e.Data; TaskFilter filter = CreateFilter(project.BoardId); filter.ProjectIds = new[] { project.Id }; List <ITask> tasks = Get(filter); tasks.ForEach(x => x.ProjectName = project.Name); }); #endregion #region Обновляем имена статусов в задачах Utility.Statuses.OnUpdate.Add( (sender, e) => { ITasksStatus status = e.Data; TaskFilter filter = CreateFilter(status.BoardId); filter.Statuses = new[] { status.Id }; List <ITask> tasks = Get(filter); tasks.ForEach( x => { x.TaskStatusName = status.Name; x.TaskStatusPosition = status.Position; }); }); #endregion #region При удалении статуса чистим кеш доски Utility.Statuses.OnDelete.Add( (sender, e) => { ITasksStatus status = e.Data; var key = Cache.GetKeys(CacheKey.Status, status.Id); Cache.Clear(key); key = GetAllTasksKey(status.BoardId); Cache.Clear(key); }); #endregion #region Обновление исполнителя Utility.Users.OnUpdate.Add( (sender, e) => { IUser user = e.NewData; Repository.Tasks.UpdateExecutor(user); List <IBoard> boards = Utility.Boards.GetByUser(user.Id); foreach (var board in boards) { var cache = GetTasksCache(board.Id); if (cache != null) { using (new UpdateLock(board.Id)) { foreach (ITask task in cache.Where(x => x.ExecutorUserId == user.Id)) { task.ExecutorEmail = user.EMail; task.ExecutorNick = user.Nick; } } } } }); #endregion // TODO: протестить лики из-за подписок }