private void btnDelete_Click(object sender, RoutedEventArgs e)
{
try
{
var custorder = lstOrders.SelectedItem;
System.Type type = custorder.GetType();
int orderid = (int)type.GetProperty("OrderID").GetValue(custorder, null);
Order odemo = ctx.Orders.Where(o => o.OrderID == orderid).ToList()[0];
var odt = ctx.Order_Details.Where(od => od.OrderID == orderid).ToList();
foreach(Order_Detail od in odt)
ctx.DeleteObject(od);
ctx.DeleteObject(odemo);
ctx.SaveChanges();
MessageBox.Show("Deleted!");
cmbCustomers_SelectionChanged(null, null);
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString());
}
}
Showing posts with label REST. Show all posts
Showing posts with label REST. Show all posts
Thursday, 3 May 2012
WCF DeleteObject
Because Orders table has a constaint to Order_Details table, the latter has to be deleted also with related Order.
Wednesday, 14 March 2012
SharePoint 2010 REST with ASP.NET
From http://extendtheenterprise.com/2010/11/03/using-sharepoint-2010-rest-apis-in-asp-net/
with some changes to make it work for me.
Default.aspx
Default.aspx.cs
Result
with some changes to make it work for me.
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SPRest._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
table.gridtbl {
background-color: orange;
font-family: tahoma;
}
table.gridtbl TR {
background-color: white;
font-family: tahoma;
}
table.gridtbl TH {
background-color:Gray;
PADDING:4px;
color: White;
font-family: tahoma;
}
table.gridtbl TD {
PADDING:4px;
font-family: tahoma;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" CSSClass="gridtbl" CellSpacing="1" GridLines="None"/>
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SPRest.SUB1DataContext;
using System.Net;
namespace SPRest
{
public partial class _Default : System.Web.UI.Page
{
SPRest.SUB1DataContext.SUB1DataContext context = new SPRest.SUB1DataContext.SUB1DataContext(new Uri("http://blah/_vti_bin/listdata.svc"));
protected void Page_Load(object sender, EventArgs e)
{
context.Credentials = CredentialCache.DefaultNetworkCredentials;
BindData();
}
protected void BindData()
{
var custItems = from c in context.Customer.ToList()
join d in context.Purchases.ToList()
on c.CustomerID equals d.PurchaserID into TMP
from subTMP in TMP.DefaultIfEmpty()
select new
{
c.CustomerID,
c.Name,
OrderNum =(subTMP==null)? "NA" : subTMP.OrderNumber,
Product = (subTMP==null)? "NA" : subTMP.Product,
Qty = (subTMP==null)? null : subTMP.Quantity,
Price = (subTMP==null)? null : subTMP.Price
};
GridView1.DataSource = custItems;
GridView1.DataBind();
}
}
}
Result
Labels:
LINQ,
REST,
SPGridView,
WebParts
Subscribe to:
Posts (Atom)