/// <summary> /// Returns true/false if the current user is in the database role being tested. /// </summary> /// <param name="databaseRole"></param> /// <returns></returns> public static bool IsMember(DatabaseRoleInfo databaseRole) { using (HVCCDataContext db = new HVCCDataContext()) { return(true == db.fn_IsMember(databaseRole.Role)); } }
/// <summary> /// Adds a relationship for the selected property /// </summary> /// <param name="relationship"></param> /// <returns></returns> public static bool AddRelationship(IDataContext datacontext, Owner owner, Relationship relationship) { HVCCDataContext dc = datacontext as HVCCDataContext; try { // Check to see if this Relationship is in the database (has a non-zero ID), // or is pending insertion (has a zero ID). We only want to process new // relationships. if (0 == relationship.RelationshipID) { // Add the default HVCC image to the relationship record. relationship.Photo = LoadDefalutImage(dc); relationship.Active = true; relationship.OwnerID = owner.OwnerID; dc.Relationships.InsertOnSubmit(relationship); } return(true); } catch (Exception ex) { MessageBox.Show("Error activating new Relationship/n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } }
public static Binary LoadDefalutImage(IDataContext datacontext) { HVCCDataContext dc = datacontext as HVCCDataContext; ApplicationDefault defaults = (from p in dc.ApplicationDefaults select p).FirstOrDefault(); return(defaults.Photo); }
/// <summary> /// Deactivate a relationship from the selected property either by making it inactive or deleting it /// from the Relationships table. /// </summary> /// <param name="relationship"></param> /// <returns></returns> public static bool RemoveRelationship(IDataContext datacontext, Relationship relationship, string action = null) { HVCCDataContext dc = datacontext as HVCCDataContext; try { //// Check to see if this Relationship is in the database (has a non-zero ID), //// or is pending insertion (has a zero ID). if (0 != relationship.RelationshipID && !relationship.RelationToOwner.Contains("Owner") && string.IsNullOrEmpty(action)) { // Test to see if the relationship being removed has any FacilitiesUage records. // If not, we can delete the relationship record. Otherwise, we have to set // the records to inactive. IEnumerable <FacilityUsage> fuList = (from x in dc.FacilityUsages where x.RelationshipId == relationship.RelationshipID select x); // If no facility usage records are returned, it is safe to just delete the // Relationship record. Since the passed in Relationship object (relationship) // is not attached to an enity set (it is local to the VM), we need to query the Relationship // table. if (0 == fuList.Count()) { dc.Relationships.DeleteOnSubmit(relationship); } // Otherwise, to deactivate the Relationship (related to F.U. records) we just // set the Active flag false. else { relationship.Active = false; } } // If this is an Ownership Change, we just make the relationship inactive else if (null != action && action.Contains("ChangeOwner")) { relationship.Active = false; } // Otherwise, the RelationshipID is 0, so it is a pending insert else { // This is a pending insert, so we can simply remove the record from the in-memory // store. We raise a PropertiesList property change event to force any/all bound // views to be updated. //selectedProperty.Relationships.Remove(relationship); dc.Relationships.DeleteOnSubmit(relationship); } ChangeSet cs = dc.GetChangeSet(); // <I> This is only for debugging....... return(true); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnClick_CreateDuesButton(object sender, RoutedEventArgs e) { PropertiesViewModel vm = ((PropertiesViewModel)this.DataContext); bool standing = true; int numCarts = 0; decimal cartFees = System.Convert.ToDecimal(this.txtCartFees); using (HVCCDataContext dc = new HVCCDataContext()) { foreach (Property p in vm.PropertiesList) { List <AnnualPropertyInformation> pA = p.AnnualPropertyInformations.ToList(); if (pA.Count > 0) { standing = pA[0].IsInGoodStanding; numCarts = pA[0].NumGolfCart; } else { standing = true; numCarts = 0; } AnnualPropertyInformation a = new AnnualPropertyInformation() { PropertyID = p.PropertyID, Year = Int32.Parse(seForYear.Text), AmountOwed = System.Convert.ToDecimal(txtAnnualDues.Text), IsInGoodStanding = standing, NumGolfCart = numCarts, CartFeesOwed = System.Convert.ToDecimal(numCarts) * cartFees }; dc.AnnualPropertyInformations.InsertOnSubmit(a); } dc.SubmitChanges(); } this.btnCreateDues.Visibility = Visibility.Hidden; }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnClick_CreatePropertiesButton(object sender, RoutedEventArgs e) { PropertiesViewModel vm = ((PropertiesViewModel)this.DataContext); int start = Int32.Parse(txtStartLot.Text); int end = Int32.Parse(txtEndLot.Text); using (HVCCDataContext dc = new HVCCDataContext()) { for (int i = start; i <= end; i++) { Property p = new Property() { Section = Int32.Parse(txtSection.Text), Block = Int32.Parse(txtBlock.Text), Lot = i, SubLot = 0 }; dc.Properties.InsertOnSubmit(p); } dc.SubmitChanges(); } this.btnCreateProperties.Visibility = Visibility.Hidden; }
public MainViewModel(IDataContext dc) { this.dc = dc as HVCCDataContext; this.Host = HVCC.Shell.Host.Instance; //this.RegisterCommands(); }