コード例 #1
0
        //create assigned tasks
        public void createAssignedTask(string taskName, string username)
        {
            using (var db = new HealthModelsDataContext())
            {
                Task task = db.Tasks.SingleOrDefault(targetTask => targetTask.taskName.Equals(taskName));
                User user = db.Users.SingleOrDefault(targetUser => targetUser.userName.Equals(username));

                if (task != null && user != null)
                {
                    var assignedTask = new AssignedTask();

                    assignedTask.taskId = task.id;
                    assignedTask.userId = user.id;

                    db.AssignedTasks.InsertOnSubmit(assignedTask);
                    db.SubmitChanges();
                }
            }
        }
コード例 #2
0
        public void When_TheStartTimeOfTheNewAssignmentIsGreaterThanTheEndTimeOfTheLastAssignment_Expects_False(IEnumerable <AssignedTask> assignedTasks)
        {
            //arrange
            var newAssignment = new AssignedTask
            {
                EmployeeId     = 26,
                AssignmentDate = new DateTime(2018, 08, 20),
                StartTime      = new TimeSpan(10, 00, 00),
                EndTime        = new TimeSpan(13, 00, 00),
            };
            var assignments = assignedTasks.ToList();

            //act
            var result = validateAssignment
                         .IsTheStartTimeOfTheNewAssignmentGreaterThanTheEndTimeOfTheLastAssignment(newAssignment, assignments);

            //assert
            Assert.That(result, Is.False);
        }
コード例 #3
0
        public void When_TotalAssignedHoursOfEmployeeOnDateIs7_Expects_7(IEnumerable <AssignedTask> assignedTasks)
        {
            //arrange
            var newAssignment = new AssignedTask
            {
                EmployeeId     = 26,
                AssignmentDate = new DateTime(2018, 08, 21),
                StartTime      = new TimeSpan(18, 00, 00),
                EndTime        = new TimeSpan(19, 00, 00),
            };
            var assignments = assignedTasks.ToList();
            var expected    = 7d;

            //act
            var result = validateAssignment.GetTotalAssignedHoursOfEmployeeOnDate(newAssignment, assignments);

            //assert
            Assert.AreEqual(result, expected);
        }
コード例 #4
0
        public void When_TotalAssignedHoursOfEmployeeOnDateIs9_Expects_True()
        {
            //arrange
            var newAssignment = new AssignedTask
            {
                EmployeeId     = 26,
                AssignmentDate = new DateTime(2018, 08, 21),
                StartTime      = new TimeSpan(18, 00, 00),
                EndTime        = new TimeSpan(19, 00, 00),
            };
            var totalHoursAssignedAlready = 8d;
            var maxHoursPerDay            = 8d;

            //act
            var result = validateAssignment.ExceedsMaxHoursPerDay(newAssignment, totalHoursAssignedAlready, maxHoursPerDay);

            //assert
            Assert.That(result, Is.True);
        }
コード例 #5
0
        public void When_CurrentDateIs12December2018_Expects_LastDateOfWeek15December2018()
        {
            //arrange
            var newAssignment = new AssignedTask
            {
                EmployeeId     = 26,
                AssignmentDate = new DateTime(2018, 12, 12),
                StartTime      = new TimeSpan(10, 00, 00),
                EndTime        = new TimeSpan(13, 00, 00),
            };

            var expected = new DateTime(2018, 12, 15);

            //act
            var result = validateAssignment
                         .GetEndDateOfWeek(newAssignment);

            //assert
            Assert.That(result, Is.EqualTo(expected));
        }
コード例 #6
0
        public string AssignedTask(AssignedtaskViewModel assignedTask)
        {
            try
            {
                var staffid = _dbContext.StaffDetails.Where(x => x.ID == assignedTask.StaffID).FirstOrDefault();
                if (staffid.IsAvailable != false)
                {
                    var TaskIid = _dbContext.TaskDetails.Where(x => x.ID == assignedTask.TaskID).FirstOrDefault();
                    if (TaskIid.Hour >= assignedTask.AsiggnedHours)
                    {
                        AssignedTask astask = new AssignedTask
                        {
                            StaffID       = staffid,
                            TaskID        = TaskIid,
                            AsiggnedHours = assignedTask.AsiggnedHours,
                            AssignedDate  = assignedTask.AssignedDate
                        };
                        var taskRemainingHour = (TaskIid.Hour - assignedTask.AsiggnedHours);
                        _dbContext.AssignedTasks.Add(astask);
                        _dbContext.TaskDetails.Where(x => x.ID == assignedTask.TaskID).ToList().ForEach(i => i.Hour          = taskRemainingHour);
                        _dbContext.StaffDetails.Where(x => x.ID == assignedTask.StaffID).ToList().ForEach(i => i.IsAvailable = false);


                        _dbContext.SaveChanges();
                        return("Added");
                    }
                    else
                    {
                        return("Please provide hours less than or equal to : " + TaskIid.Hour);
                    }
                }
                else
                {
                    return("Staff is Already working on some task.");
                }
            }
            catch (Exception ex)
            {
                return("Exception while assigning task" + ex.Source);
            }
        }
コード例 #7
0
ファイル: Objectiver.cs プロジェクト: chengyimingvb/CYMUni
        public virtual void Init(BaseUnit selfUnit)
        {
            if (selfUnit == null)
            {
                CLog.Error("Objectiver.Init:selfUnit==null");
                return;
            }
            SelfBaseUnit = selfUnit;
            OnAddConfig();
            Enum <TEnum> .ForIndex(x =>
            {
                int enumIndex = x;
                AssignedTask.Add(enumIndex, new HashSet <Task>());
                TypedTask.Add(enumIndex, new List <Task>());
                TypeIdles.Add(enumIndex, new HashList <TUnit>());
                if (!ConfigData.ContainsKey(enumIndex))
                {
                    CLog.Error("错误!{0}:没有配置ConfigData", x.ToString());
                }
            });

            BaseUnit.Callback_OnRealDeathG += OnRealDeathG;
        }
コード例 #8
0
        public double GetTotalAssignedHoursOfEmployeeOnDate(AssignedTask newAssignment, List <AssignedTask> assignedTasks)
        {
            var assignments = assignedTasks.ToList();

            var employeeAssignments = from item in assignments
                                      where item.AssignmentDate.Date >= newAssignment.AssignmentDate.Date &&
                                      item.EmployeeId == newAssignment.EmployeeId
                                      select item;

            //this can cause error because of date conversion
            //double totalAssignedHours = assignedTasks
            //    .Where(a => a.EmployeeId == newAssignment.EmployeeId
            //        && Convert.ToDateTime(a.AssignmentDate.Date) == Convert.ToDateTime(newAssignment.AssignmentDate.Date))
            //    .Sum(a => (new TimeSpan(a.EndTime.Ticks - a.StartTime.Ticks)).TotalHours);


            //WorkAround:
            double totalAssignedHours = employeeAssignments
                                        .Sum(a => (new TimeSpan(a.EndTime.Ticks - a.StartTime.Ticks)).TotalHours);


            return(totalAssignedHours);
        }
コード例 #9
0
        public AssignedTasksResponse GetApprovedTasksForCurrentUser(int currentPageIndex, int recordsCount)
        {
            var user           = _commonService.GetCurrentUserContext();
            var response       = new AssignedTasksResponse();
            var totalRecords   = 0;
            var taskStatusList = new List <AssignedTask>();
            //var dbApprovedApplicants = _contributorRepository.GetAssignedTask(user.UserId).Where(x => x.task.STATUS == Enums.TaskStatus.Assigned.ToString() && x.user.ID == user.UserId);
            var dbApprovedApplicants = _contributorRepository.GetAssignedTask(user.UserId, currentPageIndex, recordsCount, out totalRecords);

            response.TotalRecords = totalRecords;
            foreach (var dbApprovedApplicant in dbApprovedApplicants)
            {
                var taskStatus = new AssignedTask();
                taskStatus.Applicant = _approvedApplicantModelFactory.CreateModel <DCode.Models.ResponseModels.Contributor.Contributor>(dbApprovedApplicant);
                taskStatus.Task      = _taskModelFactory.CreateModel <Models.ResponseModels.Task.Task>(dbApprovedApplicant.task);
                taskStatus.Applicant.ProjectManagerName = taskStatus.Task.FullName;
                taskStatus.ApprovedApplicantId          = dbApprovedApplicant.ID;
                taskStatusList.Add(taskStatus);
                //totalRecords++;
            }
            response.AssignedTasks = taskStatusList;
            response.TotalRecords  = totalRecords;
            return(response);
        }
コード例 #10
0
 public void AssignMemberNewTask(AssignedTask newTask)
 {
     if (assignedTasks.ContainsKey(newTask.performingMember)) throw new System.Exception("Trying to assign task to member with task!");
     if (newTask.preconditionCheck.Invoke())
     {
         newTask.DoStartAction();
         assignedTasks.Add(newTask.performingMember,newTask);
         MapManager.main.memberTokens[newTask.performingMember].NewTaskSet(newTask.GetTaskSprite());
         PartyStatusCanvasHandler.main.RefreshAssignmentButtons(selectedMembers);
         //MapManager.main.memberTokens[newTask.performingMember].moved=true;
     }
 }
コード例 #11
0
 private void OnAssigned(AssignedTask @event)
 {
     AssignedTo = @event.AssignedTo;
 }
コード例 #12
0
 private string Println(object oo)
 {
     return(oo switch {
         AssignedTask x => $"{x.TaskId}: {x.AssignedTo} - {x.AssignedBy}",
         _ => "Not found"
     });
コード例 #13
0
        public bool ValidateAssignment(AssignedTask assignedTask)
        {
            var assignmentIsValid = true;
            var maxHoursPerDay    = 8;
            var maxDaysPerWeek    = 5;

            //Linq to entities does not support Convert.ToDateTime
            //var assignments = assignedTaskService.Get(a => a.EmployeeId == assignedTask.EmployeeId
            //                        && Convert.ToDateTime(a.AssignmentDate.Date) == Convert.ToDateTime(assignedTask.AssignmentDate.Date));

            //WorkAround:
            var data = assignedTaskService.Get(a => a.EmployeeId == assignedTask.EmployeeId).ToList();

            //Then filter
            var assignments = from item in data
                              where item.AssignmentDate.Date >= assignedTask.AssignmentDate.Date
                              select item;

            //Check if the employee has assigments already for the selected assigment date
            bool assigneeHasAlreadyAssignments = validateAssignment.AssigneeHasAlreadyAssignmentsOnDate(assignedTask, assignments.ToList());

            if (assigneeHasAlreadyAssignments)
            {
                //The employee has assigment(s) already, so check if the selected start time is before the end time of the last assignment
                //taking into consideration that a task is assigned in sequential order
                var IsTheStartTimeValid = validateAssignment.IsTheStartTimeOfTheNewAssignmentGreaterThanTheEndTimeOfTheLastAssignment(assignedTask, assignments.ToList());

                if (!IsTheStartTimeValid)
                {
                    MessageBox.Show("The selected start time should be greater than the end time of the last assignment.");
                    return(false);
                }
            }
            else
            {
                //The employee has no assignment for the selected assignment date
                //so to check if the selected assigment exceeds the maximum working days per week for the employee,
                //take the week and count the working days
                var firstDateOfWeek = validateAssignment.GetStartDateOfWeek(assignedTask);
                var lastDateOfWeek  = validateAssignment.GetEndDateOfWeek(assignedTask);

                var assignmentsOfTheWeek = assignedTaskService.Get(a => a.EmployeeId == assignedTask.EmployeeId &&
                                                                   a.AssignmentDate >= firstDateOfWeek &&
                                                                   a.AssignmentDate <= lastDateOfWeek);

                //An employee can have more than one assignment per day,
                //so we have to count the unique days, not the assigments
                var assignedDaysPerWeek = (from temp in assignmentsOfTheWeek
                                           select temp.AssignmentDate).Distinct().Count();

                var assignmentExceedsMaxDaysPerWeek = validateAssignment.AssignmentExceedsMaxDaysPerWeek(assignedDaysPerWeek, maxDaysPerWeek);

                if (assignmentExceedsMaxDaysPerWeek)
                {
                    MessageBox.Show($"The maximum days per week is exceeded. The limit is {maxDaysPerWeek} days per week.");
                    return(false);
                }
            }

            //If both the above mentioned cases passes then rest
            //to check if the duration between the selected start time and end time exceeds the maximum working hours per day or not
            var totalHoursAssignedAlready = validateAssignment.GetTotalAssignedHoursOfEmployeeOnDate(assignedTask, assignments.ToList());
            var IsMaxHoursPerDayExceeded  = validateAssignment.ExceedsMaxHoursPerDay(assignedTask, totalHoursAssignedAlready, maxHoursPerDay);

            if (IsMaxHoursPerDayExceeded)
            {
                MessageBox.Show($"The maximum hours to work on the assignment is exceeded. The limit is {maxHoursPerDay}.");
                return(false);
            }

            return(assignmentIsValid);
        }
コード例 #14
0
        public bool IsTheStartTimeOfTheNewAssignmentGreaterThanTheEndTimeOfTheLastAssignment(AssignedTask newAssignment, List <AssignedTask> assignedTasks)
        {
            var datesList = new List <DateTime>();
            var max       = DateTime.MinValue;

            foreach (var assignedTask in assignedTasks)
            {
                datesList.Add(DateTime.Now.Date + assignedTask.EndTime);
            }

            foreach (DateTime date in datesList)
            {
                if (DateTime.Compare(date, max) == 1)
                {
                    max = date;
                }
            }

            var EndTimeOfTheLastAssignment  = max;
            var StartTimeOfTheNewAssignment = DateTime.Now.Date + newAssignment.StartTime;

            return(StartTimeOfTheNewAssignment > EndTimeOfTheLastAssignment);
        }
コード例 #15
0
 public async System.Threading.Tasks.Task SaveAssignedTask(AssignedTask assignedTask)
 {
     _dataContext.Add(assignedTask);
     await _dataContext.SaveChangesAsync();
 }
コード例 #16
0
 private async void OnAssigned(AssignedTask @event)
 {
     await _bucket.MutateIn <TaskDocument>(@event.TaskId.ToString())
     .Replace("assignedTo", @event.AssignedTo)
     .ExecuteAsync();
 }