public bool CanMoveNext(ref int nextIndex, TaskContract currentResult)
            {
                if (_stopWatch.ElapsedTicks > maxMilliseconds)
                {
                    return(false);
                }

                return(true);
            }
Пример #2
0
 public void deleteTaskContract(TaskContract item)
 {
     if (item == null)
     {
         throw new ArgumentNullException(nameof(item));
     }
     _taskContractRepository.Delete(item);
     _eventPublisher.EntityDeleted(item);
 }
Пример #3
0
        public IHttpActionResult Put(TaskContract taskContract)
        {
            var mappedEntity  = Mapper.Map <TaskContract, Task>(taskContract);
            var updatedEntity = _taskService.Save(mappedEntity);

            if (updatedEntity != null)
            {
                return(Ok());
            }

            return(StatusCode(HttpStatusCode.InternalServerError));
        }
        public string AddTask(TaskContract data)
        {
            var repo    = _unitWork.Repository <Task>();
            var project = Mapper.Map <Task>(data);

            try
            {
                if (data.IsParentTask)
                {
                    var parentRepo = _unitWork.Repository <ParentTask>();
                    var ParentTask = Mapper.Map <ParentTask>(data);
                    if (data.ParentId == 0)
                    {
                        parentRepo.Insert(ParentTask);
                    }
                    else
                    {
                        parentRepo.Update(ParentTask);
                    }
                }
                else
                {
                    if (data.Id == 0)
                    {
                        repo.Insert(project);
                    }
                    else
                    {
                        repo.Update(project);
                    }

                    if (data?.Manager?.Id != null && data?.Manager?.Id != 0)
                    {
                        var userRepo = _unitWork.Repository <User>();
                        var user     = userRepo.GetById(data.Manager.Id);
                        if (user != null)
                        {
                            user.TaskId = project.Id;
                        }
                        userRepo.Update(user);
                    }
                }

                _unitWork.Save();

                return("Success");
            }
            catch
            {
                throw;
            }
        }
Пример #5
0
 public void InsertTaskContract(TaskContract item)
 {
     if (item == null)
     {
         throw new ArgumentNullException(nameof(item));
     }
     if (_taskContractRepository.Table.Any(c => c.TaskId == item.TaskId && c.ContractId == item.ContractId))
     {
         return;
     }
     _taskContractRepository.Insert(item);
     _eventPublisher.EntityInserted(item);
 }
Пример #6
0
            public bool CanMoveNext(ref int nextIndex, TaskContract currentResult)
            {
                if (_iterations >= _maxTasksPerIteration - 1)
                {
                    _iterations = 0;

                    return(false);
                }

                _iterations++;

                return(true);
            }
Пример #7
0
        public ActionResult Update(TaskContract model)
        {
            if (ModelState.IsValid)
            {
                var request = new RestRequest("tasks", Method.PUT);
                AddAuthHeaders(ref request, HttpMethod.Put.Method, "tasks");
                model.ModifiedOn = DateTime.Now;
                request.AddJsonBody(model);

                IRestResponse response = RestClient.Execute(request);
                return(response.StatusCode != HttpStatusCode.OK ? new HttpStatusCodeResult(HttpStatusCode.InternalServerError) : new HttpStatusCodeResult(HttpStatusCode.OK));
            }

            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
        }
Пример #8
0
        public async Task CreateTask(TaskContract contract, string ownerId)
        {
            var group = await _repository.GetGroup(contract.GroupId);

            if (group.OwnerId != ownerId && group.CoOwnerId != ownerId)
            {
                throw new UserNotOwnerException();
            }
            if (group.Tasks.Any(t => t.Name == contract.Name))
            {
                throw new NameAlreadyUsedException(contract.Name);
            }
            var task = _taskModelMapper.Map(contract);
            await _repository.AddTask(task);
        }
        public bool CanMoveNext(ref int nextIndex, TaskContract currentResult, int coroutineCount)
        {
            //never stops until maxMilliseconds is elapsed or Break.AndResumeNextIteration is returned
            if (_stopWatch.ElapsedTicks > maxTicks)
            {
                _stopWatch.Reset();
                _stopWatch.Start();

                return(false);
            }

            if (nextIndex >= coroutineCount)
            {
                nextIndex = 0;     //restart iteration and continue
            }
            return(true);
        }
Пример #10
0
        public async Task EditTask(TaskContract contract, string userId)
        {
            var group = await GetGroup(contract.GroupId, userId);

            if (group.Tasks.Any(p => p.Name == contract.Name && p.Id != contract.Id))
            {
                throw new NameAlreadyUsedException(contract.Name);
            }

            var storageTask = group.Tasks.FirstOrDefault(t => t.Id == contract.Id);

            if (storageTask is null)
            {
                throw new TasksNotFoundException(contract.Id);
            }
            var task        = _taskModelMapper.Map(contract);
            var updatedTask = storageTask.Update(task);
            await _repository.UpdateTask(updatedTask);
        }
        public override ITask BuildTask(IVocabBank vocabBank)
        {
            var questionTranslation = RandomPicker.PickItem(vocabBank.Translations);
            bool isReverse = IsReverseDirection();
            IWord question;
            IWord correctAnswer;
            Func<ITranslation, IWord> answersPicker;
            if (isReverse)
            {
                question = questionTranslation.Target;
                correctAnswer = questionTranslation.Source;
                answersPicker = translation => translation.Source;
            }
            else
            {
                question = questionTranslation.Source;
                correctAnswer = questionTranslation.Target;
                answersPicker = translation => translation.Target;
            }

            var questionBlacklist = SynonymSelector.GetSimilarTranslations(questionTranslation, vocabBank.Translations);
            var answers = RandomPicker
                .PickItems(vocabBank.Translations, DefaultAnswersCount, questionBlacklist)
                .Select(answersPicker)
                .ToList();

            answers.Insert(RandomPicker.PickInsertIndex(answers), correctAnswer);

            var result = new TaskContract
            {
                Answers = answers,
                CorrectAnswer = correctAnswer,
                Question = question
            };

            if (TaskValidator.IsValidTask(result))
            {
                return result;
            }

            throw new ArgumentException("Task created incorrectly.", "vocabBank");
        }
Пример #12
0
 public Task Map(TaskContract contract) =>
Пример #13
0
        public bool MoveNext()
        {
            if (_current.Continuation != null)
            {
                //a task is waiting to be completed, spin this one
                if (_current.Continuation.Value.isRunning == true)
                {
                    return(true);
                }

                //this is a continued task
                if (_taskContinuation._continuingTask != null)
                {
                    //the child task is telling to interrupt everything!
                    var currentBreakIt = _taskContinuation._continuingTask.Current.breakIt;
                    _taskContinuation._continuingTask = null;

                    if (currentBreakIt == Break.AndStop)
                    {
                        return(false);
                    }
                }
            }

            if (_current.enumerator != null)
            {
                if (_current.isTaskEnumerator)
                {
                    _taskContinuation._continuingTask = (IEnumerator <TaskContract>)_current.enumerator;

                    //a new TaskContract is created, holding the continuationEnumerator of the new task
                    //TODO Optimize this:
                    TTask tempQualifier = ((TTask)_taskContinuation._continuingTask);
                    var   continuation  =
                        new LeanSveltoTask <TTask>().Run(_taskContinuation._runner, ref tempQualifier /*, false*/);

                    _current = continuation.isRunning == true ?
                               new TaskContract(continuation) :
                               new TaskContract(); //end of the enumerator, reset TaskContract?

                    return(true);
                }

                if (_current.enumerator.MoveNext() == true)
                {
                    return(true);
                }

                _current = new TaskContract();  //end of the enumerator, reset TaskContract?
            }

            //continue the normal execution of this task
            if (task.MoveNext() == false)
            {
                return(false);
            }

            _current = task.Current;

            if (_current.yieldIt == true)
            {
                return(true);
            }

            if (_current.breakIt == Break.It || _current.breakIt == Break.AndStop || _current.hasValue == true)
            {
                return(false);
            }

            return(true);
        }
Пример #14
0
 public void View(TaskContract task)
 {
     throw new NotImplementedException();
 }
Пример #15
0
        public virtual IActionResult _Create(TaskModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageContract))
            {
                return(JsonErrorMessage());
            }
            if (ModelState.IsValid)
            {
                var  note            = "";
                var  noti            = "admin.common.Added";
                Task item            = new Task();
                int  PreParentTaskId = model.ParentId;
                if (model.Id > 0)
                {
                    item            = _workTaskService.GetTaskById(model.Id);
                    PreParentTaskId = item.ParentId.GetValueOrDefault();
                    note            = MessageReturn.CreateSuccessMessage("oldData", item.ToModel <TaskModel>()).toStringJson();
                }
                _taskModelFactory.PrepareTask(item, model);
                if (model.Id > 0)
                {
                    _workTaskService.UpdateTask(item);
                    _taskModelFactory.InsertContractLog(item);
                    var TaskLogModel = new TaskLogModel
                    {
                        TaskId = item.Id,
                        Note   = "Cập nhật công việc "
                    };
                    _taskModelFactory.InsertTaskLog(TaskLogModel);
                    noti = "admin.common.Updated";
                    //kiem tra xem co thay doi cha ko, neu co thay doi cha thi phai update lai cha
                    //if(PreParentTaskId!=model.ParentId && PreParentTaskId>0)
                    //{
                    //    _workTaskService.UpdateTaskAmount(PreParentTaskId);
                    //}
                }
                else
                {
                    //neu them cong viec vao hop dong thi mac dinh cong viec o trang thai dang working
                    if (model.ContractId > 0)
                    {
                        var contract1 = _contractService.GetContractById(model.ContractId);
                        if (contract1.StatusId != (int)ContractStatus.Draf)
                        {
                            item.StatusId = (int)TaskStatus.Working;
                        }
                    }
                    _workTaskService.InsertTask(item);
                    //lay lai thong tin da insert
                    item = _workTaskService.GetTaskById(item.Id);
                    _taskModelFactory.InsertContractLog(item);
                    var TaskLogModel = new TaskLogModel
                    {
                        TaskId = item.Id,
                        Note   = "Thêm mới công việc "
                    };
                    _taskModelFactory.InsertTaskLog(TaskLogModel);
                }
                if (model.AppendixId > 0)
                {
                    var taskContract = new TaskContract
                    {
                        TaskId      = item.Id,
                        ContractId  = model.AppendixId,
                        CreatorId   = _workContext.CurrentCustomer.Id,
                        CreatedDate = DateTime.Now,
                        Note        = note,
                    };
                    _workTaskService.InsertTaskContract(taskContract);
                }
                var contract = _contractService.GetContractById(item.ContractId);
                //neu hop dong dang chay va co ContractTypeId thì chay lai gt do dang
                if (contract != null && contract.StatusId != (int)ContractStatus.Draf && item.ContractTypeId > 0 && item.StatusId != (int)TaskStatus.Draf)
                {
                    UpdateContractUnfinish(item.Id);
                }
                return(JsonSuccessMessage(_localizationService.GetResource(noti), item.ToModel <TaskModel>()));
            }
            var list = ModelState.Values.Where(c => c.Errors.Count > 0).ToList();

            return(JsonErrorMessage("Error", list));
        }
Пример #16
0
 public TaskContract AddTask(TaskContract task)
 {
     throw new NotImplementedException();
 }
        public bool MoveNext()
        {
            if (_current.Continuation != null)
            {
                //a task is waiting to be completed, spin this one
                if (_current.Continuation.Value.isRunning == true)
                {
                    return(true);
                }

                //this is a continued task
                if (_taskContinuation._continuingTask != null)
                {
                    //the child task is telling to interrupt everything!
                    var currentBreakIt = _taskContinuation._continuingTask.Current.breakIt;
                    _taskContinuation._continuingTask = null;

                    if (currentBreakIt == Break.AndStop)
                    {
                        return(false);
                    }
                }
            }

            if (_current.enumerator != null)
            {
                if (_current.isTaskEnumerator)
                {
                    _taskContinuation._continuingTask = (IEnumerator <TaskContract>)_current.enumerator;

                    //a new TaskContract is created, holding the continuationEnumerator of the new task
                    var continuation =
                        ((TTask)_taskContinuation._continuingTask).RunImmediate(_taskContinuation._runner);

                    _current = continuation.isRunning == true ?
                               new TaskContract(continuation) :
                               new TaskContract(); //todo what was this case for?

                    return(true);
                }

                if (_current.enumerator.MoveNext() == true)
                {
                    return(true);
                }

                _current = new TaskContract();  //todo what was this case for?
            }

            //continue the normal execution of this task
            if (task.MoveNext() == false)
            {
                return(false);
            }

            _current = task.Current;

            if (_current.yieldIt == true)
            {
                return(true);
            }

            if (_current.breakIt == Break.It || _current.breakIt == Break.AndStop || _current.hasValue == true)
            {
                return(false);
            }

            return(true);
        }
Пример #18
0
 public HttpResponseMessage UpdateTasks([FromBody] TaskContract data)
 {
     return(Request.CreateResponse(HttpStatusCode.OK, _service.AddTask(data)));
 }
Пример #19
0
 public bool CanMoveNext(ref int nextIndex, TaskContract currentResult, int coroutinesCount)
 {
     return(true);
 }