Esempio n. 1
0
        //由于授权一般在服务层,所以ABP直接在ApplicationService基类注入并定义了一个PermissionChecker属性 这样 在服务层 就可以直接调PermissionChecker属性进行权限检查
        //public IPermissionChecker PermissionChecker { protected get; set; }
        //创建任务
        public int CreateTask(CreateTaskInput input)
        {
            //We can use Logger, it's defined in ApplicationService class.
            Logger.Info("Creating a task for input: " + input);

            //判断用户是否有权限
            if (input.AssignedPersonId.HasValue && input.AssignedPersonId.Value != AbpSession.GetUserId())
            {
                PermissionChecker.Authorize(PermissionNames.Pages_Tasks_AssignPerson);
            }
            var task   = Mapper.Map <Task>(input);
            int result = _taskRepository.InsertAndGetId(task);

            if (result > 0)//只有创建成功才发送邮件和通知
            {
                task.CreationTime = Clock.Now;

                if (input.AssignedPersonId.HasValue)
                {
                    task.AssignedPerson = _userRepository.Load(input.AssignedPersonId.Value);
                    var message = "You hava been assigned one task into your todo list.";

                    //TODO:需要重新配置QQ邮箱密码
                    //SmtpEmailSender emailSender = new SmtpEmailSender(_smtpEmialSenderConfig);
                    //emailSender.Send("*****@*****.**", task.AssignedPerson.EmailAddress, "New Todo item", message);

                    _notificationPublisher.Publish("NewTask", new MessageNotificationData(message), null,
                                                   NotificationSeverity.Info, new[] { task.AssignedPerson.ToUserIdentifier() });
                }
            }
            return(result);
        }
        public void Create(CreateTaskInput input)
        {
            if (input == null)
            {
                Logger.Error($"{nameof(input)} should not be null.");
                return;
            }
            var task = Mapper.Map <Core.Entities.Task>(input);

            input.ApplicationName = input.ApplicationName.Trim();
            input.Arguments       = input.Arguments?.Trim();
            input.Cron            = input.Cron.Trim();
            input.Package         = input.Package.Trim();
            input.Name            = input.Name.Trim();

            if (input.Cron != Configuration.IngoreCron)
            {
                var job = new SchedulerJobDto
                {
                    Id   = task.Id,
                    Name = task.Name,
                    Cron = input.Cron,
                    Url  = string.Format(Configuration.SchedulerCallback, task.Id),
                    Data = JsonConvert.SerializeObject(new { TaskId = task.Id })
                };
                _schedulerAppService.Create(job);
            }

            DbContext.Task.Add(task);
            DbContext.SaveChanges();
        }
Esempio n. 3
0
        //[AbpAuthorize(TaskeverPermissions.CreateTask)]
        public virtual CreateTaskOutput CreateTask(CreateTaskInput input)
        {
            //Get entities from database
            var creatorUser  = _userRepository.Get(AbpUser.CurrentUserId.Value);
            var assignedUser = _userRepository.Get(input.Task.AssignedUserId);

            if (!_taskPolicy.CanAssignTask(creatorUser, assignedUser))
            {
                throw new UserFriendlyException("You can not assign task to this user!");
            }

            //Create the task
            var taskEntity = input.Task.MapTo <Task>();

            taskEntity.CreatorUserId = creatorUser.Id;
            taskEntity.AssignedUser  = _userRepository.Load(input.Task.AssignedUserId);
            taskEntity.State         = TaskState.New;

            if (taskEntity.AssignedUser.Id != creatorUser.Id && taskEntity.Privacy == TaskPrivacy.Private)
            {
                throw new ApplicationException("A user can not assign a private task to another user!");
            }

            _taskRepository.Insert(taskEntity);

            Logger.Debug("Creaded " + taskEntity);

            _eventBus.TriggerUow(this, new EntityCreatedEventData <Task>(taskEntity));

            return(new CreateTaskOutput
            {
                Task = taskEntity.MapTo <TaskDto>()
            });
        }
        public int CreateTask(CreateTaskInput input)
        {
            //We can use Logger, it's defined in ApplicationService class.
            Logger.Info("Creating a task for input: " + input);

            var task = Mapper.Map <Task>(input);

            task.CreationTime = Clock.Now;

            if (input.AssignedPersonId.HasValue)
            {
                task.AssignedPerson = _userRepository.Load(input.AssignedPersonId.Value);
                var message = "You hava been assigned one task into your todo list.";

                //TODO:需要重新配置QQ邮箱密码
                //SmtpEmailSender emailSender = new SmtpEmailSender(_smtpEmialSenderConfig);
                //emailSender.Send("*****@*****.**", task.AssignedPerson.EmailAddress, "New Todo item", message);

                _notificationPublisher.Publish("NewTask", new MessageNotificationData(message), null,
                                               NotificationSeverity.Info, new[] { task.AssignedPerson.ToUserIdentifier() });
            }

            //Saving entity with standard Insert method of repositories.
            return(_taskRepository.InsertAndGetId(task));
        }
Esempio n. 5
0
        public int CreateTask(CreateTaskInput input)
        {
            //We can use Logger, it's defined in ApplicationService class.
            Logger.Info("Creating a task for input: " + input);


            var task = Mapper.Map <Task>(input);

            int result = _taskRepository.InsertAndGetId(task);

            //只有创建成功才发送邮件和通知
            if (result > 0)
            {
                if (input.AssignedPersonId.HasValue)
                {
                    var user = _userRepository.Load(input.AssignedPersonId.Value);
                    //task.AssignedPerson = user;
                    //var message = "You hava been assigned one task into your todo list.";

                    //使用领域事件触发发送通知操作
                    _eventBus.Trigger(new TaskAssignedEventData(task, user));

                    //TODO:需要重新配置QQ邮箱密码
                    //_smtpEmailSender.Send("*****@*****.**", task.AssignedPerson.EmailAddress, "New Todo item", message);

                    //_notificationPublisher.Publish("NewTask", new MessageNotificationData(message), null,
                    //    NotificationSeverity.Info, new[] { task.AssignedPerson.ToUserIdentifier() });
                }
            }

            return(result);
        }
Esempio n. 6
0
        public ActionResult Create(CreateTaskInput task)
        {
            var id = _taskAppService.CreateTask(task);

            //return Json(id, JsonRequestBehavior.AllowGet);
            return(RedirectToAction("List"));
        }
Esempio n. 7
0
        public ActionResult Create(CreateTaskInput task)
        {
            var id     = _taskAppServices.CreateTask(task);
            var input  = new GetTaskInput();
            var output = _taskAppServices.GetTasks(input);

            return(PartialView("_List", output.Tasks));
        }
Esempio n. 8
0
        public void CreateTask(CreateTaskInput input)
        {
            Logger.Info("Creating a task for input: " + input);
            var task = new TaskNew();

            //if (input.AssignedPersonId.HasValue)
            //{
            //    task.AssignedPersonId = input.AssignedPersonId.Value;
            //}
            _tasknewRepository.Insert(task);
        }
        public void CreateTask(CreateTaskInput input)
        {
            Logger.Info("Creating a task for input: " + input);

            // TODO: Implement feature
            _taskRepository.Insert(new Task
            {
                AssignedPersonId = input.AssignedPersonId,
                Description      = input.Description
            });
        }
Esempio n. 10
0
 public void CreateTask(CreateTaskInput input)
 {
     Logger.Info("创建一条任务:"+ input);
     var task = new Task {Description = input.Description};
     if (input.AssignedPersonId.HasValue)
     {
         task.AssignedPerson = _personalRepository.Load(input.AssignedPersonId.Value);
     }
     //通过仓储类的常规插入方法进行保存处理
     _taskRepository.Insert(task);
 }
Esempio n. 11
0
        public int CreateTask(CreateTaskInput input)
        {
            //We can use Logger, it's defined in ApplicationService class.
            Logger.Info("Creating a task for input: " + input);


            var task = Mapper.Map <Task>(input);

            int result = _taskRepository.InsertAndGetId(task);

            return(result);
        }
Esempio n. 12
0
        public void CreateTask(CreateTaskInput input)
        {
            Logger.Info("Creating a task for input: " + input);

            var task = new TaskEntity()
            {
                Description = input.Description, AssignedPersonId = input.AssignedPersonId
            };

            //调用仓储基类的Insert方法把实体保存到数据库中
            _taskRepository.Insert(task);
        }
Esempio n. 13
0
        public void CreateTask(CreateTaskInput input)
        {
            Logger.Info("Creating a task for input:" + input);
            var newTask = new Task {
                Description = input.Description
            };

            if (input.AssignedPersonId.HasValue)
            {
                newTask.AssignedPersonId = input.AssignedPersonId.Value;
            }
            _taskRepository.Insert(newTask);
        }
Esempio n. 14
0
        public async System.Threading.Tasks.Task Create(CreateTaskInput input)
        {
            var task = ObjectMapper.Map <MyTask>(input);

            try
            {
                await _taskRepository.InsertAsync(task);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 15
0
        public long CreateTask(CreateTaskInput input)
        {
            Logger.Info("Creating a task for input: " + input);
            var task = new Task {
                Description = input.Description
            };

            if (input.AssignedPersonId.HasValue)
            {
                task.AssignedPersonId = input.AssignedPersonId.Value;
            }

            var id = _taskRepository.InsertAndGetId(task);

            return(id);
        }
Esempio n. 16
0
        public void CreateTask(CreateTaskInput input)
        {
            Logger.Info("Creating a task for input: " + input);

            var task = new Task {
                Description = input.Description
            };

            if (input.AssignedPersonId.HasValue)
            {
                task.AssignedPersonId = input.AssignedPersonId.Value;
            }

            //Saving entity with standard Insert method of repositories.
            _taskRepository.Insert(task);
        }
Esempio n. 17
0
        public int CreateTask(CreateTaskInput input)
        {
            //We can use Logger, it's defined in ApplicationService class.
            Logger.Info("Creating a task for input: " + input);

            //Creating a new Task entity with given input's properties
            var task = new MyTasks.Task {
                Description  = input.Description,
                Title        = input.Title,
                State        = input.State,
                CreationTime = Clock.Now
            };

            //Saving entity with standard Insert method of repositories.
            return(_taskRepository.InsertAndGetId(task));
        }
Esempio n. 18
0
        public void CreateTask(CreateTaskInput input)
        {
            Logger.Info("Creating a task for input: " + input);

            //通过输入参数,创建一个新的Task实体
            var task = new Task {
                Description = input.Description
            };

            if (input.AssignedPersonId.HasValue)
            {
                task.AssignedPersonId = input.AssignedPersonId.Value;
            }

            //调用仓储基类的Insert方法把实体保存到数据库中
            _taskRepository.Insert(task);
        }
        public void CreateTask(CreateTaskInput input)
        {
            Logger.Info("Creating a task for input: " + input);

            _taskRepository.Insert(new Task()

            {
                AssignedPersonId = input.AssignedPersonId,

                CreationTime = DateTime.Now,

                Description = input.Description,

                State = TaskState.Active
            });

            // TODO: Implement feature
        }
Esempio n. 20
0
        public void CreateTask(CreateTaskInput input)
        {
            //We can use Logger, it's defined in ApplicationService class.
            Logger.Info("Creating a task for input: " + input);

            //Creating a new Task entity with given input's properties
            var task = new Task {
                Description = input.Description
            };

            if (input.AssignedPersonId.HasValue)
            {
                task.AssignedPersonId = input.AssignedPersonId.Value;
            }

            //Saving entity with standard Insert method of repositories.
            _taskRepository.Insert(task);
        }
Esempio n. 21
0
        public void CreateTask(CreateTaskInput input)
        {
            //我们可以使用Logger,它在应用服务基类中定义
            Logger.Info("Creating a task for input:" + input);

            //使用给定的input的属性创建一个新的Task
            var task = new Tasks.Task {
                Description = input.Description
            };

            if (input.AssignedPersonId.HasValue)
            {
                task.AssignedPersonId = input.AssignedPersonId.Value;
            }

            //使用仓储标准Insert方法保存实体
            _taskRepository.Insert(task);
        }
Esempio n. 22
0
        //public List<EmployeeListDetailDto> GetListEmployee()
        //{
        //    var result = new List<EmployeeListDetailDto>(){};
        //     result = _taskRepository.GetAll()
        //                    .Where(s => s.AssignedEmployeeId.HasValue)
        //                    .Select(e => new
        //                    {
        //                        EmployeeId = e.AssignedEmployeeId,
        //                        EmployeeName = e.AssignedEmployee.Name,
        //                        Age = e.AssignedEmployee.BirthDate,
        //                        e.State
        //                    })
        //                    .GroupBy(l => new { l.EmployeeId, l.EmployeeName , l.Age})
        //                    .Select(cl => new EmployeeListDetailDto
        //                    {
        //                        EmployeeId = cl.Key.EmployeeId,
        //                        EmployeeName = cl.Key.EmployeeName,
        //                        Age= DateTime.Today.Year- cl.Key.Age.Year,
        //                        TaskPending = cl.Where(x => x.State == TaskState.Open).Count(),
        //                        TaskComplete = cl.Where(y => y.State == TaskState.Completed).Count(),
        //                    }).ToList();

        //    return result;
        //}

        public async Task <TaskListDto> Create(CreateTaskInput input)
        {
            try
            {
                input.TenantId = 1;
                input.State    = TaskState.Completed;
                var task = ObjectMapper.Map <WS.Tasks.Task>(input);
                await _taskRepository.InsertAsync(task);

                await CurrentUnitOfWork.SaveChangesAsync();

                return(ObjectMapper.Map <TaskListDto>(task));
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
Esempio n. 23
0
        public async Task <IActionResult> createTask([FromBody] CreateTaskInput taskInput)
        {
            string token = HttpContext.Request.Headers["Authorization"];

            if (token != null)
            {
                try
                {
                    ApplicationUser user = await _userManager.FindByEmailAsync(_jwtService.GetClaimValue(token, "email"));

                    ProjectTask NewTask = new ProjectTask();
                    NewTask.Title       = taskInput.Title;
                    NewTask.Description = taskInput.Description;
                    NewTask.Created     = DateTime.Now;
                    NewTask.DueDate     = DateTime.Parse(taskInput.DueDate);
                    NewTask.CreatedBy   = user.Email;

                    _context.Add(NewTask);
                    if (!string.IsNullOrEmpty(taskInput.AssignedTo))
                    {
                        //TODO split string by ; and make multiple PTU
                        ApplicationUser AssignTo = await _userManager.FindByEmailAsync(taskInput.AssignedTo);

                        ProjectTaskUser NewPTU = new ProjectTaskUser();
                        NewPTU.ProjectTaskID = NewTask.ID;
                        NewPTU.UserID        = AssignTo.Id;
                        _context.Add(NewPTU);
                    }

                    await _context.SaveChangesAsync();

                    return(Json(NewTask.ID));
                }
                catch (ApplicationException e)
                {
                    return(Unauthorized());
                }
                catch (Exception e)
                {
                    return(NotFound());
                }
            }
            return(Unauthorized());
        }
Esempio n. 24
0
        public async System.Threading.Tasks.Task CreateTaskAsync(CreateTaskInput input)
        {
            if (await _taskRepository.CountAsync(e => e.Name == input.Name) > 0)
            {
                Logger.Info($"The task [{input}] already exists.");
                return;
            }

            Logger.Info($"Creating a task for input: {input}");

            var task = new Task
            {
                Name        = input.Name,
                Description = input.Description,
                State       = input.State ?? TaskState.Active
            };

            await _taskRepository.InsertAsync(task);
        }
        public void Should_Not_Create_New_Order_AssignToOrther_Without_Permission()
        {
            //Arrange
            LoginAsTenant(Tenant.DefaultTenantName, "TestUser");

            //获取admin用户
            var adminUser = UsingDbContext(ctx => ctx.Users.FirstOrDefault(u => u.UserName == User.AdminUserName));

            var newTask = new CreateTaskInput()
            {
                Title            = "Test Task",
                Description      = "Test Task",
                State            = TaskState.Open,
                AssignedPersonId = adminUser.Id //TestUser创建Task并分配给Admin
            };

            //Act,Assert
            Assert.Throws <AbpAuthorizationException>(() => _taskAppService.CreateTask(newTask));
        }
Esempio n. 26
0
        public int CreateTask(CreateTaskInput input)
        {
            //We can use Logger, it's defined in ApplicationService class.
            Logger.Info("Creating a task for input: " + input);

            var currentUser = AsyncHelper.RunSync(this.GetCurrentUserAsync);

            PermissionChecker.Authorize(PermissionNames.Pages_Tasks);
            //Creating a new Task entity with given input's properties
            var task = new TaskModel
            {
                Description  = input.Description,
                Title        = input.Title,
                State        = input.State,
                CreationTime = Clock.Now
            };

            //Saving entity with standard Insert method of repositories.
            return(_taskRepository.InsertAndGetId(task));
        }
        public async System.Threading.Tasks.Task Create(CreateTaskInput input)
        {
            try
            {
                //var task = ObjectMapper.Map<Acme.SimpleTaskApp.Tasks.Task>(input);
                //await _taskRepository.InsertAsync(task);
                //await CurrentUnitOfWork.SaveChangesAsync();

                //return ObjectMapper.Map<TaskListDto>(task);
                input.TenantId = 1;
                var task = ObjectMapper.Map<Acme.SimpleTaskApp.Tasks.Task>(input);
                await _taskRepository.InsertAsync(task);
                await CurrentUnitOfWork.SaveChangesAsync();
                //return ObjectMapper.Map<TaskListDto>(task);
            }
            catch (Exception e)
            {
                throw (e);
            }

        }
Esempio n. 28
0
        /// <summary>
        /// 添加一个任务
        /// </summary>
        /// <param name="input"></param>
        public void Create(CreateTaskInput input)
        {
            if (input == null)
            {
                Logger.Error($"{nameof(input)} should not be null.");
                return;
            }
            //映射到任务对象
            var task = Mapper.Map <Core.Entities.Task>(input);

            input.ApplicationName = input.ApplicationName.Trim();
            input.Arguments       = input.Arguments?.Trim();
            input.Cron            = input.Cron.Trim();
            input.Package         = input.Package.Trim();
            input.Name            = input.Name.Trim();

            //表示要创建议计划?
            if (input.Cron != Configuration.IngoreCron)
            {
                //计划工作
                var job = new SchedulerJobDto
                {
                    Id      = task.Id,
                    Name    = task.Name,
                    Cron    = input.Cron,
                    Url     = string.Format(Configuration.SchedulerCallback, task.Id),                 //设置回调
                    Content = JsonConvert.SerializeObject(new { TaskId = task.Id })
                };

                if (!task.Name.StartsWith(job.Group))
                {
                    task.Name = $"[{job.Group}]{task.Name}";
                }

                _schedulerAppService.Create(job); //创建计划
            }

            DbContext.Task.Add(task);             //添加任务
            DbContext.SaveChanges();
        }
Esempio n. 29
0
        // 实现IApplicationService接口方法
        public void CreateTask(CreateTaskInput input)
        {
            // 使用_TaskRepository执行数据库操作
            var task = _taskRepository.FirstOrDefault(p => p.Description == input.Description);

            if (task != null)
            {
                //
            }
            task = new Task {
                Description = input.Description
            };
            _taskRepository.Insert(task);

            // 记录日志(Logger 定义在 ApplicationService 类中)
            Logger.Info("Creating a new task with description: " + input.Description);

            //获取本地化文本 (L 是LocalizationHelper.GetString(...)的简写, 定义在 ApplicationService类中)
            var text = L("SampleLocalizableTextKey");

            //TODO: Add new task to database...
        }
        public void Create(CreateTaskInput input)
        {
            if (input == null)
            {
                Logger.LogError($"{nameof(input)} should not be null.");
                return;
            }
            var task = Mapper.Map <Domain.Entities.Task>(input);

            input.ApplicationName = input.ApplicationName.Trim();
            input.Arguments       = input.Arguments?.Trim();
            input.Cron            = input.Cron.Trim();
            input.Version         = input.Version.Trim();
            input.Name            = input.Name.Trim();

            var cron = task.Cron;

            task.Cron = DotnetSpiderConsts.UnTriggerCron;
            DbContext.Task.Add(task);
            DbContext.SaveChanges();

            if (cron != DotnetSpiderConsts.UnTriggerCron)
            {
                var taskId = task.Id.ToString();
                var job    = new SchedulerJobDto
                {
                    Id   = taskId,
                    Name = task.Name,
                    Cron = cron,
                    Url  = string.Format(Configuration.SchedulerCallback, taskId),
                    Data = JsonConvert.SerializeObject(new { TaskId = taskId })
                };
                _schedulerAppService.Create(job);
                task.Cron = cron;
                DbContext.Task.Update(task);
                DbContext.SaveChanges();
            }
        }
Esempio n. 31
0
        public int CreateTask(CreateTaskInput input)
        {
            Logger.Info("Creating a task for input:" + input);

            //获取当前用户
            var currentUser = AsyncHelper.RunSync(this.GetCurrentUserAsync);

            //判断用户是否有权限
            if (input.AssignedPersonId.HasValue && input.AssignedPersonId.Value != currentUser.Id)
            {
                PermissionChecker.Authorize(PermissionNames.Pages_Tasks_AssignPerson);
            }

            var task   = Mapper.Map <MyTask>(input);
            int result = taskRespository.InsertAndGetId(task);

            //只有创建成功才发送邮件通知
            if (result > 0)
            {
                task.CreationTime = Clock.Now;
                if (task.AssignedPersonId.HasValue)
                {
                    task.AssignedPerson = userRepository.Load(input.AssignedPersonId.Value);
                    var message = "You have been assigned one task into your todo list.";

                    notificationPublisher.Publish("NewTask", new MessageNotificationData(message), null, NotificationSeverity.Info, new[] { task.AssignedPerson.ToUserIdentifier() });
                }
            }
            return(result);
            //var task = new MyTask
            //{
            //    Title = input.Title,
            //    Description = input.Description,
            //    State = input.State,
            //    CreationTime = Clock.Now
            //};
            //return taskRespository.InsertAndGetId(task);
        }