Skip to main content

Posts

Showing posts from August, 2014

foreach in mvc 5 counter values

 The below code sample for  foreach in MVC 5 razor  view. < div class ="list-group">                             @ foreach ( var pro in ViewBag.BucketTypes)       {           < a href ="/Connect/ServiceDetails/ @ pro.ID " class ="list-group-item">                  < span class ="badge"> @ pro.SERVICECOUNT  View detail </ span >                  < i class ="fa fa-bitbucket"></ i > @ pro.VALUE           </ a >       }   </ div >

MVC 5 Web API Base Controller

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Http; using System.Web.Mvc.Filters; namespace myPortal.API {     /// <summary>     /// Base api controller will extend to all apis. And can handle authentication and authorization here.     /// </summary>     public class BaseAPIController : ApiController     {         /// <summary>         /// BaseAPIController constructor will check that identity exists or not.         /// </summary>         public BaseAPIController ()         {             if (! HttpContext .Current.User.Identity.IsAuthenticated) ...

Base controller in MVC 5

 public class BaseController : Controller  {         public UserSession _userSession { set ; get ; }         AuthenticationManager _authenticationManager = new AuthenticationManager ();                 public BaseController()         {             if (System.Web. HttpContext .Current.User.Identity.IsAuthenticated)             {                 ( new UserManager ()).CreateUserSession();             }             else           ...

read cookies with key value pair in JavaScript jquery

This is basically used to  read the cookies data by using the key and value pair in MVC 5 jQuery. The code sample as give below. var cookies = cookies || {}; cookies.read = new function   (){ function setCokiesValue(key, value) {     session[key] = value; }; var  session = []; var getCookie = function readCookie () {        match = document.cookie.match( new RegExp( 'MyCookieName' + '=([^;]+)' ));         if (match) {             var array = match[1].split( '&' );             for ( var i = 0; i < array.length; i++) {                 name = array[i].split( '=' )[0];                 value = array[i].split( '=' )[1];                 session.push(setCokiesValue(name, value));    ...

How to create cookies in MVC 5 with C# .net?

We are using Request.Cookies for get the values of cookies and the Respone.Cookies are use to add the cookies. In the below example, used to Respone.Cookies for create/ add new cookies. i.e. 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 //This method id used to Create the cookies and assign the values in cookies . private static void SetCookies(UserSession userSession) {      HttpCookie cookie = HttpContext.Current.Request.Cookies[ "GlobalCookieName" ] ??      new HttpCookie( "GlobalCookieName " );      cookie.Values[ "CompanyID" ] = Convert.ToString(userSession.CompanyID);      cookie.Values[ "TenantId" ] = userSession.CompanyName;      cookie.Values[ "EmailID" ] = userSession.EmailID;      cookie.Values[ "UserType" ] = Convert.ToString(userSession.UserType);      cookie.Exp...

Set Globalization Culture for MVC 5

The below code sample is used to set the globalization culture in MVC 5. < system.web >      <!-- Set globalization culture (en-GB) for English and Great Britain -->     < globalization   culture = " en-GB " /> </ system.web >

count number of column in datatable c#

DataTable Sheets = connectionString.GetOleDbSchemaTable( OleDbSchemaGuid .Tables, null ); foreach ( DataRow dr in Sheets.Rows) {     string sheetStr = dr[2].ToString().Replace( "'" , "" );     OleDbDataAdapter dataAdapter = new OleDbDataAdapter ( "select * from [" + sheetStr + "]" , connectionString);     var ds = new DataSet ();     dataAdapter.Fill(ds, "DataTable" );     DataTable data = ds.Tables[ "DataTable" ];     if (ds.Tables[ "DataTable" ]. Rows.Count > 0)     {         GetSetUploadExcelData(uploadExl, data, CompanyID, TenantID);     } }

Reset password with UserManager of ASP.NET MVC 5

The given below code sample used for reset password using user manager using MVC 5 c# public class ResetPwdController : Controller {     UserManager < IdentityUser > userManager =  new UserManager < IdentityUser >( new UserStore < IdentityUser >());                [ HttpPost ]    [ AllowAnonymous ]     public ActionResult ResetPassword ( ResetPwdViewModel model, string email, string code)    {         if (ModelState.IsValid)        {                         AspNetUser user = ( new AspDotNetUserRepository ()).GetAspNetUser(email);           if (user != null )          {         ...