示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("UserPartsId,UserId,PartsId")] UserParts userParts)
        {
            if (id != userParts.UserPartsId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userParts);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserPartsExists(userParts.UserPartsId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PartsId"] = new SelectList(_context.Parts, "PartsId", "PartName", userParts.PartsId);
            ViewData["UserId"]  = new SelectList(_context.ApplicationUser, "Id", "Id", userParts.UserId);
            return(View(userParts));
        }
示例#2
0
        public async Task <IActionResult> Checkout(int?id, Parts Parts)
        {
            var user = await GetCurrentUserAsync();

            // Parts partsToCheckout = await _context.Parts
            //.Include(p => p.partType)
            // .Include(p => p.UserParts)
            // .FirstOrDefaultAsync(m => m.PartsId == id);
            var parts = await _context.Parts
                        .Include(p => p.partType)
                        .Include(p => p.UserParts)
                        .FirstOrDefaultAsync(m => m.PartsId == id);

            var newPartQuantity = parts.Quantity - 1;

            parts.Quantity = newPartQuantity;
            _context.Update(parts);
            await _context.SaveChangesAsync();


            UserParts newPart = new UserParts()
            {
                UserId  = user.Id,
                PartsId = id.Value
            };

            _context.Add(newPart);

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("UserPartsId,UserId,PartsId")] UserParts userParts)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userParts);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PartsId"] = new SelectList(_context.Parts, "PartsId", "PartName", userParts.PartsId);
            ViewData["UserId"]  = new SelectList(_context.ApplicationUser, "Id", "Id", userParts.UserId);
            return(View(userParts));
        }