コード例 #1
0
        public async Task <GetOrCreateSubscriberOutput> GetOrCreate(GetOrCreateSubscriberInput input)
        {
            try
            {
                SubscriberDto subscriberDto   = null;
                bool          newSubscriber   = false;
                string        normalisedEmail = StringUtils.NormaliseEmailAddress(input.EmailAddress);

                subscriberDto = await _crudServices.ReadSingleAsync <SubscriberDto>(s => s.EmailAddress == normalisedEmail);

                if (subscriberDto == null)
                {
                    string emailVerifyCode = !input.EmailAddressVerified
                        ? Guid.NewGuid().ToString("N").ToLowerInvariant().Truncate(Subscriber.MAX_LENGTH_EMAIL_VERIFY_CODE)
                        : null;

                    subscriberDto = await _crudServices.CreateAndSaveAsync(new SubscriberDto
                    {
                        EmailAddress         = normalisedEmail,
                        EmailAddressVerified = input.EmailAddressVerified,
                        EmailVerifyCode      = emailVerifyCode
                    });

                    if (!_crudServices.IsValid)
                    {
                        return(new GetOrCreateSubscriberOutput
                        {
                            ErrorMessage = _crudServices.GetAllErrors()
                        });
                    }

                    newSubscriber = true;
                }

                return(new GetOrCreateSubscriberOutput
                {
                    Subscriber = subscriberDto,
                    CreatedNewSubscriber = newSubscriber,
                    ErrorMessage = subscriberDto == null ? $"Error creating subscriber with email '{normalisedEmail}' in database" : null
                });
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "EmailAddress: " + input.EmailAddress);
                return(new GetOrCreateSubscriberOutput
                {
                    ErrorMessage = ex.Message
                });
            }
        }
コード例 #2
0
        /// <summary>
        ///     Calculates the sum of all accounts at the current moment.
        /// </summary>
        /// <returns>Sum of the balance of all accounts.</returns>
        protected override async Task <double> CalculateTotalBalance()
        {
            try
            {
                var account = await crudServices.ReadSingleAsync <AccountViewModel>(accountId).ConfigureAwait(true);

                return(account.CurrentBalance);
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }

            return(0);
        }
コード例 #3
0
        }                                             //#A

        //public async Task<IActionResult> AddPromotion(int id)
        public async Task <AddPromotionDto> AddPromotion(int id)
        {
            var dto = await _service                          //#B
                      .ReadSingleAsync <AddPromotionDto>(id); //#B

            //return View(dto);
            return(dto);
        }
コード例 #4
0
        public async Task <IActionResult> AddPromotion(int id, [FromServices] ICrudServicesAsync <BookDbContext> service)
        {
            Request.ThrowErrorIfNotLocal();
            var dto = await service.ReadSingleAsync <AddPromotionDto>(id);

            SetupTraceInfo();
            return(View(dto));
        }
コード例 #5
0
        public override async void Prepare(ModifyCategoryParameter parameter)
        {
            SelectedCategory = await crudServices.ReadSingleAsync <CategoryViewModel>(parameter.CategoryId)
                               .ConfigureAwait(true);

            Title = string.Format(CultureInfo.InvariantCulture, Strings.EditCategoryTitle, SelectedCategory.Name);

            base.Prepare(parameter);
        }
コード例 #6
0
        public async Task <UnsubscribeFromArtistOutput> UnsubscribeFromArtist(UnsubscribeFromArtistInput input)
        {
            if (input.ArtistId <= 0)
            {
                throw new ArgumentException("ArtistId must be a valid Id", "ArtistId");
            }

            if (String.IsNullOrWhiteSpace(input.UnsubscribeToken))
            {
                throw new ArgumentException("UnsubscribeToken must be set", "UnsubscribeToken");
            }

            try
            {
                var subscription = await _crudServices.ReadSingleAsync <Subscription>(
                    s => s.ArtistId == input.ArtistId && s.Subscriber.UnsubscribeToken == input.UnsubscribeToken);

                if (subscription != null)
                {
                    await _crudServices.DeleteAndSaveAsync <Subscription>(subscription.Id);

                    return(new UnsubscribeFromArtistOutput
                    {
                        ErrorMessage = _crudServices.IsValid ? null : _crudServices.GetAllErrors()
                    });
                }
                else
                {
                    return(new UnsubscribeFromArtistOutput
                    {
                        ErrorMessage = "Subscription not found. Either you've already unsubscribed, or the URL that got you here wasn't quite right."
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "ArtistId: {0}, UnsubscribeToken: {1}", input.ArtistId, input.UnsubscribeToken);
                return(new UnsubscribeFromArtistOutput
                {
                    ErrorMessage = ex.Message
                });
            }
        }
コード例 #7
0
        public async Task <IActionResult> RemovePromotion(int id, [FromServices] ICrudServicesAsync <BookDbContext> service)
        {
            Request.ThrowErrorIfNotLocal();
            var dto = await service.ReadSingleAsync <RemovePromotionDto>(id);

            if (!service.IsValid)
            {
                service.CopyErrorsToModelState(ModelState, dto);
            }
            SetupTraceInfo();
            return(View(dto));
        }
コード例 #8
0
        public override void Prepare(ModifyPaymentParameter parameter)
        {
            SelectedPayment = crudServices.ReadSingleAsync <PaymentViewModel>(parameter.PaymentId).Result;

            // We have to set this here since otherwise the end date is null. This causes a crash on android.
            // Also it's user unfriendly if you the default end date is the 1.1.0001.
            if (SelectedPayment.IsRecurring && SelectedPayment.RecurringPayment.IsEndless)
            {
                SelectedPayment.RecurringPayment.EndDate = DateTime.Today;
            }

            Title = PaymentTypeHelper.GetViewTitleForType(parameter.PaymentType, true);
            base.Prepare(parameter);
        }
コード例 #9
0
        protected override async Task Initialize()
        {
            await base.Initialize();

            SelectedPayment = await crudServices.ReadSingleAsync <PaymentViewModel>(PaymentId);

            // We have to set this here since otherwise the end date is null. This causes a crash on android.
            // Also it's user unfriendly if you the default end date is the 1.1.0001.
            if (SelectedPayment.IsRecurring && SelectedPayment.RecurringPayment.IsEndless)
            {
                SelectedPayment.RecurringPayment.EndDate = DateTime.Today;
            }

            Title = PaymentTypeHelper.GetViewTitleForType(SelectedPayment.Type, true);
        }
コード例 #10
0
        /// <inheritdoc />
        public override async Task Initialize()
        {
            Title = (await crudServices.ReadSingleAsync <AccountViewModel>(AccountId).ConfigureAwait(true)).Name;

            BalanceViewModel = new PaymentListBalanceViewModel(crudServices, balanceCalculationService, AccountId,
                                                               logProvider, navigationService);
            ViewActionViewModel = new PaymentListViewActionViewModel(crudServices,
                                                                     settingsFacade,
                                                                     dialogService,
                                                                     BalanceViewModel,
                                                                     messenger,
                                                                     AccountId,
                                                                     logProvider,
                                                                     navigationService);
        }
コード例 #11
0
 public override async void Prepare(ModifyAccountParameter parameter)
 {
     base.Prepare(parameter);
     SelectedAccount = await crudServices.ReadSingleAsync <AccountViewModel>(AccountId)
                       .ConfigureAwait(true);
 }
 public async Task <ActionResult <WebApiMessageAndResult <TodoItemHybrid> > > GetSingleAsync(int id, [FromServices] ICrudServicesAsync service)
 {
     return(service.Response(await service.ReadSingleAsync <TodoItemHybrid>(id)));
 }
コード例 #13
0
        protected override async Task Initialize()
        {
            SelectedAccount = await crudServices.ReadSingleAsync <AccountViewModel>(AccountId);

            Title = string.Format(CultureInfo.InvariantCulture, Strings.EditAccountTitle, SelectedAccount.Name);
        }
コード例 #14
0
        protected override async Task Initialize()
        {
            SelectedCategory = await crudServices.ReadSingleAsync <CategoryViewModel>(CategoryId);

            Title = string.Format(CultureInfo.InvariantCulture, Strings.EditCategoryTitle, SelectedCategory.Name);
        }
コード例 #15
0
        public async Task UpdateSecondaryLiveTiles()
        {
            IReadOnlyList <SecondaryTile> tiles = await SecondaryTile.FindAllForPackageAsync();

            if (tiles == null)
            {
                return;
            }

            foreach (SecondaryTile item in tiles)
            {
                AccountViewModel acct = await crudService.ReadSingleAsync <AccountViewModel>(int.Parse(item.TileId));

                List <string> displayContent = GetSecondaryPayments(int.Parse(item.TileId));
                var           content        = new TileContent
                {
                    Visual = new TileVisual
                    {
                        TileSmall = new TileBinding
                        {
                            Content = new TileBindingContentAdaptive
                            {
                                Children =
                                {
                                    new AdaptiveGroup
                                    {
                                        Children =
                                        {
                                            new AdaptiveSubgroup
                                            {
                                                Children =
                                                {
                                                    new AdaptiveText
                                                    {
                                                        Text      = acct.Name,
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = LiveTileHelper.TruncateNumber(acct.CurrentBalance),
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        },
                        TileMedium = new TileBinding
                        {
                            Content = new TileBindingContentAdaptive
                            {
                                Children =
                                {
                                    new AdaptiveGroup
                                    {
                                        Children =
                                        {
                                            new AdaptiveSubgroup
                                            {
                                                Children =
                                                {
                                                    new AdaptiveText
                                                    {
                                                        Text      = acct.Name,
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileAccountBalance,
                                                                             acct.CurrentBalance.ToString("C2",
                                                                                                          CultureInfo.InvariantCulture)),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = Strings.ExpenseLabel,
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileLastMonthsExpenses,
                                                                             DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(
                                                                                 DateTime.Now.AddMonths(-1).Month),
                                                                             LiveTileHelper.TruncateNumber(
                                                                                 GetMonthExpenses(
                                                                                     DateTime.Now.AddMonths(-1).Month, DateTime.Now.Year,
                                                                                     acct))),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileCurrentMonthsExpenses,
                                                                             DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(
                                                                                 DateTime.Now.Month),
                                                                             LiveTileHelper.TruncateNumber(
                                                                                 GetMonthExpenses(
                                                                                     DateTime.Now.Month, DateTime.Now.Year, acct))),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        },
                        TileWide = new TileBinding
                        {
                            Content = new TileBindingContentAdaptive
                            {
                                Children =
                                {
                                    new AdaptiveGroup
                                    {
                                        Children =
                                        {
                                            new AdaptiveSubgroup
                                            {
                                                Children =
                                                {
                                                    new AdaptiveText
                                                    {
                                                        Text      = acct.Name,
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileAccountBalance,
                                                                             acct.CurrentBalance.ToString("C2",
                                                                                                          CultureInfo.InvariantCulture)),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = Strings.ExpenseLabel,
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileLastMonthsExpenses,
                                                                             DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(
                                                                                 DateTime.Now.AddMonths(-1).Month),
                                                                             GetMonthExpenses(
                                                                                 DateTime.Now.AddMonths(-1).Month, DateTime.Now.Year,
                                                                                 acct).ToString("C2", CultureInfo.InvariantCulture)),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileCurrentMonthsExpenses,
                                                                             DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(
                                                                                 DateTime.Now.Month),
                                                                             GetMonthExpenses(
                                                                                 DateTime.Now.Month, DateTime.Now.Year, acct)
                                                                             .ToString("C2", CultureInfo.InvariantCulture)),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        },
                        TileLarge = new TileBinding
                        {
                            Content = new TileBindingContentAdaptive
                            {
                                Children =
                                {
                                    new AdaptiveGroup
                                    {
                                        Children =
                                        {
                                            new AdaptiveSubgroup
                                            {
                                                Children =
                                                {
                                                    new AdaptiveText
                                                    {
                                                        Text      = acct.Name,
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileAccountBalance,
                                                                             acct.CurrentBalance.ToString("C2",
                                                                                                          CultureInfo.InvariantCulture)),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = Strings.ExpenseLabel,
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileLastMonthsExpenses,
                                                                             DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(
                                                                                 DateTime.Now.AddMonths(-1).Month),
                                                                             GetMonthExpenses(
                                                                                 DateTime.Now.AddMonths(-1).Month, DateTime.Now.Year,
                                                                                 acct).ToString("C2", CultureInfo.InvariantCulture)),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileCurrentMonthsExpenses,
                                                                             DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(
                                                                                 DateTime.Now.Month),
                                                                             GetMonthExpenses(
                                                                                 DateTime.Now.Month, DateTime.Now.Year, acct)
                                                                             .ToString("C2", CultureInfo.InvariantCulture)),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = Strings.LiveTilePastPayments,
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = displayContent[0],
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = displayContent[1],
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = displayContent[2],
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = displayContent[3],
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = displayContent[4],
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = displayContent[5],
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                };

                var tn = new TileNotification(content.GetXml());
                TileUpdateManager.CreateTileUpdaterForSecondaryTile(item.TileId).Update(tn);
            }
        }
コード例 #16
0
        /// <summary>
        ///     Calculates the sum of all accounts at the current moment.
        /// </summary>
        /// <returns>Sum of the balance of all accounts.</returns>
        protected override async Task <double> CalculateTotalBalance()
        {
            AccountViewModel account = await crudServices.ReadSingleAsync <AccountViewModel>(accountId);

            return(account.CurrentBalance);
        }
コード例 #17
0
        public async Task <ActionResult <WebApiMessageAndResult <TodoItem> > > GetSingleAsync(int id, [FromServices] ICrudServicesAsync service)
        {
            var result = await service.ReadSingleAsync <TodoItem>(id);

            return(service.Response(result));
        }
コード例 #18
0
 public override void Prepare(ModifyPaymentParameter parameter)
 {
     SelectedPayment = crudServices.ReadSingleAsync <PaymentViewModel>(parameter.PaymentId).Result;
     Title           = PaymentTypeHelper.GetViewTitleForType(parameter.PaymentType, true);
     base.Prepare(parameter);
 }