public async Task <IActionResult> Put(AddAppInfoModel model) { string appkey = Guid.NewGuid().ToString() + model.Email; string appsecret = Guid.NewGuid().ToString(); if (await AppInfoSvc.GetByAppKeyAsync(appkey) != null) { return(new JsonResult(new APIResult <int> { ErrorMsg = "appkey存在" }) { StatusCode = 400 }); } AddAppInfoDTO dto = new AddAppInfoDTO(); dto.AppKey = appkey; dto.AppSecret = appsecret; dto.Email = model.Email; await AppInfoSvc.AddNewAsync(dto); return(new JsonResult(new APIResult <AddAppInfoDTO> { Data = dto })); }
public async Task <long> AddNewAsync(AddAppInfoDTO dot) { AppInfoEntity entity = new AppInfoEntity(); entity.AppKey = dot.AppKey; entity.AppSecret = dot.AppSecret; entity.Email = dot.Email; using (OtherContext ctx = new OtherContext()) { BaseService <AppInfoEntity> bs = new BaseService <AppInfoEntity>(ctx); var appinfo = await bs.GetAll().SingleOrDefaultAsync(e => e.Email == dot.Email); if (appinfo != null) { throw new Exception("邮箱已存在"); } await ctx.AppInfos.AddAsync(entity); await ctx.SaveChangesAsync(); return(entity.Id); } }