Beispiel #1
0
        public async Task <IActionResult> Create([Bind("Id,TypeId,Date,Text")] Publication publication, params int[] selectedLists)
        {
            if (ModelState.IsValid)
            {
                _context.Add(publication);
                await _context.SaveChangesAsync();

                //   var work_user = new Work_User { WorkId=publication.Id, UserId = int.Parse(_userManager.GetUserId(User))};
                //   _context.Work_Users.Add(work_user);
                var use = _userManager.GetUserId(User);
                if (use != null)
                {
                    var work_user1 = new Work_User {
                        PublicationId = publication.Id, UserId = use
                    };
                    _context.Work_Users.Add(work_user1);
                    await _context.SaveChangesAsync();
                }
                //await _context.SaveChangesAsync();
                return(RedirectToAction(nameof(Index)));
            }

            ViewData["TypeId"] = new SelectList(_context.Work_Enums, "Id", "Name", publication.TypeId);
            return(View(publication));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,WorkId,UserId")] Work_User work_User)
        {
            if (id != work_User.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(work_User);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Work_UserExists(work_User.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["WorkId"] = new SelectList(_context.Works, "Id", "Id", work_User.WorkId);
            return(View(work_User));
        }
Beispiel #3
0
        public void CanChangeWorkUserUserId()
        {
            var u = new Work_User {
                Id = 3, PublicationId = 4, UserId = "5"
            };

            u.UserId = "6";
            Assert.Equal("6", u.UserId);
        }
Beispiel #4
0
        public void CanChangeWorkUserPublicationId()
        {
            var u = new Work_User {
                Id = 3, PublicationId = 2, UserId = "5"
            };

            u.PublicationId = 4;
            Assert.Equal(4, u.PublicationId);
        }
        public async Task <IActionResult> Create([Bind("Id,WorkId,UserId")] Work_User work_User)
        {
            if (ModelState.IsValid)
            {
                _context.Add(work_User);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["WorkId"] = new SelectList(_context.Works, "Id", "Id", work_User.WorkId);
            return(View(work_User));
        }