Пример #1
0
        public async Task <IActionResult> Edit(Guid id, [Bind("SampleColumn,Id,OrderNumber,RowVersion,IsDeleted,CreationTime,LastModificationTime,CreationUserId,LastModificationUserId")] Domain.Sample.Domain domain)
        {
            if (id != domain.Id)
            {
                return(NotFoundView());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    domain.LastModificationUserId = new Guid(HttpContext.User.GetSubjectId());
                    _context.Update(domain);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DomainExists(domain.Id))
                    {
                        return(NotFoundView());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CreationUserId"]         = new SelectList(_context.Users, "Id", "Id", domain.CreationUserId);
            ViewData["LastModificationUserId"] = new SelectList(_context.Users, "Id", "Id", domain.LastModificationUserId);
            return(View(domain));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("SampleColumn,Id,OrderNumber,RowVersion,IsDeleted,CreationTime,LastModificationTime,CreationUserId,LastModificationUserId")] Domain.Sample.Domain domain)
        {
            if (ModelState.IsValid)
            {
                domain.Id             = Guid.NewGuid();
                domain.CreationUserId = new Guid(HttpContext.User.GetSubjectId());
                //导航属性的优先级高于显式外键属性,如果导航属性与外键属性冲突,以导航属性为准
                //domain.CreationUser = await _userManager.FindByNameAsync("alice");
                _context.Add(domain);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CreationUserId"]         = new SelectList(_context.Users, "Id", "Id", domain.CreationUserId);
            ViewData["LastModificationUserId"] = new SelectList(_context.Users, "Id", "Id", domain.LastModificationUserId);
            return(View(domain));
        }