public virtual IActionResult TaskUpdate(ScheduleTaskModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageScheduleTasks))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(ErrorJson(ModelState.SerializeErrors()));
            }

            //try to get a schedule task with the specified id
            var scheduleTask = _scheduleTaskService.GetTaskById(model.Id)
                               ?? throw new ArgumentException("Schedule task cannot be loaded");

            scheduleTask = model.ToEntity(scheduleTask);

            _scheduleTaskService.UpdateTask(scheduleTask);

            //activity log
            _customerActivityService.InsertActivity("EditTask",
                                                    string.Format(_localizationService.GetResource("ActivityLog.EditTask"), scheduleTask.Id), scheduleTask);

            return(new NullJsonResult());
        }
예제 #2
0
        public virtual async Task <IActionResult> TaskUpdate(ScheduleTaskModel model)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageScheduleTasks))
            {
                return(AccessDeniedView());
            }

            //try to get a schedule task with the specified id
            var scheduleTask = await _scheduleTaskService.GetTaskByIdAsync(model.Id)
                               ?? throw new ArgumentException("Schedule task cannot be loaded");

            //To prevent inject the XSS payload in Schedule tasks ('Name' field), we must disable editing this field,
            //but since it is required, we need to get its value before updating the entity.
            if (!string.IsNullOrEmpty(scheduleTask.Name))
            {
                model.Name = scheduleTask.Name;
                ModelState.Remove(nameof(model.Name));
            }

            if (!ModelState.IsValid)
            {
                return(ErrorJson(ModelState.SerializeErrors()));
            }

            scheduleTask = model.ToEntity(scheduleTask);

            await _scheduleTaskService.UpdateTaskAsync(scheduleTask);

            //activity log
            await _customerActivityService.InsertActivityAsync("EditTask",
                                                               string.Format(await _localizationService.GetResourceAsync("ActivityLog.EditTask"), scheduleTask.Id), scheduleTask);

            return(new NullJsonResult());
        }
예제 #3
0
        public virtual IActionResult TaskUpdate(ScheduleTaskModel model)
        {
            if (!ModelState.IsValid)
            {
                return(ErrorJson(ModelState.SerializeErrors()));
            }

            //try to get a schedule task with the specified id
            var scheduleTask = _scheduleTaskService.GetTaskById(model.Id)
                               ?? throw new ArgumentException("Schedule task cannot be loaded");

            scheduleTask = model.ToEntity(scheduleTask);

            _scheduleTaskService.UpdateTask(scheduleTask);

            return(new NullJsonResult());
        }
        public async Task <IActionResult> EditScheduler(ScheduleTaskModel model, bool continueEditing)
        {
            var scheduleTask = await _scheduleTaskService.GetTaskById(model.Id);

            if (ModelState.IsValid)
            {
                scheduleTask = model.ToEntity(scheduleTask);
                await _scheduleTaskService.UpdateTask(scheduleTask);

                Success(_translationService.GetResource("Admin.System.ScheduleTasks.Updated"));
                if (continueEditing)
                {
                    return(await EditScheduler(model.Id));
                }
                return(RedirectToAction("List"));
            }
            model.ScheduleTaskName = scheduleTask.ScheduleTaskName;
            model.Type             = scheduleTask.Type;
            model = await PrepareStores(model);

            Error(ModelState);

            return(View(model));
        }