public void ApartmentSell(Apartment cur) { #region Check if (cur.CanSell == false && cur.CanMarketSell == false) { cur.ValidationErrors.Add(new ValidationResult(ApartmentServiceError.SellException_AuthLimit, null)); MessageBox.Show(ApartmentServiceError.SellException_AuthLimit); return; } if (cur.Consumer == null || cur.LockStatu == null) { throw new InvalidOperationException(ApartmentServiceError.SystemException_CheckState); } //不为空,则表示已售记录,再次销售 if (!String.IsNullOrEmpty(cur.Consumer.OperateUser)) { throw new InvalidOperationException(ApartmentServiceError.SystemException_SellSold); } if (!CheckComsterInfo(cur.Consumer)) { MessageBox.Show(ApartmentServiceError.SellException_NeedInformation); return; } #endregion #region pepare RepareOperation(cur); #endregion #region initial content Apartment commitApartment = new Apartment { ApartmentId = cur.ApartmentId, RoomType = cur.RoomType, Area = cur.Area, Builing = cur.Builing, Uint = cur.Uint, Floor = cur.Floor, Number = cur.Number, ActualArea = cur.ActualArea, ShareArea = cur.ShareArea, ShareFactor = cur.ShareFactor, ResidentialId = cur.ResidentialId, Residential = null, Consumer = null, LockStatu = null }; commitApartment.LockStatu = new LockStatu() { Apartment = commitApartment, ApartmentId = cur.ApartmentId, OperateUser = cur.LockStatu.OperateUser, OperateTime = cur.LockStatu.OperateTime }; #endregion #region submit NitpickHouseDomainContext submitContext = new NitpickHouseDomainContext(); //use attach to set apartment to unchange state submitContext.Apartments.Attach(commitApartment); commitApartment.LockStatu = null; commitApartment.Consumer = new Consumer() { Apartment = commitApartment, ApartmentId = cur.Consumer.ApartmentId, SellType = cur.Consumer.SellType, RegionType = cur.Consumer.RegionType, Name = cur.Consumer.Name, IdCard = cur.Consumer.IdCard, RealEstateId = cur.Consumer.RealEstateId, OriginArea = cur.Consumer.OriginArea, OriginAddress = cur.Consumer.OriginAddress, OperateUser = WebContext.Current.User.Name, OperateTime = DateTime.Now }; // submit the new context SubmitOperation submitOp = submitContext.SubmitChanges(); submitOp.Completed += (send, args) => { CompleteOperation(submitOp, cur); }; #endregion }
public void ApartmentDelete(Apartment cur) { #region Check if (MessageBox.Show(ApartmentServiceError.DelException_Warnning, "警告", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) { return; } if (cur.CanDelSold == false) { cur.ValidationErrors.Add(new ValidationResult(ApartmentServiceError.DelException_AuthLimit, null)); MessageBox.Show(ApartmentServiceError.DelException_AuthLimit); return; } if (cur.Consumer == null || cur.LockStatu == null) { throw new InvalidOperationException(ApartmentServiceError.SystemException_CheckState); } //为空,则表示正在删除未售记录 if (String.IsNullOrEmpty(cur.Consumer.OperateUser)) { throw new InvalidOperationException(ApartmentServiceError.SystemException_DeleteUnSell); } #endregion #region pepare RepareOperation(cur); #endregion #region initial content Apartment commitApartment = new Apartment { ApartmentId = cur.ApartmentId, RoomType = cur.RoomType, Area = cur.Area, Builing = cur.Builing, Uint = cur.Uint, Floor = cur.Floor, Number = cur.Number, ActualArea = cur.ActualArea, ShareArea = cur.ShareArea, ShareFactor = cur.ShareFactor, ResidentialId = cur.ResidentialId, Residential = null, Consumer = null, LockStatu = null }; commitApartment.Consumer = new Consumer() { Apartment = commitApartment, ApartmentId = cur.Consumer.ApartmentId, SellType = cur.Consumer.SellType, RegionType = cur.Consumer.RegionType, Name = cur.Consumer.Name, IdCard = cur.Consumer.IdCard, RealEstateId = cur.Consumer.RealEstateId, OriginArea = cur.Consumer.OriginArea, OriginAddress = cur.Consumer.OriginAddress, OperateTime = cur.Consumer.OperateTime, OperateUser = cur.Consumer.OperateUser }; commitApartment.LockStatu = new LockStatu() { Apartment = commitApartment, ApartmentId = cur.ApartmentId, OperateUser = cur.LockStatu.OperateUser, OperateTime = cur.LockStatu.OperateTime }; #endregion #region submit NitpickHouseDomainContext submitContext = new NitpickHouseDomainContext(); //use attach to set apartment to unchange state submitContext.Apartments.Attach(commitApartment); commitApartment.LockStatu = null; commitApartment.Consumer = null; // submit the new context SubmitOperation submitOp = submitContext.SubmitChanges(); submitOp.Completed += (send, args) => { CompleteOperation(submitOp, cur); }; #endregion }
/// <summary> /// 锁定Apartment函数,被browser调用 /// </summary> /// <param name="cur"></param> /// <param name="callback"></param> public void ApartmentLock(Apartment cur) { #region Check if (cur.CanLock == false) { cur.CurState = ApartmentRuntimeState.Deleted; cur.ValidationErrors.Add(new ValidationResult(ApartmentServiceError.LockException_AuthLimit, null)); MessageBox.Show(ApartmentServiceError.LockException_AuthLimit); return; } if (cur.LockStatu != null) { cur.CurState = ApartmentRuntimeState.Deleted; cur.ValidationErrors.Add(new ValidationResult(ApartmentServiceError.LockException_LockForLocked, null)); MessageBox.Show(ApartmentServiceError.LockException_LockForLocked); return; } if (cur.HasChanges) { cur.CurState = ApartmentRuntimeState.Deleted; cur.ValidationErrors.Add(new ValidationResult(ApartmentServiceError.LockException_RecordModified, null)); MessageBox.Show(ApartmentServiceError.LockException_RecordModified); return; } #endregion #region set origin state cur.CurState = ApartmentRuntimeState.Busing; #endregion #region initial content Apartment commitApartment = new Apartment{ ApartmentId = cur.ApartmentId, RoomType = cur.RoomType, Area = cur.Area, Builing = cur.Builing, Uint = cur.Uint, Floor = cur.Floor, Number = cur.Number, ActualArea = cur.ActualArea, ShareArea = cur.ShareArea, ShareFactor = cur.ShareFactor, ResidentialId = cur.ResidentialId, Residential = null, Consumer = null, LockStatu = null }; if (cur.Consumer != null) { commitApartment.Consumer = new Consumer() { Apartment = commitApartment, ApartmentId = cur.Consumer.ApartmentId, SellType = cur.Consumer.SellType, RegionType = cur.Consumer.RegionType, Name = cur.Consumer.Name, IdCard = cur.Consumer.IdCard, RealEstateId = cur.Consumer.RealEstateId, OriginArea = cur.Consumer.OriginArea, OriginAddress = cur.Consumer.OriginAddress, OperateTime = cur.Consumer.OperateTime, OperateUser = cur.Consumer.OperateUser }; } #endregion #region submit NitpickHouseDomainContext submitContext = new NitpickHouseDomainContext(); //use attach to set apartment to unchange state submitContext.Apartments.Attach(commitApartment); commitApartment.LockStatu = new LockStatu() { Apartment = commitApartment, ApartmentId = cur.ApartmentId, OperateUser = WebContext.Current.User.Name, OperateTime = DateTime.Now }; // submit the new context var submitOp = submitContext.SubmitChanges(); submitOp.Completed += (send, args) => { if (submitOp.HasError) { cur.CurState = ApartmentRuntimeState.Deleted; cur.ValidationErrors.Add(new ValidationResult(submitOp.Error.Message, null)); submitOp.MarkErrorAsHandled(); MessageBox.Show(ApartmentServiceError.ServerOperationException); } else { //--------------------------- //如果当前正在加载,则查询结果可能不正确,需要cancel一次 MakeSureLoadCorret(); //--------------------------- Apartment submittedApartments = (Apartment)submitOp.ChangeSet.ModifiedEntities[0]; submitContext.Apartments.Detach(submittedApartments); //刷新状态 submittedApartments.CurState = ApartmentRuntimeState.Normal; submittedApartments.RefreshAuthenticate(true); _domainContext.Apartments.Attach(submittedApartments); InitialAttachedData(submittedApartments); //----------------------- //add 到视图,及时显示出来 //因为前面清除了当前查询,所以不会出现马上清除的情况。 _apartemntLocked.Add(submittedApartments); } }; #endregion }