Beispiel #1
0
        private void OkBtn_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                if (_photoChanged)
                {
                    _userAvatorService.UploadAvatorToServer(_floorViewModel.Photo);
                }

                var coreModel = Mapper.Map <Floor>(_floorViewModel);
                foreach (var dropDoor in dropDoors)
                {
                    var floorDoorViewModel = Mapper.Map <FloorDoor>(dropDoor.DataContext as FloorDoorViewModel);
                    coreModel.Doors.Add(floorDoorViewModel);
                }

                var validator = NinjectBinder.GetValidator <FloorValidator>();
                var results   = validator.Validate(coreModel);
                if (!results.IsValid)
                {
                    var message = string.Join("\n", results.Errors);
                    ShowSubViewNotification(new NotificationMessage(message));
                    return;
                }

                if (coreModel.FloorID == 0)
                {
                    coreModel.Status        = GeneralStatus.Enabled;
                    coreModel               = _floorRepo.Insert(coreModel);
                    _floorViewModel.FloorID = coreModel.FloorID;
                    _floorViewModel.BindDoors(coreModel.Doors);
                    //UpdateAuthorizationDoorsForFloor(coreModel);
                }
                else
                {
                    _floorRepo.Update(coreModel);
                    coreModel = _floorRepo.GetByKey(coreModel.FloorID);
                    _floorViewModel.BindDoors(coreModel.Doors);
                    //UpdateAuthorizationDoorsForFloor(coreModel);
                }

                _floorViewModel.ViewModelAttachment.CoreModel            = coreModel;
                _floorViewModel.ViewModelAttachment.LastOperationSuccess = true;
                ProcessCloseViewMessage(new NotificationMessage("保存成功"));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                ShowSubViewNotification(new NotificationMessage("保存失败"));
            }
        }