Example #1
0
        public async Task <IActionResult> Create([Bind("Id,PatPieceId,StyleId")] PatPieceStyle patPieceStyle)
        {
            var user = _userManger.GetUserName(HttpContext.User);

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

                var styleName   = "";
                var patternName = "";

                foreach (var item in _context.Style)
                {
                    if (item.Id == patPieceStyle.StyleId)
                    {
                        styleName = item.Title;
                    }
                }
                foreach (var item in _context.PatternPiece)
                {
                    if (item.Id == patPieceStyle.PatPieceId)
                    {
                        patternName = item.Title;
                    }
                }
                logger.Info(user + " added " + patternName + " to " + styleName);

                return(RedirectToAction("Details", "Styles", new { id = patPieceStyle.StyleId }));
            }
            ViewData["PatPieceId"] = new SelectList(_context.PatternPiece, "Id", "Id", patPieceStyle.PatPieceId);
            ViewData["StyleId"]    = new SelectList(_context.Style, "Id", "Id", patPieceStyle.StyleId);
            return(View(patPieceStyle));
        }
Example #2
0
        // GET: PatPieceStyles/Create
        public IActionResult Create(int?Id)
        {
            ViewData["PatPieceId"] = new SelectList(_context.PatternPiece, "Id", "Title");
            PatPieceStyle model = new PatPieceStyle
            {
                StyleId = Id ?? default(int),
            };


            return(View(model));
        }
Example #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,PatPieceId,StyleId")] PatPieceStyle patPieceStyle)
        {
            var user = _userManger.GetUserName(HttpContext.User);

            if (id != patPieceStyle.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var styleName   = "";
                    var patternName = "";
                    foreach (var item in _context.Style)
                    {
                        if (item.Id == patPieceStyle.StyleId)
                        {
                            styleName = item.Title;
                        }
                    }
                    foreach (var item in _context.PatternPiece)
                    {
                        if (item.Id == patPieceStyle.PatPieceId)
                        {
                            patternName = item.Title;
                        }
                    }
                    _context.Update(patPieceStyle);
                    await _context.SaveChangesAsync();

                    logger.Info(user + " edited " + styleName + " and " + patternName);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PatPieceStyleExists(patPieceStyle.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Details", "PatternPieces", new { id = patPieceStyle.PatPieceId }));
            }
            ViewData["PatPieceId"] = new SelectList(_context.PatternPiece, "Id", "Id", patPieceStyle.PatPieceId);
            ViewData["StyleId"]    = new SelectList(_context.Style, "Id", "Title", patPieceStyle.StyleId);
            return(View(patPieceStyle));
        }