private void DeleteFromContext(Entity entity) { if (!_serviceContext.IsAttached(entity)) { _serviceContext.Attach(entity); } _serviceContext.DeleteObject(entity); _serviceContext.SaveChanges(); }
protected void ConvertToOrder_Click(object sender, EventArgs args) { var quoteToEditEntity = QuoteToEdit != null ? QuoteToEdit.Entity : null; if (quoteToEditEntity == null || (quoteToEditEntity.GetAttributeValue <EntityReference>("customerid") != null && !quoteToEditEntity.GetAttributeValue <EntityReference>("customerid").Equals(Contact.ToEntityReference()))) { throw new InvalidOperationException("Unable to retrieve quote."); } Entity order; try { order = QuoteToEdit.CreateOrder(); if (order == null) { ConvertToOrderError.Visible = true; return; } } catch (Exception e) { Tracing.FrameworkError(GetType().FullName, MethodBase.GetCurrentMethod().Name, "{0}", e); ConvertToOrderError.Visible = true; return; } var orderid = order.GetAttributeValue <Guid>("salesorderid"); if (!ServiceContext.IsAttached(Website)) { ServiceContext.Attach(Website); } var page = ServiceContext.GetPageBySiteMarkerName(Website, "View Order") ?? ServiceContext.GetPageBySiteMarkerName(Website, "Order Status"); if (page == null) { return; } var url = new UrlBuilder(ServiceContext.GetUrl(page)); url.QueryString.Set("OrderID", orderid.ToString()); Response.Redirect(url.PathWithQueryString); }