// PUT: api/Dashlets/1 public IHttpActionResult PutUpdate(int id, Dashlet dashlet) { if (id == 0) { return(BadRequest()); } var dashletInDb = db.Dashlets.SingleOrDefault(d => d.Id == id); try { var dataSourceToChange = db.DataSources.SingleOrDefault(d => d.Id == dashlet.DataSourceId); dashletInDb.DataSource = dataSourceToChange; dashletInDb.Title = dashlet.Title; dashletInDb.TextType = dashlet.TextType; dashletInDb.Sql = dashlet.Sql; dashletInDb.Styles = dashlet.Styles; dashletInDb.TopSubLevel = dashlet.TopSubLevel; dashletInDb.BottomSubTitle = dashlet.BottomSubTitle; dashletInDb.Column = dashlet.Column; dashletInDb.Position = dashlet.Position; db.SaveChanges(); } catch (Exception e) { return(InternalServerError(e)); } return(Ok(dashletInDb)); }
public ActionResult DeleteConfirmed(int id) { Dashlet dashlet = db.Dashlets.Find(id); db.Dashlets.Remove(dashlet); db.SaveChanges(); return(RedirectToAction("Index")); }
public IHttpActionResult GetDashlet(int id) { Dashlet dashlet = db.Dashlets.Include(d => d.DataSource).SingleOrDefault(X => X.Id == id); if (dashlet == null) { return(NotFound()); } return(Ok(dashlet)); }
public ActionResult Edit([Bind(Include = "Id,Title,Body,DashboardId,DataSourceId,Sql,Styles")] Dashlet dashlet) { if (ModelState.IsValid) { db.Entry(dashlet).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DashboardId = new SelectList(db.Dashboards, "Id", "Title", dashlet.DashboardId); ViewBag.DataSourceId = new SelectList(db.DataSources, "Id", "ConnectionString", dashlet.DataSourceId); return(View(dashlet)); }
public IHttpActionResult PostDashlet(Dashlet dashlet) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Dashlets.Add(dashlet); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = dashlet.Id }, dashlet)); }
//Save Data private void SaveData() { Dashlet dashlet = new Dashlet(); bool flag = true; try { dashlet.Category = ddlCategory.SelectedValue; dashlet.Title = txtTitle.Text.Trim(); dashlet.Link = txtLink.Text.Trim(); dashlet.Icon = txtIcon.Attributes["key"]; dashlet.Description = txtDescription.Text.Trim(); dashlet.InstanceMethod = txtInstanceMethod.Text.Trim(); dashlet.InstanceParameter = txtInstanceParameter.Text.Trim(); using (_session = new Session()) { if (IsAddNew()) { flag = dashlet.Create(_session); } else { dashlet.DashletId = int.Parse(this.hidDashletId.Value); flag = dashlet.Update(_session, "Category", "Title", "Link", "Icon", "Description", "InstanceMethod", "InstanceParameter"); } } this.hidDashletId.Value = dashlet.DashletId.ToString(); if (flag) { WebUtil.ShowMsg(this, "操作成功", "提示"); } else { WebUtil.ShowMsg(this, "操作失败", "提示"); } } catch (UnauthorizedException ex) { WebUtil.ShowMsg(this, ex.Message, "警告"); } catch (ApplicationException ex) { WebUtil.ShowMsg(this, ex.Message, "提示"); } catch (Exception ex) { logger.Info("保存Dashlet", ex); WebUtil.ShowMsg(this, "发生未处理的异常,请刷新页面重新操作,或者联系系统管理员"); } }
// GET: Dashlets/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Dashlet dashlet = db.Dashlets.Find(id); if (dashlet == null) { return(HttpNotFound()); } return(View(dashlet)); }
public IHttpActionResult DeleteDashlet(int id) { Dashlet dashlet = db.Dashlets.Find(id); if (dashlet == null) { return(NotFound()); } db.Dashlets.Remove(dashlet); db.SaveChanges(); return(Ok(dashlet)); }
// GET: Dashlets/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Dashlet dashlet = db.Dashlets.Find(id); if (dashlet == null) { return(HttpNotFound()); } ViewBag.DashboardId = new SelectList(db.Dashboards, "Id", "Title", dashlet.DashboardId); ViewBag.DataSourceId = new SelectList(db.DataSources, "Id", "ConnectionString", dashlet.DataSourceId); return(View(dashlet)); }
public IHttpActionResult Action(Dashlet dashlet) { if (dashlet == null) { return(BadRequest()); } try { dashlet.Dashboard = db.Dashboards.SingleOrDefault(ds => ds.Id == dashlet.DashboardId); dashlet.DataSource = db.DataSources.SingleOrDefault(ds => ds.Id == dashlet.DataSourceId); db.Dashlets.Add(dashlet); db.SaveChanges(); } catch (Exception e) { return(InternalServerError(e)); } return(Ok()); }
public IHttpActionResult PostDashletList(int id = 0, int column = 0, int position = 0, int dashboardid = 0) { if (id == 0 || column == 0) { return(BadRequest()); } var dashletInDb = db.Dashlets.SingleOrDefault(d => d.Id == id); if (dashletInDb == null) { var dashlet = new Dashlet(); dashlet.Column = column; dashlet.Position = position; dashlet.DataSource = db.DataSources.Where(d => d.Id == 4).SingleOrDefault(); dashlet.Dashboard = db.Dashboards.Where(d => d.Id == dashboardid).SingleOrDefault(); try { db.Dashlets.Add(dashlet); db.SaveChanges(); } catch (Exception e) { return(InternalServerError(e)); } } else { try { dashletInDb.Position = position; dashletInDb.Column = column; db.SaveChanges(); } catch (Exception e) { return(InternalServerError(e)); } } return(Ok()); }
private void LoadData() { hidDashletId.Value = WebUtil.Param("dashletId"); int dashletId = Cast.Int(WebUtil.Param("dashletId")); Dashlet dashlet = null; dashlet = Dashlet.Retrieve(_session, dashletId); if (dashlet != null) { ddlCategory.SelectedValue = dashlet.Category; txtTitle.Text = dashlet.Title; txtLink.Text = dashlet.Link; txtIcon.Text = dashlet.Icon; txtDescription.Text = dashlet.Description; txtInstanceMethod.Text = dashlet.InstanceMethod; txtInstanceParameter.Text = dashlet.InstanceParameter; } }
//MagicToolbar's MagicItem OnClick Event Handler, it's for both the top one and the bottom one. protected void MagicItemCommand(object sender, MagicItemEventArgs e) { try { if (e.CommandName == "Delete") { // do delete using (ISession session = new Session()) { foreach (RepeaterItem item in this.rptDashlet.Items) { HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox; if (chk != null && chk.Checked) { int dashletId = Cast.Int(chk.Attributes["dashletId"]); Dashlet.Delete(session, dashletId); } } QueryAndBindData(1, this.magicPagerMain.PageSize, true); } } } catch (UnauthorizedException ex) { WebUtil.ShowMsg(this, ex.Message, "警告"); } catch (ApplicationException ex) { WebUtil.ShowMsg(this, ex.Message, "提示"); } catch (Exception ex) { logger.Info("删除Dashlet", ex); WebUtil.ShowMsg(this, "发生未处理的异常,请刷新页面重新操作,或者联系系统管理员"); } }
public static string RenderDashlet(Dashlet dashlet) { return("<span>hello, wolrd!</span>"); }