private void Save() { string message = ""; try { var coreModel = Mapper.Map <Floor>(this); if (FloorID == 0) { coreModel = _floorRepo.Insert(coreModel); FloorID = coreModel.FloorID; message = "增加楼层成功!"; } else { coreModel = _floorRepo.Insert(coreModel); _floorRepo.Update(coreModel); message = "修改设楼层成功!"; } ViewModelAttachment.CoreModel = coreModel; ViewModelAttachment.LastOperationSuccess = true; } catch (Exception ex) { Log.Error("Update floor fails.", ex); message = "保存楼层失败"; SendMessage(message); return; } RaisePropertyChanged(null); Close(message); }
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("保存失败")); } }