public async Task <IActionResult> Create([Bind("Id,PatPieceId,VariationId")] PatPieceVariation patPieceVariation)
        {
            var user = _userManger.GetUserName(HttpContext.User);

            patPieceVariation.Id = 0;
            if (ModelState.IsValid)
            {
                _context.Add(patPieceVariation);
                await _context.SaveChangesAsync();

                var variationName = "";
                var patternName   = "";

                foreach (var item in _context.Style)
                {
                    if (item.Id == patPieceVariation.VariationId)
                    {
                        variationName = item.Title;
                    }
                }
                foreach (var item in _context.PatternPiece)
                {
                    if (item.Id == patPieceVariation.PatPieceId)
                    {
                        patternName = item.Title;
                    }
                }
                logger.Info(user + " added " + patternName + " to " + variationName);
                return(RedirectToAction("Details", "Variations", new { id = patPieceVariation.VariationId }));
            }
            ViewData["PatPieceId"] = patPieceVariation.PatPieceId;
            ViewData["PatPieceId"] = new SelectList(_context.PatternPiece, "Id", "Title");
            return(View(patPieceVariation));
        }
        // GET: PatPieceVariations/Create
        public IActionResult Create(int?id)
        {
            PatPieceVariation model = new PatPieceVariation
            {
                VariationId = id ?? default(int),
            };

            ViewData["PatPieceId"] = new SelectList(_context.PatternPiece, "Id", "Title");
            return(View(model));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,PatPieceId,VariationId")] PatPieceVariation patPieceVariation)
        {
            if (id != patPieceVariation.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var user         = _userManger.GetUserName(HttpContext.User);
                    var patVariation = "";
                    var patPiece     = "";
                    foreach (var item in _context.Variation)
                    {
                        if (patPieceVariation.PatPieceId == item.Id)
                        {
                            patVariation = item.Title;
                        }
                    }
                    foreach (var item in _context.PatternPiece)
                    {
                        if (patPieceVariation.PatPieceId == item.Id)
                        {
                            patPiece = item.Title;
                        }
                    }
                    _context.Update(patPieceVariation);
                    await _context.SaveChangesAsync();

                    logger.Info(user + " edited to " + patPiece + " and " + patVariation);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PatPieceVariationExists(patPieceVariation.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Details", "PatternPieces", new { id = patPieceVariation.PatPieceId }));
            }
            ViewData["PatPieceId"]  = new SelectList(_context.PatternPiece, "Id", "Id", patPieceVariation.PatPieceId);
            ViewData["VariationId"] = new SelectList(_context.Variation, "Id", "Title", patPieceVariation.VariationId);
            return(View(patPieceVariation));
        }