public void CreateAppTest()
        {
            OpenEcnuRepository repo = new OpenEcnuRepository(new OpenEcnuContext());

            AppInfo app = new AppInfo
            {
                appsecret = "12341234123412341234",
                redirecturi = "123",
                owner = "10102130253",
                name = "Test2",
                description = "Test2"
            };

            bool result = repo.UpdateApp(1, app);

            Assert.IsTrue(result);
        }
 /// <summary>
 /// 创建APP
 /// </summary>
 /// <param name="app">要创建的AppInfo对象</param>
 /// <returns>指示创建是否成功</returns>
 /// <exception cref="System.Data.DataException"></exception>
 public bool CreateApp(AppInfo app)
 {
     try
     {
         dbContext.AppInfoes.Add(app);
         if (!SaveAll())
             throw new DataException();
         log.InfoFormat("创建appkey为{0}的app成功", app.appkey);
         return true;
     }
     catch (DataException ex)
     {
         log.ErrorFormat("创建appkey为{0}的app失败", app.appkey);
         log.Error("异常信息:", ex);
         return false;
     }
     catch (Exception ex)
     {
         log.Fatal("未知异常:", ex);
         return false;
     }
 }
Beispiel #3
0
        public ActionResult Create(AppModel appModel)
        {
            if (ModelState.IsValid)
            {
                AppInfo newApp = new AppInfo
                {
                    appsecret = RandomString.RandomStringImpl.CreateRandomString(20),
                    name = appModel.Name,
                    description = appModel.Description,
                    redirecturi = appModel.RedirectUri,
                    owner = GetUserId()
                };
                if (repo.CreateApp(newApp))
                {
                    AppInfo theApp = repo.GetAppInfo(newApp.name);
                    return RedirectToAction("Detail", "App", new { appKey = theApp.appkey });
                }
                ViewBag.ErrorMessage = "对不起,这个应用已经有人申请过了!请换个名字试试";
            }

            ViewBag.UserName = repo.GetUsersDetail(GetUserId()).Name;
            return View(appModel);
        }
Beispiel #4
0
 public ActionResult Modify(AppModel model)
 {
     if (ModelState.IsValid)
     {
         AppInfo newAppInfo = new AppInfo
         {
             appsecret = model.AppSecret,
             owner = model.Owner,
             name = model.Name,
             redirecturi = model.RedirectUri,
             description = model.Description
         };
         if (repo.UpdateApp(model.AppKey, newAppInfo))
             return RedirectToAction("Detail", new { appKey = model.AppKey });
         ModelState.AddModelError("", "Update Failed");
         ViewBag.ErrorMessage = "你所使用的应用名称已被使用,请换一个试试!";
     }
     ViewBag.UserName = repo.GetUsersDetail(GetUserId()).Name;
     return View(model);
 }
 /// <summary>
 /// 修改指定ID的APP信息
 /// </summary>
 /// <param name="appKey">应用的AppKey</param>
 /// <param name="newAppInfo">新的AppInfo,用于覆盖旧的AppInfo</param>
 /// <returns>指示修改是否成功</returns>
 /// <exception cref="System.Data.DataException"></exception>
 public bool UpdateApp(int appKey, AppInfo newAppInfo)
 {
     AppInfo oldAppInfo = dbContext.AppInfoes.Find(appKey);
     // 目前仅允许修改应用的名称、描述和回调地址
     // 2014-04-10 更新:允许修改所有者
     oldAppInfo.name = newAppInfo.name;
     oldAppInfo.description = newAppInfo.description;
     oldAppInfo.redirecturi = newAppInfo.redirecturi;
     oldAppInfo.owner = newAppInfo.owner;
     try
     {
         dbContext.Entry(oldAppInfo).State = EntityState.Modified;
         if (!SaveAll())
             throw new DataException();
         log.InfoFormat("修改appkey为{0}的app信息成功", appKey);
         return true;
     }
     catch (DataException ex)
     {
         log.ErrorFormat("修改appkey为{0}的app失败", appKey);
         log.Error("异常信息:", ex);
         return false;
     }
     catch (Exception ex)
     {
         log.Fatal("未知异常:", ex);
         return false;
     }
 }