private async void ExtendedEOWClosingEventHandler(object sender, DialogClosingEventArgs eventArgs)
        {
            if ((bool)eventArgs.Parameter)
            {
                var dc = (eventArgs.Session.Content as Wizards.EditOwnerWizard);
                //Accept
                if (dc._ownerLocalCopy == null)
                {
                    if (!IsValid(dc as DependencyObject) || (string.IsNullOrEmpty(dc.OwnerFirstName) || string.IsNullOrEmpty(dc.OwnerSurname) || string.IsNullOrEmpty(dc.MailAddress)))
                    {
                        eventArgs.Cancel();
                        return;
                    }
                    //Add new owner
                    var newOwner = new LibDataModel.Owner {
                        OwnerId = Guid.NewGuid(), MailAddress = dc.MailAddress, OwnerFirstName = dc.OwnerFirstName, OwnerSurname = dc.OwnerSurname, IsDeleted = false
                    };
                    using (var db = new DB.DomenaDBContext())
                    {
                        db.Owners.Add(newOwner);
                        db.SaveChanges();
                    }
                    InitializeOwnerList();
                    SelectedOwnerName = OwnersNames.Where(x => x.OwnerId.Equals(newOwner.OwnerId)).FirstOrDefault();
                }
                else
                {
                    if (!IsValid(dc as DependencyObject) || (string.IsNullOrEmpty(dc.OwnerFirstName) || string.IsNullOrEmpty(dc.OwnerSurname) || string.IsNullOrEmpty(dc.MailAddress)))
                    {
                        eventArgs.Cancel();
                        return;
                    }
                    //Edit Owner
                    using (var db = new DB.DomenaDBContext())
                    {
                        var q = db.Owners.Where(x => x.OwnerId.Equals(dc._ownerLocalCopy.OwnerId)).FirstOrDefault();
                        q.OwnerFirstName = dc.OwnerFirstName;
                        q.OwnerSurname   = dc.OwnerSurname;
                        q.MailAddress    = dc.MailAddress;
                        db.SaveChanges();
                    }
                    InitializeOwnerList();
                    SelectedOwnerName = OwnersNames.Where(x => x.OwnerId.Equals(dc._ownerLocalCopy.OwnerId)).FirstOrDefault();
                }
            }
            else if (!(bool)eventArgs.Parameter)
            {
                bool ynResult = await Helpers.YNMsg.Show("Czy chcesz anulować?");

                if (!ynResult)
                {
                    //eventArgs.Cancel();
                    var dc     = (eventArgs.Session.Content as Wizards.EditOwnerWizard);
                    var result = await DialogHost.Show(dc, "HelperDialog", ExtendedEOWOpenedEventHandler, ExtendedEOWClosingEventHandler);
                }
            }
        }
        public PaymentsPage(Apartment apartment)
        {
            DataContext = this;
            InitializeCollection();
            InitializeLists();
            InitializeApartmentsNumbers();
            SelectedPayments = new List <PaymentDataGrid>();
            InitializeComponent();
            GroupByBuilding = true;

            using (var db = new DB.DomenaDBContext())
            {
                var apar = db.Apartments.FirstOrDefault(x => x.ApartmentId.Equals(apartment.ApartmentId));
                SelectedBuildingName    = BuildingsNames.FirstOrDefault(x => x.BuildingId.Equals(apar.BuildingId));
                SelectedApartmentNumber = apar.ApartmentNumber;
                SelectedOwnerName       = OwnersNames.FirstOrDefault(x => x.OwnerId.Equals(apar.OwnerId));
            }
        }
Esempio n. 3
0
        public ChargesPage(Apartment apartment)
        {
            DataContext = this;
            InitializeCollection();
            InitializeCategories();
            InitializeLists();
            InitializeApartmentsNumbers();
            SelectedChargesList = new List<ChargeDataGrid>();
            InitializeComponent();
            GroupByBuilding = false;
            ShowClosed = true;

            using (var db = new DB.DomenaDBContext())
            {
                SelectedBuildingName = BuildingsNames.FirstOrDefault(x => x.BuildingId.Equals(apartment.BuildingId));
                SelectedApartmentNumber = ApartmentsNumbers.FirstOrDefault(x => x == apartment.ApartmentNumber);
                SelectedOwnerName = OwnersNames.FirstOrDefault(x => x.OwnerId.Equals(apartment.OwnerId)); ;
            }
        }
Esempio n. 4
0
        private void Profiles(MyContext db)
        {
            Field <UserType>(
                "createProfile",
                description: "Create a new profile",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <NewProfileInputType> > {
                Name = "input"
            }
                    ),
                resolve: _ => {
                var context = (UserContext)_.UserContext;
                var profile = _.GetArgument <NewProfileDTO>("input");
                StringInfo strinfo;

                //Validate input
                //check for duplicate cognitoId first
                if (db.Owners.Any(x => x.CognitoId.Equals(context.cognitoId)))
                {
                    throw new ExecutionError("You already have an account. Use the `updateProfile` command to make changes to an existing profile.");
                }

                //name
                if (String.IsNullOrWhiteSpace(profile.name))
                {
                    throw new ExecutionError("The 'name' field is required.");
                }
                strinfo = new StringInfo(profile.name);
                if ((strinfo.LengthInTextElements < 3) || (strinfo.LengthInTextElements > 30))
                {
                    throw new ExecutionError("The 'name' field must be between 3 and 30 utf-8 characters in length.");
                }
                if (db.OwnersNames.Any(x => x.Name.Equals(profile.name)))
                {
                    throw new ExecutionError("The name you requested is either in use or has been recently used. Please choose a different one.");
                }

                //country
                if ((!String.IsNullOrWhiteSpace(profile.country)) && (profile.country.Length != 2))
                {
                    throw new ExecutionError("The 'country' field must consist of only two characters, representing a valid ISO 3166-1 alpha-2 country code.");
                }
                profile.country = profile.country.ToUpper();

                //tagline
                if (!String.IsNullOrWhiteSpace(profile.tagline))
                {
                    strinfo = new StringInfo(profile.tagline);
                    if (strinfo.LengthInTextElements > 255)
                    {
                        throw new ExecutionError("The 'tagline' field may not exceed 255 utf-8 characters.");
                    }
                }

                //anonymous
                //Apparently doesn't need to be checked. Should auto-default to false.

                //consent
                if (profile.consent != true)
                {
                    throw new ExecutionError("You must consent to the terms of service and to the processing of your data to create an account and use Abstract Play.");
                }

                //Create record
                DateTime now    = DateTime.UtcNow;
                byte[] ownerId  = GuidGenerator.GenerateSequentialGuid();
                byte[] playerId = Guid.NewGuid().ToByteArray();
                Owners owner    = new Owners {
                    OwnerId     = ownerId,
                    CognitoId   = context.cognitoId,
                    PlayerId    = playerId,
                    DateCreated = now,
                    ConsentDate = now,
                    Anonymous   = profile.anonymous,
                    Country     = profile.country,
                    Tagline     = profile.tagline
                };
                OwnersNames ne = new OwnersNames {
                    EntryId       = GuidGenerator.GenerateSequentialGuid(),
                    OwnerId       = ownerId,
                    EffectiveFrom = now,
                    Name          = profile.name
                };
                owner.OwnersNames.Add(ne);
                db.Add(owner);
                db.SaveChanges();
                return(owner);
            }
                );

            Field <UserType>(
                "updateProfile",
                description: "Update your existing profile",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <PatchProfileInputType> > {
                Name = "input"
            }
                    ),
                resolve: _ => {
                var context = (UserContext)_.UserContext;
                var input   = _.GetArgument <PatchProfileDTO>("input");
                // LambdaLogger.Log(JsonConvert.SerializeObject(input));

                //Load profile first
                Owners rec = db.Owners.SingleOrDefault(x => x.CognitoId.Equals(context.cognitoId));
                if (rec == null)
                {
                    throw new ExecutionError("Could not find your profile. You need to do `createProfile` first.");
                }

                //name
                if (!String.IsNullOrWhiteSpace(input.name))
                {
                    var strinfo = new StringInfo(input.name);
                    if ((strinfo.LengthInTextElements < 3) || (strinfo.LengthInTextElements > 30))
                    {
                        throw new ExecutionError("The 'name' field must be between 3 and 30 utf-8 characters in length.");
                    }
                    if (db.OwnersNames.Any(x => x.Name.Equals(input.name)))
                    {
                        throw new ExecutionError("The name you requested is either in use or has been recently used. Please choose a different one.");
                    }
                    DateTime now   = DateTime.UtcNow;
                    OwnersNames ne = new OwnersNames {
                        EntryId       = GuidGenerator.GenerateSequentialGuid(),
                        OwnerId       = rec.OwnerId,
                        EffectiveFrom = now,
                        Name          = input.name
                    };
                    rec.OwnersNames.Add(ne);
                }

                //country
                if (!String.IsNullOrWhiteSpace(input.country))
                {
                    if (input.country.Length != 2)
                    {
                        throw new ExecutionError("The 'country' field must consist of only two characters, representing a valid ISO 3166-1 alpha-2 country code.");
                    }
                    rec.Country = input.country.ToUpper();
                    //If it's not null, it's an empty or whitespace string, so remove from the profile
                }
                else if (input.country != null)
                {
                    rec.Country = null;
                }

                //tagline
                if (!String.IsNullOrWhiteSpace(input.tagline))
                {
                    var strinfo = new StringInfo(input.tagline);
                    if (strinfo.LengthInTextElements > 255)
                    {
                        throw new ExecutionError("The 'tagline' field may not exceed 255 utf-8 characters.");
                    }
                    rec.Tagline = input.tagline;
                }
                else if (input.tagline != null)
                {
                    rec.Tagline = null;
                }

                //anonymous
                if (input.anonymous != null)
                {
                    rec.Anonymous = (bool)input.anonymous;
                }

                db.Owners.Update(rec);
                db.SaveChanges();
                return(rec);
            }
                );
        }