Wednesday, 23 April 2014

Pagging in MVC




Pagging in MVC

View Side:
At top of the view:

@model PagedList.IPagedList<Properties>

@Html.Partial("_Pager")


_Pager.cshtml:

<div class="pagging">
    <div class="left">
        Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
        of @Model.PageCount
    </div>
    <div class="right">
        @{var action = ViewContext.RouteData.GetRequiredString("action");}
        @if (Model.HasPreviousPage)
        {
            @Html.ActionLink("First", action, new { page = 1,CategoryId =  ViewBag.CategoryId , sortBy = ViewBag.sb, IsLoggedIn = ViewBag.ls, sortOrder = ViewBag.so, Name = ViewBag.Name, Email = ViewBag.mail, Gender = ViewBag.gen, AgeFrom = ViewBag.af, AgeTo = ViewBag.at, CountryLocated = ViewBag.col, CityLocated = ViewBag.cil, IsActive = ViewBag.act, UserImage = ViewBag.pho, CountryCode = ViewBag.cc });
            @Html.Raw(" ");
            @Html.ActionLink("Prev", action, new { page = Model.PageNumber - 1,CategoryId =  ViewBag.CategoryId , sortBy = ViewBag.sb, IsLoggedIn = ViewBag.ls, sortOrder = ViewBag.so, Name = ViewBag.Name, Email = ViewBag.mail, Gender = ViewBag.gen, AgeFrom = ViewBag.af, AgeTo = ViewBag.at, CountryLocated = ViewBag.col, CityLocated = ViewBag.cil, IsActive = ViewBag.act, UserImage = ViewBag.pho, CountryCode = ViewBag.cc });
        }
        else
        {
            <span>First</span>
            @Html.Raw(" ");
            <span>Prev</span>
        }
        @if (Model.HasNextPage)
        {
            @Html.ActionLink("Next", action, new { page = Model.PageNumber + 1,CategoryId =  ViewBag.CategoryId , sortBy = ViewBag.sb, IsLoggedIn = ViewBag.ls, sortOrder = ViewBag.so, Name = ViewBag.Name, Email = ViewBag.mail, Gender = ViewBag.gen, AgeFrom = ViewBag.af, AgeTo = ViewBag.at, CountryLocated = ViewBag.col, CityLocated = ViewBag.cil, IsActive = ViewBag.act, UserImage = ViewBag.pho, CountryCode = ViewBag.cc });
            @Html.Raw(" ");
            @Html.ActionLink("Last", action, new { page = Model.PageCount,CategoryId =  ViewBag.CategoryId , sortBy = ViewBag.sb, IsLoggedIn = ViewBag.ls, sortOrder = ViewBag.so, Name = ViewBag.Name, Email = ViewBag.mail, Gender = ViewBag.gen, AgeFrom = ViewBag.af, AgeTo = ViewBag.at, CountryLocated = ViewBag.col, CityLocated = ViewBag.cil, IsActive = ViewBag.act, UserImage = ViewBag.pho, CountryCode = ViewBag.cc });
        }
        else
        {
            <span>Next</span>
            @Html.Raw(" ");
            <span>Last</span>
        }
    </div>
</div>

Controller Side:

var users = new PostRepository().GetUserPictures(objPro_PictureMaster);
            const int pageSize = 10;
            var pageNumber = (objPro_PictureMaster.page ?? 1);
            ViewBag.TotalUsers = users.Count();
            var enumerable = users as IList<Pro_PostMaster> ?? users.ToList();
            ViewBag.FilteredCount = enumerable.Count();
            ViewBag.CategoryDropDownList = categoryBind(CategoryId);
            return View(enumerable.ToPagedList(pageNumber, pageSize));

DropdownList bind and get detail





DropdownList bind and get detail


Calling Statement:

 ViewBag.CategoryDropDownList= categoryBind(0);



Method:

public List<SelectListItem> categoryBind(int CategoryId)
        {
            List<SelectListItem> CategoryDropDownList = new List<SelectListItem>();
            List<Category> CategoryList = new PostRepository().GetAllCategory();
            foreach (var item in CategoryList)
            {
                if (item.CatId == CategoryId)
                {
                    CategoryDropDownList.Add(new SelectListItem { Text = item.CatName, Value = Convert.ToString(item.CatId), Selected=true});
                }
                else
                {
                    CategoryDropDownList.Add(new SelectListItem { Text = item.CatName, Value = Convert.ToString(item.CatId)});
                }
            }
            return CategoryDropDownList;
        }

View Side:
<script>
        var jqListUser = jQuery.noConflict();
        jqListUser(document).ready(function () {
            jqListUser('#CategoryDropDownList').change(function () {               
                list = jqListUser1(this);
                var listvalue = list.val();
                document.getElementById("dropdownselectedid").click();
            });
        });
</script>
@using (Html.BeginForm("ListUserPictures", "Picture", FormMethod.Post, new { id = "formUserpicture" }))
 {
@Html.DropDownList("CategoryDropDownList")
   <input type="submit" id="dropdownselectedid" name="dropdownselectedid"   style="display:none" />
}
Fetching Data(Post Method):
CategoryId = Convert.ToInt32(Request.Form["CategoryDropDownList"]);

Redirect Page with Querystring in MVC



return RedirectToAction("MethodName", new { categoryId = TempData["CategoryId"] });


Here,

Method Name is a function which is created in controller.

CategoryId must be a part of that parameter.

TempData["CategoryId"] because it is going to redirect the page. so Viewbag is not reliable to use.




Monday, 21 April 2014

Proportional Image Resize in C# .net


Proportional Image Resize in C# .net :

public static Bitmap CreateThumbnail(string lcFilename, int lnWidth, int lnHeight)
        {
            Bitmap bmpOut = null;

            try
            {
                var loBmp = new Bitmap(lcFilename);              
                var lnNewWidth = 0;
                var lnNewHeight = 0;

                if (loBmp.Height == loBmp.Width)
                {
                    lnNewWidth = lnNewHeight = lnHeight;
                }
                else if (loBmp.Height > loBmp.Width)
                {
                    lnNewHeight = lnHeight;
                    lnNewWidth = (loBmp.Width * lnWidth) / loBmp.Height;
                }
                else
                {
                    lnNewHeight = lnWidth;
                    lnNewWidth = (loBmp.Width * lnHeight) / loBmp.Height;

                    lnNewWidth = lnWidth;
                    lnNewHeight = (loBmp.Height * lnHeight) / loBmp.Width;
                }              

                bmpOut = new Bitmap(lnNewWidth, lnNewHeight);

                var g = Graphics.FromImage(bmpOut);
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                g.FillRectangle(Brushes.Transparent, 0, 0, lnNewWidth, lnNewHeight);
                g.DrawImage(loBmp, 0, 0, lnNewWidth, lnNewHeight);
                loBmp.Dispose();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return bmpOut;
        }

Thursday, 9 January 2014

Facebook Sign In Button


<script language="javascript" type="text/javascript">
    // Load the SDK Asynchronously
    (function (d) {
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) { return; }
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);
    } (document));

    // Init the SDK upon load
    window.fbAsyncInit = function () {
        FB.init({
            appId: '680827721940158', // Write your own application id
            channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File
            scope: 'id,name,gender,user_birthday,email,user_location,user_hometown',
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true  // parse XFBML
            //,perms: 'user_address, user_mobile_phone'
        });
       

        // listen for and handle auth.statusChange events
        FB.Event.subscribe('auth.statusChange', function (response) {
            if (response.authResponse) {
                // user has auth'd your app and is logged into Facebook
                var uid = "http://graph.facebook.com/" + response.authResponse.userID + "/picture";
                FB.api('/me', function (me) {
                    if (me.name) {
                        //me.name
                        document.getElementById('<%= txtNewFirstName.ClientID%>').value = me.first_name;
                        document.getElementById('<%= txtNewLastName.ClientID%>').value = me.last_name;
                        document.getElementById('<%= txtNewEmail.ClientID%>').value = me.email;

                        var location = me.location.name.split(',');

                        //For Country DropDown
                        var isCountry = false;
                        $("#<%=ddlNewCountry.ClientID%> option[selected]").removeAttr("selected");
                        var textToFind = location[1].trim();

                       me.languages[0].name.trim();
                       // $("#<%=ddlNewCountry.ClientID%>").val(location[1].trim());
                        //me.birthday;
                        // uid;
                        //me.gender;
                    }
                })
                document.getElementById('auth-loggedout').style.display = 'block';
                document.getElementById('auth-loggedin').style.display = 'block';
            } else {
                // user has not auth'd your app, or is not logged into Facebook
                document.getElementById('auth-loggedout').style.display = 'block';
                document.getElementById('auth-loggedin').style.display = 'none';
            }
        });
        $("#auth-logoutlink").click(function () { FB.logout(function () { window.location.reload(); }); });
    }
</script>

Create account in
http://developers.facebook.com/
create new application and please the url in web login(where to use)
Make sure that sandbox is disable.

Google Plus Sign In Button



<html>
<head>
  <title>Demo: Getting an email address using the Google+ Sign-in button</title>
  <style type="text/css">
  html, body { margin: 0; padding: 0; }
  .hide { display: none;}
  .show { display: block;}
  </style>
  <script type="text/javascript">
      /**
      * Global variables to hold the profile and email data.
      */
      var profile, email;

      /*
      * Triggered when the user accepts the sign in, cancels, or closes the
      * authorization dialog.
      */
      function loginFinishedCallback(authResult) {
          if (authResult) {
              if (authResult['error'] == undefined) {
                  toggleElement('signin-button'); // Hide the sign-in button after successfully signing in the user.
                  gapi.client.load('plus', 'v1', loadProfile);  // Trigger request to get the email address.
              } else {
                  console.log('An error occurred');
              }
          } else {
              console.log('Empty authResult');  // Something went wrong
          }
      }

      /**
      * Uses the JavaScript API to request the user's profile, which includes
      * their basic information. When the plus.profile.emails.read scope is
      * requested, the response will also include the user's primary email address
      * and any other email addresses that the user made public.
      */
      function loadProfile() {
          var request = gapi.client.plus.people.get({ 'userId': 'me' });
          request.execute(loadProfileCallback);
      }

      /**
      * Callback for the asynchronous request to the people.get method. The profile
      * and email are set to global variables. Triggers the user's basic profile
      * to display when called.
      */
      function loadProfileCallback(obj) {
          profile = obj;
          console.log(obj);

          // Filter the emails object to find the user's primary account, which might
          // not always be the first in the array. The filter() method supports IE9+.
          email = obj['emails'].filter(function (v) {
              return v.type === 'account'; // Filter out the primary email
          })[0].value; // get the email from the filtered results, should always be defined.
          displayProfile(profile);
      }

      /**
      * Display the user's basic profile information from the profile object.
      */
      function displayProfile(profile) {
          document.getElementById('name').innerHTML = profile['displayName'];
          document.getElementById('name').innerHTML = profile['name']['givenName'] + " - " + profile['name']['familyName'];
          document.getElementById('pic').innerHTML = '<img src="' + profile['image']['url'] + '" />';
          document.getElementById('email').innerHTML = email;

          if (profile['language'] == 'en')
              document.getElementById('launguage').innerHTML = "English";
          else
              document.getElementById('launguage').innerHTML = "French";

          if (profile['placesLived'][0].value != "undefine");
          document.getElementById('PlacesLived').innerHTML = profile['placesLived'][0].value;
         
          toggleElement('profile');
      }

      /**
      * Utility function to show or hide elements by their IDs.
      */
      function toggleElement(id) {
          var el = document.getElementById(id);
          if (el.getAttribute('class') == 'hide') {
              el.setAttribute('class', 'show');
          } else {
              el.setAttribute('class', 'hide');
          }
      }
  </script>
  <script src="https://apis.google.com/js/client:plusone.js" type="text/javascript"></script>
</head>
<body>
  <div id="signin-button" class="show">
     <div class="g-signin"
      data-callback="loginFinishedCallback"
      data-approvalprompt="force"
      data-clientid="656942774761-v378l3ad6pm3q6k3s0hrfbd4dl4tq4te.apps.googleusercontent.com"
      data-scope="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read"
      data-height="short"
      data-cookiepolicy="single_host_origin"
      >
    </div>
    <!-- In most cases, you don't want to use approvalprompt=force. Specified
    here to facilitate the demo.-->
  </div>

  <div id="profile" class="hide">
    <div>
      <span id="pic"></span>
      <span id="name"></span>
    </div>

    <div id="email"></div>
    <div id="launguage"></div>
    <div id="PlacesLived"></div>
  </div>
</body>
</html>


Create Project with this Link

https://cloud.google.com/console/project

Then Follow the step

APIs & auth Tab -->  CredentialsClient ID for web applicationEdit Settings of (Redirect URIs & Javascript Origins)  Here write url of your site where to use.   

Saturday, 21 December 2013

Loading Before Page Load using css.

<html>
<script language="javascript" type="text/javascript">
    $(window).load(function () {
        $(".loader").fadeOut("slow");
    });  
</script>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<style>
.loader2{  
z-index: 10010;     position: fixed;     padding: 0px;     margin: 0px;     width: 30%;     top: 40%;     left: 35%;     text-align: center;     color: rgb(0, 0, 0);     border: 0px solid rgb(170, 170, 170);     cursor: wait;
}
.loader-bg-color
{
z-index: 9999; border: medium none; margin: 0px; padding: 0px; width: 100%; height: 100%; top: 0px; left: 0px; background-color: rgb(0, 0, 0); opacity: 0.6; cursor: wait; position: fixed;}
#bowl_ringG{position:absolute;width:50px;height:50px;border:4px solid #908B91;-moz-border-radius:50px;-webkit-border-radius:50px;-ms-border-radius:50px;-o-border-radius:50px;border-radius:50px;left:50%;
}
.ball_holderG
{
position:absolute;width:13px;height:50px;left:18px;top:0px;-moz-animation-name:ball_moveG;-moz-animation-duration:0.8s;-moz-animation-iteration-count:infinite;-moz-animation-timing-function:linear;-webkit-animation-name:ball_moveG;-webkit-animation-duration:0.8s;-webkit-animation-iteration-count:infinite;-webkit-animation-timing-function:linear;-ms-animation-name:ball_moveG;-ms-animation-duration:0.8s;-ms-animation-iteration-count:infinite;-ms-animation-timing-function:linear;-o-animation-name:ball_moveG;-o-animation-duration:0.8s;-o-animation-iteration-count:infinite;-o-animation-timing-function:linear;animation-name:ball_moveG;animation-duration:0.8s;animation-iteration-count:infinite;animation-timing-function:linear;
}
.ballG
{
position:absolute;left:0px;top:-12px;width:20px;height:20px;background:#FF9933;-moz-border-radius:17px;-webkit-border-radius:17px;-ms-border-radius:17px;-o-border-radius:17px;border-radius:17px;
}

@-moz-keyframes ball_moveG{
    0%{-moz-transform:rotate(0deg)}
    1000%{-mo0z-transform:rotate(360deg)}
}

@-webkit-keyframes ball_moveG{
    0%{-webkit-transform:rotate(0deg)}
    100%{-webkit-transform:rotate(360deg)}
}

@-ms-keyframes ball_moveG{
    0%{-ms-transform:rotate(0deg)}
    100%{-ms-transform:rotate(360deg)}
}

@-o-keyframes ball_moveG{
    0%{-o-transform:rotate(0deg)}
    100%{-o-transform:rotate(360deg)}
}

@keyframes ball_moveG{
    0%{transform:rotate(0deg)}
    100%{transform:rotate(360deg)}
}



</style>
<body>
    <div class="loader">
        <div class="loader-bg-color">
        </div>
        <div class="loader2">
            <div id="bowl_ringG">
                <div class="ball_holderG">
                    <div class="ballG">
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>