Ef global asax open db connection - asp.net-mvc

how can i open db connection in global asax file. For example i am trying to open in
using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using EDefterWAP.Helpers;
using EDocSis.DAL;
using System.Configuration;
namespace EDefterWAP
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_EndRequest()
{
IEDefterDB db = DBContext.CreateInstance(ConfigurationManager.ConnectionStrings["EDocSis.DAL.EDefterDB"].ConnectionString);
db.KurumVeriAktarimlari.
}
i can't write where condition after db.KurumVeriAktarimlari ? What is the problem?

It looks like you are missing a using statement.
using System.Linq;
This assembly contains the information for the Where(), First(), etc lambdas.

Related

Umbraco: Get ImageCropper & File Upload via SurfaceController

I'm still new to Umbraco 7 but I've found my way around Surface Controllers.
I have created a SurfaceController which you can see future below. But what I can't figure out is how to grab the URL from an Image Cropper and File Upload, I would normally do something like this: #node.GetCropUrl("uploadImage, "thumbnail");
But that doesn't work inside the controller. How do I achieve this? My end goal is to display the URL in a IMG tag when clicking on a category on this page: http://sp34k.dk/portfolio/vue/ in the description area.
CODE:
https://jsfiddle.net/odg3zamx/7/
GetCropUrl is an extension method of IPublishedContent so just add using Umbraco.Web; inside your sufrace controller and you should be able to call it. Like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Web.Mvc;
using Umbraco.Web; //you are missing this namespace
public class PortfolioSurfaceController : SurfaceController
{
// GET: PortfolioSurface
public ActionResult GetCategoryDetails(int id)
{
GalleryItem gItem = new GalleryItem();
var node = Umbraco.TypedContent(id);
gItem.imgUrl = node.GetCropUrl("uploadImage", "featured");
return Json(gItem, JsonRequestBehavior.AllowGet);
}
}

TFS Build 2013 - Variable scope and custom activities

I was trying to do something similar to the stackoverflow article referenced below and am finding I can't set values in the code activity. I seem to be able to read values OK. I suspect this has something to do with the scope of these. In the stackoverflow article the code implied that the variable was set for the loop,
I am after guidance on how to set these correctly or a way for my codeactivity to flag to exit the external DoWhile loop ?
Refs
StackOverflow Article
Code Activity article
OK here is the missing story and is not in the MS doco that I have found..
e.g. https://msdn.microsoft.com/en-us/library/dd647551(v=vs.120).aspx
Although MS document In, InOut, Out args their scope is not shared... i.e.
WRONG View of the world
XAML argument like MyBoolInOut Inout is the same argument that the C# code is using , e.g.
public InOutArgument MyBoolInOut { get; set; }
thus you only need to change values in C# code to change the values in the TFS XAML
Correct view of this handling
The custom code activity variables are visible in the XAML BUT are different from the XAML arguments. i.e.
as below, your C# codeactivity args have to be manually linked to the XAML args
So even though XAML has arguments and C# have arguments, these are separate.
This is an area MS could greatly improve their doco in.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;
using Microsoft.TeamFoundation.Build.Workflow.Activities;
namespace SampleActivityLibrary
{
[BuildActivity(HostEnvironmentOption.All)]
// Sample Acitivty that will Flip a bool from True to False or from False to True
public sealed class SampleFlipInOutBoolean : CodeActivity<Boolean>
{
public InOutArgument<Boolean> MyBoolInOut { get; set; }
protected override Boolean Execute(CodeActivityContext context)
{
Boolean MyBool = context.GetValue(MyBoolInOut);
context.TrackBuildWarning("SampleFlipInOutBoolean: In Value of Bool: " + MyBool.ToString(), BuildMessageImportance.High);
MyBoolInOut.Set(context, !MyBool);
MyBool = context.GetValue(MyBoolInOut);
context.TrackBuildWarning("SampleFlipInOutBoolean: Out Value of Bool: " + MyBool.ToString(), BuildMessageImportance.High);
return MyBool;
}
}
}

Strange Error :- System.Web.HttpCompileException was unhandled by user code

I habe a partial view named _GetRequestors, that have an IPagedList, it use to work well . but currently when i am trying to view this view i am getting the following error :-
System.Web.HttpCompileException was unhandled by user code
HResult=-2147467259 Message=c:\Users\Administrator\Documents\Visual
Studio 2012\Projects\TMS\TMS\Views\Customer_GetRequestors.cshtml(95):
error CS1061: 'PagedList.IPagedList' does not
contain a definition for 'ORG_ID' and no extension method 'ORG_ID'
accepting a first argument of type
'PagedList.IPagedList' could be found (are you
missing a using directive or an assembly reference?)
Source=System.Web ErrorCode=-2147467259 WebEventCode=0
SourceCode=#pragma checksum "C:\Users\Administrator\documents\visual
studio 2012\Projects\TMS\TMS\Views\customer_GetRequestors.cshtml"
"{ff1816ec-aa5e-4d10-87f7-6f4963833460}"
"9F77A32094FED764FF25BFFEBB39D9D953E8EBF5"
//------------------------------------------------------------------------------ // // This code was generated by a tool. //
Runtime Version:4.0.30319.19080 // // Changes to this file may
cause incorrect behavior and will be lost if // the code is
regenerated. //
//------------------------------------------------------------------------------
namespace ASP {
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Helpers;
using System.Web.Security;
using System.Web.UI;
using System.Web.WebPages;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Mvc.Html;
using System.Web.Optimization;
using System.Web.Routing;
using PagedList;
using PagedList.Mvc;
using TMS.Models;
public class _Page_Views_customer__GetRequestors_cshtml : System.Web.Mvc.WebViewPage<IPagedList<TMS.Models.AaaUser>> {
line hidden
public _Page_Views_customer__GetRequestors_cshtml() {
}
protected ASP.global_asax ApplicationInstance {
get {
return ((ASP.global_asax)(Context.ApplicationInstance));
}
}
As far I see, the view GetRequestors.cshtml attempted to call a method or variable named ORG_ID in generic list that implements IPagedList of TSM.Models.AaaUser but type object does not have a method called ORG_ID and if have, this is not visible or is protected
make sure that ORG_ID can be access

T4MVC is generating namespace for controllers incorrectly

I've just plugged T4MVC (3.5.1) into my ASP.NET MVC3 project.
It seems to be generating the wrong namespace in the *.generated.cs files. For example:
using System.Web;
using System.Web.Hosting;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Mvc.Html;
using System.Web.Routing;
using T4MVC;
namespace MyCompany.MyCompany.MyProject.Web.Controllers
{
public partial class HomeController
{
//snip
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public partial class T4MVC_HomeController : MyCompany.MyCompany.MyProject.Web.Controllers.HomeController
{
//snip
}
//snip
}
}
In this generated file, the first MyCompany shows MyCompany.MyCompany in intellisense, so the generated namespace is trying to look for my controller at MyCompany.MyCompany.MyCompany.MyProject.Web.Controllers.HomeController, and of course MyCompany.MyCompany does not contain MyCompany!
How can I get T4MVC to generate the namespace correctly for my solution?
David Ebbo pointed me in the right direction, someone else had the same issue here:
https://t4mvc.codeplex.com/discussions/404550
I used the global:: solution mentioned there, specifically, in T4MVC.tt, line 321, I changed:
public partial class <#=controller.DerivedClassName #> : <#=controller.FullClassName #>
to
public partial class <#=controller.DerivedClassName #> : global::<#=controller.FullClassName #>
Edit:
I also had to update line 1592 to account for parameters (my Models were having the same namespace issue). I did a quick and dirty change from this:
TT.Write(p.Type + " " + p.Name);
To this:
if (p.Type.StartsWith("FooBar"))
TT.Write("global::" + p.Type + " " + p.Name);
else
TT.Write(p.Type + " " + p.Name);

Make sure that the class defined in this code file matches the 'inherits' attribute

**File :Views/Shared/Default.aspx:**
<%# Page Language="C#" AutoEventWireup="True" CodeFile="Default.aspx.cs" Inherits="Views_Shared_Default" %>
File: Views/Shared/Default.aspx.cs:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Views_Shared_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Error:Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).
My Documents\Visual Studio 2008\Projects\3ICMS\Views\Shared\Default.aspx.cs 15 14 C:\...\3ICMS\
P.S I have 2 Default.aspx files in my Project 3ICMS.
1 File is at 3ICMS\Views\Shared\Default.aspx.cs
2nd File is at 3ICMS\Default.aspx
I have tried creating a new file and copy paste this code..Didn't work.
I have tried tried changing codefile to codebehind ... Didn't work
How to solve this problem?
The files are in different folders views and view , you should put the full directory path or put them in the same folder
<%# Page Language="C#" AutoEventWireup="True" CodeFile="../../Views/Shared/Default.aspx.cs" Inherits="Views_Shared_Default" %>

Resources