Exemplo n.º 1
0
 public override int GetHashCode()
 {
     unchecked {
         int hashCode = Name.GetHashCode();
         hashCode = (hashCode * 397) ^ Function.GetHashCode();
         hashCode = (hashCode * 397) ^ (AltFunction != null ? AltFunction.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (CtrlFunction != null ? CtrlFunction.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ShiftFunction != null ? ShiftFunction.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ComboFunction != null ? ComboFunction.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Data != null ? Data.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Color.GetHashCode();
         return(hashCode);
     }
 }
        private static ICollection <ShiftFunction> SetShiftFunctions()
        {
            List <ShiftFunction> shiftFunctions = new List <ShiftFunction>();
            int c = 1;

            foreach (Function f in functions)
            {
                ShiftFunction sf = new ShiftFunction
                {
                    ShiftFunctionID = c,
                    Function        = f,
                    FunctionID      = f.FunctionID,
                    ShiftID         = 1
                };
                shiftFunctions.Add(sf);
                c++;
            }
            return(shiftFunctions);
        }
Exemplo n.º 3
0
        public List <ShiftFunction> SetShiftFunctions(ApplicationDbContext context)
        {
            shifts    = context.Shift.ToList();
            functions = context.Function.ToList();

            foreach (Shift shift in shifts)
            {
                int    t     = 3;
                Random r     = new Random();
                int    range = functions.Count() - 1;
                for (int i = 0; i < t; i++)
                {
                    int           id           = RandomID(range) + 1;
                    int           maxEmployees = r.Next(1, 3);
                    ShiftFunction sf           = new ShiftFunction {
                        FunctionID = id, ShiftID = shift.ShiftID, MaxEmployees = maxEmployees
                    };
                    shiftFunctions.Add(sf);
                }
                counts.Clear();
            }
            return(shiftFunctions);
        }
Exemplo n.º 4
0
        private async static void AddShift(Shift shift, int[] selectedSkills, int[] selectedFunctions, int[] selectedFunctionsMax, ApplicationDbContext _context)
        {
            if (selectedSkills != null)
            {
                shift.ShiftSkills = new List <ShiftSkills>();
                foreach (var skill in selectedSkills)
                {
                    var skillToAdd = new ShiftSkills
                    {
                        ShiftID = shift.ShiftID,
                        Shift   = shift,
                        SkillID = skill,
                        Skill   = _context.Skill.Single(s => s.SkillID == skill)
                    };
                    shift.ShiftSkills.Add(skillToAdd);
                }
            }
            if (selectedFunctions != null)
            {
                shift.ShiftFunctions = new List <ShiftFunction>();
                foreach (var function in selectedFunctions)
                {
                    int functionID    = function;
                    int maxCnt        = functionID - 1;
                    var functionToAdd = new ShiftFunction
                    {
                        ShiftID      = shift.ShiftID,
                        Shift        = shift,
                        FunctionID   = functionID,
                        Function     = _context.Function.Single(f => f.FunctionID == function),
                        MaxEmployees = selectedFunctionsMax[maxCnt]
                    };
                    shift.ShiftFunctions.Add(functionToAdd);
                }
            }
            _context.Add(shift);
            await _context.SaveChangesAsync();

            if (shift.Weekly)
            {
                ICollection <Shift> children = CreateChildren(shift, _context);
                foreach (Shift child in children)
                {
                    _context.Add(child);
                    child.ShiftFunctions = new List <ShiftFunction>();
                    foreach (ShiftFunction sf in shift.ShiftFunctions)
                    {
                        ShiftFunction shiftFunction = new ShiftFunction
                        {
                            Function     = sf.Function,
                            FunctionID   = sf.FunctionID,
                            MaxEmployees = sf.MaxEmployees,
                            ShiftID      = child.ShiftID
                        };
                        child.ShiftFunctions.Add(shiftFunction);
                    }
                    child.ShiftSkills = new List <ShiftSkills>();
                    foreach (ShiftSkills ss in shift.ShiftSkills)
                    {
                        ShiftSkills shiftSkills = new ShiftSkills
                        {
                            Skill   = ss.Skill,
                            SkillID = ss.SkillID,
                            ShiftID = child.ShiftID
                        };
                        child.ShiftSkills.Add(shiftSkills);
                    }
                }
                await _context.SaveChangesAsync();

                shift.ShiftChildren = children;
            }
            await _context.SaveChangesAsync();
        }
Exemplo n.º 5
0
        private void UpdateShiftFunctions(string[] selectedFunctions, int[] selectedFunctionsMax, Shift shiftToUpdate)
        {
            if (selectedFunctions == null || selectedFunctionsMax == null)
            {
                shiftToUpdate.ShiftFunctions = new List <ShiftFunction>();
                return;
            }

            var selectedFunctionsHS = new HashSet <string>(selectedFunctions);

            if (shiftToUpdate.ShiftFunctions != null)
            {
                var shiftFunctions = new HashSet <int>
                                         (shiftToUpdate.ShiftFunctions.Select(c => c.Function.FunctionID));
                int cnt = 0;
                foreach (var function in _context.Function)
                {
                    if (selectedFunctionsHS.Contains(function.FunctionID.ToString()))
                    {
                        if (!shiftFunctions.Contains(function.FunctionID))
                        {
                            shiftToUpdate.ShiftFunctions.Add(new ShiftFunction {
                                ShiftID = shiftToUpdate.ShiftID, FunctionID = function.FunctionID, MaxEmployees = selectedFunctionsMax[cnt]
                            });
                        }
                        else
                        {
                            shiftToUpdate.ShiftFunctions.Single(f => (f.FunctionID == function.FunctionID) && (f.ShiftID == shiftToUpdate.ShiftID)).MaxEmployees = selectedFunctionsMax[cnt];
                        }
                    }
                    else
                    {
                        if (shiftFunctions.Contains(function.FunctionID))
                        {
                            ShiftFunction functionToRemove = shiftToUpdate.ShiftFunctions.FirstOrDefault(i => i.FunctionID == function.FunctionID);
                            _context.Remove(functionToRemove);
                        }
                    }
                    cnt++;
                }
            }
            else
            {
                shiftToUpdate.ShiftFunctions = new List <ShiftFunction>();
                int cnt = 0;
                foreach (var function in _context.Function)
                {
                    if (selectedFunctionsHS.Contains(function.FunctionID.ToString()))
                    {
                        shiftToUpdate.ShiftFunctions.Add(new ShiftFunction
                        {
                            ShiftID      = shiftToUpdate.ShiftID,
                            Shift        = shiftToUpdate,
                            FunctionID   = function.FunctionID,
                            Function     = function,
                            MaxEmployees = selectedFunctionsMax[cnt]
                        });
                    }
                    cnt++;
                }
            }
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("Start,End,Weekly,LocationID,Location")] Shift shift, string[] selectedSkills, string[] selectedFunctions, int[] selectedFunctionsMax)
        {
            if (User.Identity.IsAuthenticated && _context.EmployeeModel.ToList().Find(x => x.EMail == User.Identity.Name).Admin)
            {
                if (selectedSkills != null)
                {
                    shift.ShiftSkills = new List <ShiftSkills>();
                    foreach (var skill in selectedSkills)
                    {
                        var skillToAdd = new ShiftSkills
                        {
                            ShiftID = shift.ShiftID,
                            Shift   = shift,
                            SkillID = int.Parse(skill),
                            Skill   = _context.Skill.Single(s => s.SkillID == int.Parse(skill))
                        };
                        shift.ShiftSkills.Add(skillToAdd);
                    }
                }
                if (selectedFunctions != null)
                {
                    shift.ShiftFunctions = new List <ShiftFunction>();
                    foreach (var function in selectedFunctions)
                    {
                        int functionID    = int.Parse(function);
                        int maxCnt        = functionID - 1;
                        var functionToAdd = new ShiftFunction
                        {
                            ShiftID      = shift.ShiftID,
                            Shift        = shift,
                            FunctionID   = functionID,
                            Function     = _context.Function.Single(f => f.FunctionID == int.Parse(function)),
                            MaxEmployees = selectedFunctionsMax[maxCnt]
                        };
                        shift.ShiftFunctions.Add(functionToAdd);
                    }
                }
                if (ModelState.IsValid)
                {
                    _context.Add(shift);
                    await _context.SaveChangesAsync();

                    if (shift.Weekly)
                    {
                        ICollection <Shift> children = CreateChildren(shift);
                        foreach (Shift child in children)
                        {
                            _context.Add(child);
                            child.ShiftFunctions = new List <ShiftFunction>();
                            foreach (ShiftFunction sf in shift.ShiftFunctions)
                            {
                                ShiftFunction shiftFunction = new ShiftFunction
                                {
                                    Function     = sf.Function,
                                    FunctionID   = sf.FunctionID,
                                    MaxEmployees = sf.MaxEmployees,
                                    ShiftID      = child.ShiftID
                                };
                                child.ShiftFunctions.Add(shiftFunction);
                            }
                            child.ShiftSkills = new List <ShiftSkills>();
                            foreach (ShiftSkills ss in shift.ShiftSkills)
                            {
                                ShiftSkills shiftSkills = new ShiftSkills
                                {
                                    Skill   = ss.Skill,
                                    SkillID = ss.SkillID,
                                    ShiftID = child.ShiftID
                                };
                                child.ShiftSkills.Add(shiftSkills);
                            }
                        }
                        await _context.SaveChangesAsync();

                        shift.ShiftChildren = children;
                    }
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                PopulateLocationsDropDownList(shift);
                return(View(shift));
            }
            else
            {
                return(Forbid());
            }
        }