Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("ID,Kategorie,CategoryForeignkey,Name,OwnerForeignkey,BorrowerForeignkey,Discription,Status")] Item item)
        {
            if (ModelState.IsValid)
            {
                if (item.Status == false)
                {
                    item.BorrowerForeignkey = null;
                }
                else
                {
                    item.BorrowerForeignkey = item.OwnerForeignkey;
                }
                _context.Add(item);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OwnerForeignkey"] = new SelectList(_context.User, "ID", "Login", item.OwnerForeignkey);
            item.BorrowerForeignkey     = CreateDummy().ID;
            _context.User.Add(CreateDummy());

            ViewData["BorrowerForeignkey"] = new SelectList(_context.User, "ID", "Login", item.BorrowerForeignkey);
            ViewData["CategoryForeignkey"] = new SelectList(_context.Category, "ID", "Name", item.CategoryForeignkey);

            return(View(item));
        }
        public async Task <IActionResult> Create([Bind("ID,Login,Surname,Lastname,EMail,Password")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("ID,Name,Info")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

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