public async Task <IActionResult> PostAD([FromBody] ADModel model) { Log.Information("Starting call to the API"); var response = await ValidateNTUser(model); return(Ok(response)); }
public ActionResult ADSubmit(ADModel itemsEntity, long keyValue) { itemsEntity.AeditTime = itemsEntity.ACreatetime = DateTime.Now; var LoginInfo = OperatorProvider.Provider.GetCurrent(); if (LoginInfo != null) { itemsEntity.ACreateUser = LoginInfo.UserId; } AD.SubmitForm(itemsEntity, Convert.ToInt64(keyValue)); return(Success("操作成功。")); }
//添加广告位 protected void Button1_Click(object sender, EventArgs e) { if (showhide("22")) { ADModel am = new ADModel(); am.ADtitle = txtwtitle.Text; am.ADShowHide = BasePage.GetRequestId(Rshowhide.SelectedValue); am.ADwidth = BasePage.GetRequestId(txtwwidth.Text); am.ADheight = BasePage.GetRequestId(txtwheight.Text); am.ADcontents = txtwcontents.Text; am.IsAD = 1; //0为广告,1为广告位 am.Tid = 0; //广告位和单条广告时tid都为0 am.Px = BasePage.GetRequestId(txtadpx.Text); am.id = id; if (id == 0) { int i = new ADBll().Add(am); if (i > 0) { BasePage.JscriptPrint(Page, "添加成功!", "AD.aspx?tid=" + i); } } else { bool b = new ADBll().Update(am); if (b) { BasePage.JscriptPrint(Page, "修改成功!", "AD.aspx?tid=" + id); } } } else { BasePage.Alertback("添加失败,您不能添加广告位!"); Response.End(); } }
////添加广告 protected void Button2_Click(object sender, EventArgs e) { int adtid = BasePage.GetRequestId(ddltid.SelectedValue); //已有广告位 int adtype = BasePage.GetRequestId(Rdtype.SelectedValue); //展示类型 int adwidth = BasePage.GetRequestId(txtwidth1.Text), adheight = BasePage.GetRequestId(txtheight1.Text); ADModel am = new ADModel(); am.ADtitle = txtttile.Text; am.Tid = adtid; am.ADShowHide = BasePage.GetRequestId(rashowhide.SelectedValue); am.ADtype = adtype; am.ADurl = txtfile.Text; am.ADhttpurl = txthttp.Text; am.Px = BasePage.GetRequestId(txtpx.Text); am.IsAD = 0; //如果已有广告位时,宽高读取广告位的 if (adtid != 0) { ADModel ad = new ADBll().GetModel(adtid); adwidth = BasePage.GetRequestId(ad.ADwidth.ToString()); adheight = BasePage.GetRequestId(ad.ADheight.ToString()); } am.ADwidth = adwidth; am.ADheight = adheight; //展示类型为代码时 if (adtype == 2) { //代码 am.ADcontents = txtcontents.Text; } else if (adtype == 1) { //图片 if (String.IsNullOrEmpty(txthttp.Text.Trim()) || txthttp.Text == "#") { am.ADcontents = "<img src=\"" + txtfile.Text.Trim() + "\" width=\"" + adwidth + "\" height=\"" + adheight + "\" alt=\"\" />"; } else { am.ADcontents = "<a href=\"" + txthttp.Text + "\"><img src=\"" + txtfile.Text.Trim() + "\" width=\"" + adwidth + "\" height=\"" + adheight + "\" alt=\"\" /></a>"; } } am.id = id; string gourl = ""; if (ddltid.SelectedValue == "0") { gourl = "AD.aspx"; } else { gourl = "AD.aspx?tid=" + ddltid.SelectedValue; } if (id == 0) { if (showhide("18")) { int i = new ADBll().Add(am); if (i > 0) { BasePage.JscriptPrint(Page, "添加成功!", gourl); } } else { BasePage.Alertback("添加失败,你不能添加广告!"); Response.End(); } } else { bool b = new ADBll().Update(am); if (b) { BasePage.JscriptPrint(Page, "修改成功!", gourl); } } }
private async Task <ADResponse> ValidateNTUser(ADModel model) { return(await Task.Run(() => { if (model == null) { Log.Error("NT User paramter cannot be empty"); return new ADResponse() { ErrorMessage = "NT User paramter cannot be empty", Status = StatusType.Failed, UserExist = false }; } if (string.IsNullOrEmpty(model.username) || string.IsNullOrEmpty(model.password) || string.IsNullOrEmpty(model.key)) { Log.Error("NT User either username or password or key is empty"); return new ADResponse() { ErrorMessage = "NT User either username or password or key is empty", Status = StatusType.Failed, UserExist = false }; } string passkey = _config["appkey"]; if (passkey != model.key) { Log.Error("Application key is not valid"); return new ADResponse() { ErrorMessage = "Application key is not valid", Status = StatusType.Failed, UserExist = false }; } model.username = model.username.ToLower(); bool login_response = _Service.authlogindetails(model.username, model.password); if (!login_response) { Log.Error("Username or password invalid"); return new ADResponse() { ErrorMessage = "Username or password invalid", Status = StatusType.Failed, UserExist = false }; } var searchResult = _Service.GetUserDirectoryEntryDetails(model.username); if (searchResult == null) { Log.Error("User search information cannot be found"); return new ADResponse() { ErrorMessage = "User search information cannot be found", Status = StatusType.Failed, UserExist = false }; } _Service.PopulateUserDataStruct(searchResult); var userData = _Service.GetUserData(model.username); var groups = _Service.Getmemberof(searchResult); Log.Information("Active directory calls successful"); return new ADResponse() { UserExist = true, UserGroup = string.Join(",", groups.ToArray()), Status = StatusType.Success }; })); }