示例#1
0
        public async Task <IActionResult> Edit(uint id, [Bind("Id,Name")] Tag tag)
        {
            if (id != tag.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tag);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TagExists(tag.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tag));
        }
        public async Task <IActionResult> Edit(uint id, [Bind("Id,Text,PostId,UserId")] Comment comment)
        {
            if (id != comment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(comment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CommentExists(comment.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PostId"] = new SelectList(_context.Posts, "Id", "Text", comment.PostId);
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Email", comment.UserId);
            return(View(comment));
        }
示例#3
0
        public async Task <IActionResult> Edit(uint id, [Bind("Id,Name,CountryId")] City city)
        {
            if (id != city.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(city);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CityExists(city.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryId"] = new SelectList(_context.Countries, "Id", "Name", city.CountryId);
            return(View(city));
        }
        public async Task <IActionResult> Edit(uint id, PostVM viewModel)
        {
            if (id != viewModel.Post.Id)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                Post post = viewModel.Post;
                post.CreatedAt = DateTime.Now;
                _context.PostTag.RemoveRange(_context.PostTag.Where(pt => pt.PostId == id));
                await _context.SaveChangesAsync();

                if (!(viewModel.SelectedTags is null))
                {
                    foreach (var postTagId in viewModel.SelectedTags)
                    {
                        _context.PostTag.Add(new PostTag {
                            TagId = postTagId, PostId = post.Id
                        });
                    }
                }
                _context.Update(post);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostExists(viewModel.Post.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToAction(nameof(Index)));
        }
示例#5
0
 public void Update(Country country)
 {
     _context.Update(country);
 }