Exemplo n.º 1
0
        public KeeperModel AddKeeper(string key, string initKey)
        {
            lock (_runningLock)
            {
                if (IsRunning)
                {
                    throw new InvalidOperationException("Cannot operate during runnning");
                }

                var plugin = PluginHelper.Find(key);
                if (plugin == null)
                {
                    throw new KeyNotFoundException($"plugin [{key}] is not found");
                }

                var newKeeper = new KeeperModel
                {
                    Key = key, InitKey = initKey
                };
                if (KeeperInfos.Any(p => p.Equals(newKeeper)))
                {
                    throw new InvalidOperationException("the keeper is existed");
                }

                KeeperInfos.Add(newKeeper);

                return(newKeeper);
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,HiveCount,IdentityUserId")] KeeperModel keeperModel)
        {
            if (id != keeperModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(keeperModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!KeeperModelExists(keeperModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdentityUserId"] = new SelectList(_context.Users, "Id", "Id", keeperModel.IdentityUserId);
            return(View(keeperModel));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("FirstName,LastName,HiveCount")] KeeperModel keeperModel)
        {
            if (ModelState.IsValid)
            {
                var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                keeperModel.IdentityUserId = userId;
                _context.Add(keeperModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdentityUserId"] = new KeeperModel();
            return(View(keeperModel));
        }