示例#1
0
 public VacationViewModel(VacationsViewModel owner, VacationService.Vacation vacation, bool createEdited)
 {
     Owner = owner;
     Vacation = vacation ?? new VacationService.Vacation();
     if (createEdited)
     {
         IsEditMode = true;
     }
 }
        public VacationListItemViewModel(Staffing.EmployeeViewModel employee, VacationsViewModel owner)
        {
            if (employee == null)
                throw new ArgumentNullException(nameof(employee));
            if (owner == null)
                throw new ArgumentNullException(nameof(owner));

            Employee = employee;
            Owner = owner;
            Balance = owner.VacationBalances.FirstOrDefault(b => b.EmployeeId == Employee.Employee.Id);

            owner.VacationBalances.CollectionChanged += (_, e) =>
            {
                var itm = e.OldItems?
                    .Cast<VacationService.VacationBalance>()
                    .FirstOrDefault(i => i.EmployeeId == employee.Employee.Id);
                if (itm != null)
                    Balance = null;

               itm = e.NewItems?
                    .Cast<VacationService.VacationBalance>()
                    .FirstOrDefault(i => i.EmployeeId == employee.Employee.Id);
                if (itm != null)
                    Balance = itm;
            };

            foreach (var item in Owner.Vacations.Where(v => v.EmployeeId == Employee.Employee.Id))
                vacations.Add(new VacationListItemPartViewModel(this, item));

            Owner.Vacations.CollectionChanged += (_, e) => 
            {
                if (e.OldItems != null)
                    foreach (var oldItem in e.OldItems
                        .Cast<VacationService.Vacation>()
                        .Where(i => i.EmployeeId == employee.Employee.Id)
                        .Join(vacations, v => v, vm => vm.Vacation, (v, vm) => vm))
                        vacations.Remove(oldItem);

                if (e.NewItems != null)
                    foreach (var newItem in e.NewItems
                        .Cast<VacationService.Vacation>()
                        .Where(i => i.EmployeeId == employee.Employee.Id)
                        .Select(i => new VacationListItemPartViewModel(this, i)))
                        vacations.Add(newItem);
            };
        }
示例#3
0
 public VacationViewModel(VacationsViewModel owner, long employeeId, long levelId, bool createEdited)
     : this(owner, new VacationService.Vacation() { EmployeeId = employeeId, VacationLevelId = levelId }, createEdited) { }
示例#4
0
 public VacationViewModel(VacationsViewModel owner) : this(owner, null, false) { }
 internal static bool GetCanManage(VacationsViewModel vm, VacationService.Vacation vacation)
 {
     var isItMyOwnVacation = vm.Staffing.Current.Id == vacation.EmployeeId;
     var isAgrrementExists = (vacation.Agreements?.Any() ?? false);
     var canUserChengeHisOwn = isItMyOwnVacation 
         && !GetIsItGoesOver(vacation)
         && !vacation.NotUsed;
     return !isAgrrementExists && (vm.CanManageVacations || canUserChengeHisOwn);
 }
 internal static VacationFunctionalGroupViewModel CreateEdited(VacationService.VacationFunctionalGroup group, VacationsViewModel owner)
 {
     return new VacationFunctionalGroupViewModel(group, owner) { IsEditMode = true };
 }
        public VacationFunctionalGroupViewModel(VacationService.VacationFunctionalGroup group, VacationsViewModel owner)
        {
            if (group == null)
                throw new ArgumentNullException(nameof(group));
            if (owner == null)
                throw new ArgumentNullException(nameof(owner));

            Group = group;
            Owner = owner;

            IsEmpty = group.Id == 0;

            LoadEmployees(group);
            Group.PropertyChanged += (_, e) => 
            {
                if (e.PropertyName == nameof(Group.EmployeIds))
                    LoadEmployees(Group);
            };
        }