示例#1
0
        public static BarcoMember GetMemberForJob(BarcoJob barcoJob, List <BarcoMember> membersPool)
        {
            BarcoMember selectedMember = null;

            foreach (var member in membersPool)
            {
                bool memberAlreadyInJob = false;
                foreach (var shift in barcoJob.Shifts)
                {
                    if (shift.BarcoMember.UserName == member.UserName)
                    {
                        memberAlreadyInJob = true;
                        break;
                    }
                }
                if (!memberAlreadyInJob)
                {
                    selectedMember = member;
                }
            }
            if (selectedMember != null)
            {
                membersPool.Remove(selectedMember);
            }
            return(selectedMember);
        }
示例#2
0
        public async Task <IActionResult> Index()
        {
            string accessToken = "";
            string idToken     = "";

            if (User.Identity.IsAuthenticated)
            {
                accessToken = await HttpContext.GetTokenAsync("access_token");

                idToken = await HttpContext.GetTokenAsync("id_token");

                if (User.Identity.IsAuthenticated)
                {
                    var member = await _context.GetMemberAsync(User.Identity.Name);

                    if (member == null)
                    {
                        member = new BarcoMember
                        {
                            UserName = User.Identity.Name,
                            Email    = User.Claims.Single(c => c.Type == "email").Value,
                            Name     = User.Claims.Single(c => c.Type == "fullName").Value,
                            NickName = User.Claims.Single(c => c.Type == "nickName").Value
                        };

                        if (User.IsInRole("Rota"))
                        {
                            member.RotaStatus = RotaStatus.Active;
                        }

                        _context.BarcoMembers.Add(member);
                        _context.SaveChanges();
                    }
                }
            }

            //get current month
            List <DaySummaryViewModel> dayViewModels = new List <DaySummaryViewModel>();

            DateTime date            = DateTime.Today;
            var      firstDayOfMonth = new DateTime(date.Year, date.Month, 1);
            var      lastDayOfMonth  = firstDayOfMonth.AddMonths(1).AddDays(-1);

            for (DateTime day = firstDayOfMonth; day <= lastDayOfMonth; day = day.AddDays(1))
            {
                var job = _context.BarcoJobs
                          .Where(j => j.StartDateTime.Date == day.Date)
                          .Include(j => j.Shifts)
                          .ThenInclude(s => s.BarcoMember)
                          .FirstOrDefault();
                dayViewModels.Add(new DaySummaryViewModel(day, job));
            }

            return(View(dayViewModels));
        }
示例#3
0
 public BarcoMemberViewModel(BarcoMember barcoMember)
 {
     if (barcoMember.NickName != null)
     {
         Name = barcoMember.NickName;
     }
     else
     {
         Name = barcoMember.Name;
     }
 }
示例#4
0
        public async Task <IActionResult> PostBarcoMember([FromBody] BarcoMember barcoMember)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.BarcoMembers.Add(barcoMember);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBarcoMember", new { id = barcoMember.Id }, barcoMember));
        }
示例#5
0
        public static BarcoShift AddShift(BarcoJob job, BarcoMember member)
        {
            if (job.Shifts.Count < job.JobCapacity)
            {
                var shift = new BarcoShift
                {
                    BarcoMember = member,
                    ShiftStatus = ShiftStatus.Planned,
                    BarcoJob    = job
                };
                job.Shifts.Add(shift);

                return(shift);
            }
            else
            {
                return(null);
            }
        }
示例#6
0
 protected void Notify(BarcoMember member, string subject, string content)
 {
     _emailSender.SendEmailAsync(member.Email, subject, content);
 }
示例#7
0
        public static WorkPackage CreateWorkPackage(string name, DateTime startDate, DateTime endDate, BarcoMember manager, JobType jobType, int jobCapacity)
        {
            var workPackage = new WorkPackage
            {
                Name      = name,
                Manager   = manager,
                StartDate = startDate,
                Status    = WorkPackageStatus.Planned,
                Jobs      = new HashSet <BarcoJob>()
            };

            for (DateTime date = startDate; date.Date <= endDate.Date; date = date.AddDays(1))
            {
                var barTimes = GetBarTimes(date);
                workPackage.Jobs.Add(new BarcoJob
                {
                    Created       = DateTime.Now,
                    StartDateTime = barTimes.OpeningDateTime,
                    EndDateTime   = barTimes.ClosingDateTime,
                    JobType       = jobType,
                    JobCapacity   = jobCapacity,
                    WorkPackage   = workPackage
                });
            }

            return(workPackage);
        }
示例#8
0
        public static WorkPackageFIllResult FillWorkPackage(WorkPackage workPackage, List <BarcoMember> allMembersPool, bool useEngagedMembers)
        {
            var engagedMembers = useEngagedMembers ? new List <BarcoMember>(): workPackage.Jobs.SelectMany(j => j.Shifts).Select(s => s.BarcoMember).ToList();

            List <BarcoMember> membersPool = new List <BarcoMember>();

            foreach (var member in allMembersPool)
            {
                if (!engagedMembers.Contains(member))
                {
                    membersPool.Add(member);
                }
            }

            //shuffle
            var rand = new Random(DateTime.UtcNow.Millisecond);

            var n = membersPool.Count;

            while (n > 1)
            {
                n--;
                var k      = rand.Next(n + 1);
                var member = membersPool[k];
                membersPool[k] = membersPool[n];
                membersPool[n] = member;
            }

            //assign
            var stats = new WorkPackageFIllResult(workPackage.Jobs.Count);

            foreach (var job in workPackage.Jobs)
            {
                var filledShifts    = job.Shifts.Count;
                var attemptedShifts = 0;

                while (filledShifts + attemptedShifts < job.JobCapacity)
                {
                    if (membersPool.Count == 0)
                    {
                        return(stats);
                    }

                    BarcoMember selected = GetMemberForJob(job, membersPool);

                    if (selected != null)
                    {
                        job.Shifts.Add(new BarcoShift
                        {
                            BarcoMember = selected,
                            BarcoJob    = job,
                            ShiftStatus = ShiftStatus.Planned
                        });
                        filledShifts += 1;
                        stats.ShiftFilled();
                    }
                    else
                    {
                        attemptedShifts += 1;
                    }
                }

                stats.JobFilled();
            }

            return(stats);
        }