コード例 #1
0
        public async Task <IActionResult> Create([Bind("PluginId,Title,UserId,EngineId,PluginTypeId,CommercialUse,Free,Webpage,IsListed,About,Keywords")] Plugin plugin)
        {
            var currentUser = await GetCurrentUserAsync();

            ModelState.Remove("UserId");
            ModelState.Remove("User");

            if (ModelState.IsValid)
            {
                plugin.UserId   = currentUser.Id;
                plugin.IsListed = true;
                _context.Add(plugin);
                await _context.SaveChangesAsync();

                //create inital version
                var version = new Version()
                {
                    Name     = "Initial",
                    PluginId = plugin.PluginId
                };
                //save initial version.
                _context.Add(version);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EngineId"]     = new SelectList(_context.Engines, "EngineId", "Title", plugin.EngineId);
            ViewData["PluginTypeId"] = new SelectList(_context.PluginTypes, "PluginTypeId", "Name", plugin.PluginTypeId);
            return(View(plugin));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("VersionId,Name,ReadMe,PluginId,DownloadLink,Iteration")] Version version)
        {
            ModelState.Remove("UserId");
            ModelState.Remove("User");

            if (ModelState.IsValid)
            {
                //set iteration to one plus the number of versions that already have this version's pluginId.
                version.Iteration = _context.Versions.Where(v => v.PluginId == version.PluginId).Count() + 1;
                _context.Add(version);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                //go to plugin details when creating new version.
                return(RedirectToAction("Details", "Plugins", new { id = version.PluginId }));
            }
            ViewData["PluginId"] = new SelectList(_context.Plugins, "PluginId", "Title", version.PluginId);
            return(View(version));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("VersionId,Name,ReadMe,PluginId,DownloadLink,Iteration")] Version version)
        {
            if (id != version.VersionId)
            {
                return(NotFound());
            }

            ModelState.Remove("UserId");
            ModelState.Remove("User");


            if (ModelState.IsValid)
            {
                try
                {
                    //get iteration from original version, but remember to remove the oriignal version from _context or there will be errors resulting from duplicate Ids.
                    var OldVersion = _context.Versions.FirstOrDefault(v => v.VersionId == version.VersionId);
                    _context.Remove(OldVersion);
                    version.Iteration = OldVersion.Iteration;
                    _context.Update(version);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VersionExists(version.VersionId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //redirect back to plugin details list.
                return(RedirectToAction("Index", "Versions", new { id = version.PluginId }));
            }
            ViewData["PluginId"] = new SelectList(_context.Plugins, "PluginId", "Title", version.PluginId);
            return(View(version));
        }