示例#1
0
        public ActionResult Remove(string itemId)
        {
            if (string.IsNullOrEmpty(itemId))
            {
                ViewData["Message"] = "No key provided";
                return(View("Error"));
            }

            IModuleInfo item = _repositoryModel.ModuleInfosList
                               .Where(x => x.Id.Equals(itemId))
                               .Select(x => x)
                               .DefaultIfEmpty(null)
                               .SingleOrDefault();

            if (item == null)
            {
                ViewData["Message"] = "Key could not be found in database";
                return(View("Error"));
            }

            try
            {
                _repositoryModel.RemoveModule(item);
            }
            catch (Exception e)
            {
                ViewData["Message"] = e.Message;
                return(View("Error"));
            }

            return(RedirectToAction("Index"));
        }
 public void passign_null_to_remove_raises_exception()
 {
     Assert.Throws <ArgumentNullException>(() => _repositoryModel.RemoveModule(null));
 }