private bool ShouldUpdatePositionProperty(string propertyName)
        {
            EmployementPosition p = new EmployementPosition();
            Type type             = p.GetType();

            return(type.GetProperty(propertyName) != null);
        }
Пример #2
0
        public bool Equals(EmployementPosition obj)
        {
            EmployementPosition pos2 = obj as EmployementPosition;

            if (pos2 != null)
            {
                return(this.FullTimeProcent == pos2.FullTimeProcent &&
                       this.Position == pos2.Position && this.StartDate == pos2.StartDate);
            }
            return(false);
        }
        private EmployementPosition ViewModelToPosition(PositionViewModel vm)
        {
            EmployementPosition p = new EmployementPosition();

            Location workLoc = DbManager.GetInstance().GetLocationForName(vm.WorkLocation);

            p.BossOver        = vm.BossOver != null ? vm.BossOver : null;
            p.EndDate         = vm.EndDate;
            p.FullTimeProcent = vm.FullTimeProcent;
            p.Id             = vm.Id;
            p.ShopId         = vm.ShopId;
            p.StartDate      = vm.StartDate;
            p.Position       = vm.Position;
            p.WorkLocationId = workLoc != null ? workLoc.Id : ObjectId.Empty;


            return(p);
        }
        private void dgPositions_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            if (e.EditAction == DataGridEditAction.Commit)
            {
                if (!PositionListHasError())
                {
                    var newItem = e.Row.Item;

                    if (newPositions != null && newPositions.Contains(newItem))
                    {
                        bool ok = true;
                        foreach (var pos in newPositions)
                        {
                            if (pos.EmployeeId == null || pos.EmployeeId == ObjectId.Empty)
                            {
                                ok = false;
                            }
                            else
                            {
                                EmployementPosition empPosition = ViewModelToPosition(pos);
                                ok = DbManager.GetInstance().AddPositionToEmployee(empPosition, pos.EmployeeId);
                                if (ok)
                                {
                                    var positions = Employees.Where(emp => emp.Id == pos.EmployeeId).Single().Positions.ToList();
                                    positions.Add(empPosition);
                                    Employees.Where(emp => emp.Id == pos.EmployeeId).Single().Positions = positions;
                                }
                            }
                        }
                        if (!ok)
                        {
                            MessageBox.Show("Adding new position failed");
                        }
                        else
                        {
                            newPositions.Clear();
                        }
                    }
                }
            }
        }
        private PositionViewModel PositionToViewModel(EmployementPosition pos)
        {
            PositionViewModel vm = new PositionViewModel()
            {
                BossOver        = pos.BossOver,
                EndDate         = pos.EndDate,
                FullTimeProcent = pos.FullTimeProcent,
                Id           = pos.Id,
                ShopId       = pos.ShopId,
                StartDate    = pos.StartDate,
                Position     = pos.Position,
                WorkLocation = DbManager.GetInstance().GetNameOfLocation(pos.WorkLocationId),
            };

            Address address = DbManager.GetInstance().GetShopAddressForId(pos.ShopId);

            if (address != null)
            {
                vm.ShopAddress = AddressToViewModel(address);
            }

            return(vm);
        }