Exemple #1
0
        public async Task <IActionResult> Edit(int id, SubscriptionPlanPrice entitySaleablePrice)
        {
            if (id != entitySaleablePrice.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(entitySaleablePrice);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EntitySaleablePriceExists(entitySaleablePrice.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToBaseEntity(entitySaleablePrice.EntityId));
            }
            ViewData["CurrencyId"] = new SelectList(_context.Currencies, "Id", "Key", entitySaleablePrice.CurrencyId);
            ViewData["EntityId"]   = new SelectList(_context.SubscriptionsPlans, "Id", "Id", entitySaleablePrice.EntityId);
            return(View(entitySaleablePrice));
        }
Exemple #2
0
        public async Task <IActionResult> Create(SubscriptionPlanPrice entitySaleablePrice)
        {
            if (ModelState.IsValid)
            {
                _context.SubscriptionsPlansPrices.Add(entitySaleablePrice);
                await _context.SaveChangesAsync();

                return(RedirectToBaseEntity(entitySaleablePrice.EntityId));
            }
            ViewData["CurrencyId"] = new SelectList(_context.Currencies, "Id", "Key", entitySaleablePrice.CurrencyId);
            ViewData["EntityId"]   = new SelectList(_context.SubscriptionsPlans, "Id", "Id", entitySaleablePrice.EntityId);
            return(View(entitySaleablePrice));
        }
Exemple #3
0
        public async Task <List <SubscriptionPlan> > FindAll()
        {
            using (var conn = OpenConnection()) {
                using (var reader = await conn.QueryMultipleAsync(
                           @"select sp.*, br.* from subscription_plans sp
                    join billing_references br on sp.billing_reference_id = br.id;

                  select spp.*, br2.* from subscription_plan_prices spp
                    join subscription_plans sp on spp.plan_id = sp.id
                    join billing_references br2 on sp.billing_reference_id = br2.id;
                ")
                       ) {
                    var plans = reader.Read <SubscriptionPlanRow, BillingReferenceRow, SubscriptionPlan>(
                        (sp, br) => new SubscriptionPlan(
                            sp.Id,
                            sp.Name,
                            sp.Description,
                            BillingReference.Product(br.BillingId),
                            roleId: sp.RoleId
                            )
                        );

                    var planDict = new Dictionary <Guid, SubscriptionPlan>(plans.Select(p => KeyValuePair.Create(p.Id, p)));

                    var prices = reader.Read <SubscriptionPlanPriceRow, BillingReferenceRow, SubscriptionPlanPrice>(
                        (spp, br) => {
                        var price = new SubscriptionPlanPrice(
                            spp.Price,
                            spp.Interval,
                            new BillingReference(
                                br.BillingId,
                                br.Type
                                )
                            );

                        planDict[spp.PlanId].Prices.Add(price);

                        return(price);
                    }
                        );

                    return(plans.ToList());
                }
            }
        }