Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Price,DayDuration,MonthDuration")] SubscriptionListing subscriptionListing)
        {
            if (id != subscriptionListing.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(subscriptionListing);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SubscriptionListingExists(subscriptionListing.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(subscriptionListing));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("Id,Title,Price,DayDuration,MonthDuration")] SubscriptionListingViewModel vm)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var user   = _context.Users.Find(userId);

            vm.User = user;
            SubscriptionListing listing = (SubscriptionListing)vm;

            if (ModelState.IsValid)
            {
                _context.Add(listing);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vm));
        }