コード例 #1
0
ファイル: ZVotesController.cs プロジェクト: larryw3i/toupiao
        public async Task <IActionResult> Edit(Guid id,
                                               [Bind("Id,IsLegal")] ZVote zVote)
        {
            if (id != zVote.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var _zVote = await _context.ZVote.FindAsync(id);

                    _zVote.IsLegal = zVote.IsLegal;
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ZVoteExists(zVote.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(zVote));
        }
コード例 #2
0
        public IActionResult XinJian()
        {
            var _zvote = new ZVote()
            {
                DOStart = DateTimeOffset.Now
            };

            ViewData["IsEdit"] = false;
            return(View(_zvote));
        }
コード例 #3
0
ファイル: ZVotesController.cs プロジェクト: larryw3i/toupiao
        public async Task <IActionResult> Create(
            [Bind("Id,Title,DOCreating,DOStart,DOEnd,IsSaveOnly,Description," +
                  "XuanxiangA,XuanxiangB,XuanxiangC,XuanxiangD,IsLegal")] ZVote zVote)
        {
            if (ModelState.IsValid)
            {
                zVote.Id = Guid.NewGuid();
                _context.Add(zVote);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(zVote));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(Guid id,
                                               [Bind("Id,Title,Description,DOEnd,DOStart,CoverImage," +
                                                     "XuanxiangA," +
                                                     "XuanxiangB," +
                                                     "XuanxiangC," +
                                                     "XuanxiangD")]
                                               ZVote zVote)
        {
            if (id != zVote.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (zVote.CoverImage != null)
                    {
                        zVote.CoverPath = await ControllerMix.SaveFormFileAsync(
                            zVote.CoverImage, _env, ModelState,
                            nameof(zVote.CoverImage));
                    }
                    var _user = await _userManager.GetUserAsync(User);

                    zVote.SubmitterId = _user.Id;
                    zVote.Submitter   = _user;

                    _context.Update(zVote);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ZVoteExists(zVote.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(zVote));
        }
コード例 #5
0
        public async Task <IActionResult> Create(
            [Bind("Id,Title,Description,DOEnd,DOStart,CoverImage," +
                  "XuanxiangA," +
                  "XuanxiangB," +
                  "XuanxiangC," +
                  "XuanxiangD")]
            ZVote zVote
            )
        {
            if (ModelState.IsValid)
            {
                if (zVote.Title == null || zVote.Title?.Length < 1)
                {
                    ModelState.AddModelError(
                        nameof(zVote.Title),
                        "请添加一个标题!!");
                    return(View(zVote));
                }
                if (zVote.Description == null || zVote.Description?.Length < 1)
                {
                    ModelState.AddModelError(
                        nameof(zVote.Description),
                        "请添加一个描述!!");
                    return(View(zVote));
                }
                if (zVote.XuanxiangA == null || zVote.XuanxiangA?.Length < 1)
                {
                    ModelState.AddModelError(
                        nameof(zVote.XuanxiangA),
                        "选项A和选项B要填写!");
                    return(View(zVote));
                }
                if (zVote.XuanxiangB == null || zVote.XuanxiangB?.Length < 1)
                {
                    ModelState.AddModelError(
                        nameof(zVote.XuanxiangB),
                        "选项A和选项B要填写!");
                    return(View(zVote));
                }

                zVote.Submitter = await _userManager.GetUserAsync(User);

                zVote.DOCreating = DateTimeOffset.Now;
                zVote.Id         = Guid.NewGuid();

                if (zVote.CoverImage != null)
                {
                    zVote.CoverPath = await ControllerMix.SaveFormFileAsync(
                        zVote.CoverImage, _env, ModelState,
                        nameof(zVote.CoverImage));
                }

                _context.Add(zVote);
                await _context.SaveChangesAsync();

                ViewData["IsEdit"] = false;
                return(RedirectToAction(nameof(Index)));
            }

            return(View(zVote));
        }