/// <inheritdoc />
        public async Task <WorkableTask> GetTask(Guid id)
        {
            if (runningtasks.TryGetValue(id, out WorkableTask task))
            {
                return(task);
            }

            TaskDb dbtask = await loadtask.ExecuteEntityAsync(id);

            if (dbtask == null)
            {
                throw new NotFoundException(typeof(WorkableTask), id.ToString());
            }

            return(new WorkableTask {
                Id = dbtask.Id,
                WorkableId = dbtask.WorkableId,
                WorkableRevision = dbtask.WorkableRevision,
                WorkableName = dbtask.WorkableName,
                Parameters = dbtask.Parameters.Deserialize <Dictionary <string, object> >(),
                Status = dbtask.Status,
                Started = dbtask.Started,
                Finished = dbtask.Finished,
                Runtime = dbtask.Finished - dbtask.Started,
                Result = dbtask.Result.Deserialize <object>(),
                Log = new List <string>(dbtask.Log.Deserialize <string[]>() ?? new string[0])
            });
        }
Exemplo n.º 2
0
 protected override async Task OnInitializedAsync()
 {
     Programme       = (await ProgramContext.Get(ProgrammeId));
     TaskList        = TaskDb.GetAllTasksByProgrammeId(ProgrammeId);
     model.StartDate = DateTime.Now;
     model.EndDate   = DateTime.Now.AddDays(7);
 }
 protected override async Task OnInitializedAsync()
 {
     Group           = (await GroupContext.Get(GroupId));
     TaskList        = TaskDb.GetAllTasksByGroupId(GroupId);
     model.StartDate = DateTime.Now;
     model.EndDate   = DateTime.Now.AddDays(7);
 }
 internal virtual void ResolveTask(string remarks, TaskDb taskDb)
 {
     TaskStatus        = TaskStatus.Closed;
     ResolutionRemarks = remarks;
     this.ClosedDate   = DateTime.Now;
     taskDb.CreateTask(this);
 }
Exemplo n.º 5
0
    private void CheckCount()
    {
        TaskDb db = new TaskDb();

        _count = db.GetCount();
        db.Close();
    }
Exemplo n.º 6
0
 protected override async Task OnInitializedAsync()
 {
     Course          = (await CourseContext.Get(CourseId));
     TaskList        = TaskDb.GetAllTasksByCourseId(CourseId);
     model.StartDate = DateTime.Now;
     model.EndDate   = DateTime.Now.AddDays(7);
 }
Exemplo n.º 7
0
        private async Task AddTask()
        {
            TaskItem t = new TaskItem();

            t.Title        = model.Title;
            t.CreationDate = DateTime.Now;
            t.Description  = model.Description;
            t.StartDate    = model.StartDate;
            t.EndDate      = model.EndDate;
            t.Status       = "Aktiv";
            t.UpdateCount  = 0;

            if (selectedPriority == "Ej Prio")
            {
                t.Priority = 1;
            }
            else if (selectedPriority == "Låg")
            {
                t.Priority = 2;
            }
            else if (selectedPriority == "Medel")
            {
                t.Priority = 3;
            }
            else if (selectedPriority == "Hög")
            {
                t.Priority = 4;
            }
            else if (selectedPriority == "Omedelbar")
            {
                t.Priority = 5;
            }

            if (selectedConsequence == "Ingen")
            {
                t.Consequence = 1;
            }
            else if (selectedConsequence == "Låg")
            {
                t.Consequence = 2;
            }
            else if (selectedConsequence == "Medel")
            {
                t.Consequence = 3;
            }
            else if (selectedConsequence == "Hög")
            {
                t.Consequence = 4;
            }
            else if (selectedConsequence == "Dödlig")
            {
                t.Consequence = 5;
            }

            await TaskServ.CreateTaskProgramme(t, ProgrammeId);

            TaskList = TaskDb.GetAllTasksByProgrammeId(ProgrammeId);
            StateHasChanged();
            ModalMd = false;
        }
Exemplo n.º 8
0
    private void InitTasks()
    {
        TaskDb db = new TaskDb();

        availableTasksIds = db.GetAllIds();
        db.Close();
        usedTasksIds = new List <int>();
    }
Exemplo n.º 9
0
    public static TaskEntity GetDataById(int id)
    {
        TaskDb     db   = new TaskDb();
        TaskEntity task = db.GetEntityById(id);

        db.Close();
        return(task);
    }
 internal override void CreateTask(TaskDb taskDb)
 {
     base.CreateTask(taskDb);
     if (SupplierService == null)
     {
         SupplierService = new SupplierService();
     }
     SupplierService.SendMessage($"New Task - '{this.Title}' has been created for you.", this.TaskId);
 }
 internal override void ResolveTask(string remarks, TaskDb taskDb)
 {
     base.ResolveTask(remarks, taskDb);
     if (SupplierService == null)
     {
         SupplierService = new SupplierService();
     }
     SupplierService.SendMessage("This issue has been closed and customer has been informed.", this.TaskId);
 }
Exemplo n.º 12
0
    private List <int> FilterByLessLevelIn(List <int> idsIn)
    {
        TaskDb     db          = new TaskDb();
        List <int> idsForLevel = db.GetIdsForLessLevel(GameProgress.Level);

        db.Close();
        List <int> result = idsIn.Intersect(idsForLevel).ToList(); //probably better to filter in sql query

        return(result);
    }
Exemplo n.º 13
0
 public void storeTask(SkTaskModel recognitionTask)
 {
     if (!Exist(recognitionTask))
     {
         lock (TaskDb)
         {
             using (StreamWriter sw = File.AppendText(this.TaskDbFilePath))
             {
                 sw.WriteLine($"{recognitionTask.Path}; {recognitionTask.AudioUrl}; {recognitionTask.TaskId}");
                 TaskDb.Add(recognitionTask.Path, recognitionTask);
                 sw.Flush();
             }
         }
     }
 }
Exemplo n.º 14
0
        private bool CheckPermission(bool taskManagementRole, long UserId, TaskDb oldTask = null, TaskDTO newTask = null)
        {
            TaskDTO task1 = (TaskDTO)oldTask ?? null;
            TaskDTO task2 = newTask ?? null;
            //use local variables to avoid problems
            bool assignedToSelf = false;
            bool assignedBySelf = false;
            bool advancedEdits  = false;

            if (task1 != null && task2 == null)
            {
                task2 = task1;
            }
            else if (task2 != null && task1 == null)
            {
                task1 = task2;
            }
            else if (task1 != null && task2 != null)
            { //Good!
            }
            else
            {
                throw new Exception("In the Task Controller, both new and old Tasks are null!");
            }

            //You have to check if the new and old job are both self-assigned. Otherwise the user will have admin right over the job abd be able to assign it to someone else
            assignedToSelf = task1.assignedToID == UserId && task2.assignedToID == UserId;
            assignedBySelf = task1.assignedByID == UserId && task2.assignedByID == UserId;

            advancedEdits = (task1.payRate - task2.payRate) > 0.01 || task1.dueDate != task2.dueDate || task1.assignedToID != task2.assignedToID ||
                            task1.type != task2.type || task1.name != task2.name || task1.taskDescription != task2.taskDescription || task1.markedDeleted != task2.markedDeleted;

            bool[] permission = Permissions.First(p => p[0] == taskManagementRole && p[1] == assignedToSelf && p[2] == assignedBySelf);

            //move local to global variables
            AssignedToSelf = assignedToSelf;
            AssignedBySelf = assignedBySelf;
            AdvancedEdits  = advancedEdits;

            if (AdvancedEdits)
            {
                return(permission[4]);
            }
            else
            {
                return(permission[3]);
            }
        }
Exemplo n.º 15
0
        private void loadTasksDbFile()
        {
            if (!new FileInfo(this.TaskDbFilePath).Exists)
            {
                log.Warning($"Task file {this.TaskDbFilePath} not exists");
                return;
            }

            SkTaskModel[] tasks = File.ReadAllLines(this.TaskDbFilePath)
                                  .Select(SplitAndFill)
                                  .ToArray();

            foreach (SkTaskModel t in tasks)
            {
                TaskDb.Add(t.Path, t);
            }
        }
 public RetrievePriorityListDataService()
 {
     _taskDatabase = new TaskDb();
 }
Exemplo n.º 17
0
        /// <summary> Edits a job that already exists, according to the truth Table. You can wind back time, we do not check for it. </summary>
        /// <param name="id">Id of the job you want to alter</param>
        /// <param name="newTask">Job to be added</param>
        /// <returns></returns>
        public async Task <dynamic> Put([FromUri] long id, [FromBody]  DTO.TaskDTO newTask)
        {
            bool AdvancedEdits   = false;
            long UserId          = long.Parse(User.Identity.GetUserId());
            bool TimeAdded       = false;
            bool anythingChanged = false;

            //Check Data integrity
            HttpResponseMessage responce = Utils.CheckModel(newTask, Request);

            if (!responce.IsSuccessStatusCode)
            {
                return(responce);
            }

            TaskDb oldTask = await db.Tasks.Where(f => f.Id == id).Include(f => f.ForField)
                             .Include(f => f.ForField.OnOrganisation).Include(f => f.ForField.OnOrganisation.Bonds).FirstOrDefaultAsync();

            if (oldTask == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ErrorResponse.DoesntExist));
            }

            if (!oldTask.ForField.OnOrganisation.Bonds.Any(p => p.PersonID == newTask.assignedToID))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ErrorResponse.PersonNotAvaliable));
            }

            //Setup variables
            string role = OrganisationsController.FindAndGetRole(oldTask.ForField.OnOrganisation, UserId);

            TaskManagementRole = BondDb.CanAssignJobsToOthers.Contains(role);


            TimeAdded = oldTask.TimeTaken < newTask.timeTaken;


            anythingChanged = AdvancedEdits || TimeAdded || newTask.state != oldTask.State;


            //Check user's access
            if (role == BondDb.RoleNone)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ErrorResponse.CantView));
            }


            bool[] permission = Permissions.First(p => p[0] == TaskManagementRole && p[1] == AssignedToSelf && p[2] == AssignedBySelf);

            if (!CheckPermission(TaskManagementRole, UserId, oldTask, newTask))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ErrorResponse.PermissionsTooLow));
            }


            if (anythingChanged)
            {
                eventLog = JsonConvert.DeserializeObject <List <TaskEvent> >(oldTask.EventLog);

                oldTask.Name            = newTask.name;
                oldTask.TaskDescription = newTask.taskDescription;
                oldTask.PayRate         = newTask.payRate;
                oldTask.State           = newTask.state;
                oldTask.DueDate         = newTask.dueDate;
                oldTask.TimeTaken       = newTask.timeTaken;
                oldTask.MarkedDeleted   = newTask.markedDeleted;
                oldTask.AssignedToID    = newTask.assignedToID;
                oldTask.UpdatedOn       = DateTime.UtcNow;


                eventLog.Add(new TaskEvent((DTO.TaskDTO)oldTask, UserId));
                oldTask.EventLog = JsonConvert.SerializeObject(eventLog);
                if (newTask.state == TaskDb.StateFinished)
                {
                    oldTask.DateFinished = DateTimeOffset.UtcNow;
                }

                await db.SaveChangesAsync();
            }

            return(Ok((TaskDTO)oldTask));
        }
Exemplo n.º 18
0
        /// <summary> Creates a job. You can assign a job to yourself, or to staff at this organisation if you role is manager or owner </summary>
        /// <param name="newJob">Job to be added</param>
        /// <returns>200 if successfull, and ErrorResponce Otherwise</returns>
        public async Task <dynamic> Post([FromBody] DTO.TaskDTO newJob)
        {
            if (newJob != null)
            {
                newJob.oldObject = false;
            }

            long UserId = long.Parse(User.Identity.GetUserId());

            HttpResponseMessage responce = Utils.CheckModel(newJob, Request);

            if (!responce.IsSuccessStatusCode)
            {
                return(responce);
            }

            var theField = await db.Fields.Where(f => f.Id == newJob.forFieldID).Include(f => f.OnOrganisation).Include(f => f.OnOrganisation.Bonds).FirstOrDefaultAsync();

            if (theField == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ErrorResponse.DoesntExist));
            }

            if (!theField.OnOrganisation.Bonds.Any(p => p.PersonID == newJob.assignedToID))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ErrorResponse.PersonNotAvaliable));
            }

            string role              = OrganisationsController.FindAndGetRole(theField.OnOrganisation, UserId);
            bool   editRights        = BondDb.CanAssignJobsToOthers.Contains(role);
            bool   requestAuthorised = false;

            //Check user's access
            if (role == BondDb.RoleNone)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ErrorResponse.CantView));
            }

            //Self-create
            if (newJob.assignedToID == UserId || editRights)
            {
                requestAuthorised = true;
            }

            TaskDb job = new TaskDb
            {
                Name            = newJob.name,
                TaskDescription = newJob.taskDescription,
                PayRate         = newJob.payRate,
                State           = newJob.state,
                Type            = newJob.type,
                DueDate         = newJob.dueDate,
                EventLog        = string.Empty,

                AssignedByID = UserId,
                AssignedToID = newJob.assignedToID,
                ForFieldID   = theField.Id,

                TimeTaken     = 0,
                CreatedOn     = DateTime.UtcNow,
                UpdatedOn     = DateTime.UtcNow,
                MarkedDeleted = false
            };

            eventLog.Add(new TaskEvent((DTO.TaskDTO)job, UserId, "Job crated"));
            job.EventLog = JsonConvert.SerializeObject(eventLog);

            if (requestAuthorised)
            {
                db.Tasks.Add(job);
                await db.SaveChangesAsync();

                //If it makes sence, send a mesage
                if (newJob.assignedToID != UserId && newJob.state != TaskDb.StateFinished)
                {
                    var parties = await db.Users.Where(p => p.Id == newJob.assignedToID || p.Id == UserId).ToArrayAsync();

                    long   phone     = parties.First(p => p.Id == newJob.assignedToID).PhoneNumber;
                    string actorName = parties.First(p => p.Id == UserId).FirstName + " " + parties.First(p => p.Id == UserId).LastName;
                    string message   = "Hive: " + String.Format("{0} has assigned you a {1} task at the {2} field. For more details, see Tasks in the Hive app on your phone", actorName, newJob.type, theField.Name);
                    SMSService.SendMessage(phone.ToString(), message); //We don;t want to await an SMS, really
                }

                return(Ok((DTO.TaskDTO)job));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ErrorResponse.IllegalChanges));
            }
        }
Exemplo n.º 19
0
 internal virtual void SaveTask(TaskDb taskDb)
 {
     taskDb.CreateTask(this);
 }
Exemplo n.º 20
0
 public bool Exist(SkTaskModel recognitionTask)
 {
     return(TaskDb.ContainsKey(recognitionTask.Path));
 }
Exemplo n.º 21
0
 protected AccountDataServiceBase()
 {
     _taskDatabase = new TaskDb();
 }
 public RetrieveCategoryListDataService()
 {
     _taskDatabase = new TaskDb();
 }
 public TaskController()
 {
     taskDb = new TaskDb();
 }
Exemplo n.º 24
0
 public UserService()
 {
     userDb = new TaskDb();
 }
Exemplo n.º 25
0
 internal virtual void CreateTask(TaskDb taskDb)
 {
     TaskStatus      = TaskStatus.Open;
     this.CreateDate = DateTime.Now;
     taskDb.CreateTask(this);
 }
Exemplo n.º 26
0
 public TaskDataServices()
 {
     _taskDatabase = new TaskDb();
 }
Exemplo n.º 27
0
 public SupplierService()
 {
     taskDb = new TaskDb();
 }
Exemplo n.º 28
0
 public RetrieveStatusListDataService()
 {
     _taskDatabase = new TaskDb();
 }
Exemplo n.º 29
0
 public TaskManagerService()
 {
     taskDb = new TaskDb();
 }