Latest Posts

Sunday, July 28, 2013

Forms Authentication

 void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        if (HttpContext.Current.User != null)
        {
            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                if (HttpContext.Current.User.Identity is FormsIdentity)
                {
                    FormsIdentity formsIdentity = (FormsIdentity)HttpContext.Current.User.Identity;
                    string[] userRoles = formsIdentity.Ticket.UserData.Split(',');
                    HttpContext.Current.User = new GenericPrincipal(formsIdentity, userRoles);
                }
            }
        }
    }

 protected void Login_Click(object sender, EventArgs e)
    {
        FormsAuthenticationTicket formsAuthenticationTicket = new FormsAuthenticationTicket(1, "abcd", DateTime.Now, DateTime.Now.AddMinutes(30), false, "Admin");
        string encryptedFAT = FormsAuthentication.Encrypt(formsAuthenticationTicket);
        HttpCookie httpcookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedFAT);
        HttpContext.Current.Response.Cookies.Add(httpcookie);
        string returnURL = Request.QueryString["returnURL"];
        if (returnURL == null)
        {
            Response.Redirect(returnURL);
        }
        else
            Response.Redirect("Default.aspx");
    }

<authentication mode="Forms">
   <forms defaultUrl="Default.aspx" loginUrl="Login.aspx">
   </forms>
  </authentication>
  <authorization>
   <allow roles="Admin"/>
   <deny users="*"/>
  </authorization>



Thursday, June 20, 2013

Jquery Image Gallery

<script type="text/javascript" src="script/jquery.1.9.min.js"></script>
<script type="text/javascript">
    var imageList;
    var start = 0;
    var autoImagesLoadID;
    $(document).ready(function () {
        $.ajax({
            type: "POST",
            url: "Default.aspx/galleryPhotos",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                imageList = data.d;
                loadImages(imageList);
                autoImagesLoad(imageList);
            }
        });
        function autoImagesLoad(imgList) {
            autoImagesLoadID = setInterval(function () {
                if (start + 1 > imgList.length) {
                    start = 0;
                }
                else {
                    start = start + 1;
                }
                $("#content > div.box > div.image > img").attr("src", "upload/" + imgList[start].photoPath);
                if (start % 5 == 0) {
                    var $divthumbs = $("#content > div.box > div.thumbs").empty().append("");
                    for (var i = start; i < start + 5; i++) {
                        if (imgList[i] && imgList[i].photoPath.length > 1) {
                            var $div = $("<div/>").attr("class", "thumb").attr("title", imgList[i].rowID);
                            var $divT = $("<div/>").attr("class", "imgthumb");
                            var $a = $("<a/>").attr("href", "javascript:;");
                            var $img = $("<img/>").attr("src", "upload/" + imgList[i].photoPath).appendTo($a);
                            $divT.append($a).appendTo($div);
                            $divthumbs.append($div);
                        }
                    }
                }
                $("#content > div.box > div.thumbs > div.thumb").css("background-color", "");
                $("#content > div.box > div.thumbs > div.thumb[title~=" + (start + 1) + "]").css("background-color", "Blue");
            }, 3000);
        }
        function loadImages(imgList) {
            $("#content > div.box > div.image > img").attr("src", "upload/" + imgList[start].photoPath);
            var $divthumbsTemp = $("<div/>");
            for (var i = start; i < start + 5; i++) {
                if (imgList[i] && imgList[i].photoPath.length > 1) {
                    var $div = $("<div/>").attr("class", "thumb").attr("title", imgList[i].rowID);
                    if (i == 0) {
                        $div.css("background-color", "Blue");
                    }
                    var $divT = $("<div/>").attr("class", "imgthumb");
                    var $a = $("<a/>").attr("href", "javascript:;");
                    var $img = $("<img/>").attr("src", "upload/" + imgList[i].photoPath).appendTo($a);
                    $divT.append($a).appendTo($div);
                    $divthumbsTemp.append($div);
                }
            }
            $("#content > div.box > div.thumbs").empty().html($divthumbsTemp.html());
        }
        $("#content > div.box > div.arrowleft").click(function () {
            if (start - 5 < 0)
                start = 0;
            else
                start = start - 5;
            $("#content > div.box > div.thumbs").animate({ "margin-right": "85%", height: "73px", width: "1px" }, "slow", function () {
                loadImages(imageList);
            });
            $("#content > div.box > div.thumbs").animate({ "margin-right": "0%", height: "73px", width: "545px" }, "slow");

        });
        $("#content > div.box > div.arrowright").click(function () {
            if (start + 5 < imageList.length)
                start = start + 5;
            $("#content > div.box > div.thumbs").animate({ "margin-left": "85%", height: "73px", width: "1px" }, "slow", function () {
                loadImages(imageList);
            });
            $("#content > div.box > div.thumbs").animate({ "margin-left": "0%", height: "73px", width: "545px" }, "slow");
        });
        $("#content > div.box > div.thumbs").on("mouseenter", "div.thumb", function () {
            start = ($(this).attr("title")) - 1;
            $("#content > div.box > div.image > img").attr("src", "upload/" + imageList[start].photoPath);
            $("#content > div.box > div.thumbs > div.thumb").css("background-color", "");
        });
        $("#content > div.box").mouseover(function () {
            clearInterval(autoImagesLoadID);
        });
        $("#content > div.box").mouseout(function () {
            autoImagesLoad(imageList);
        });
    });
</script>


 <!--begin pbox-->
    <div class="box">
        <h3>Image Description</h3>
        <!-- begin post -->
    <div class="image"> <img src="" height="400px" width="640px" alt="" /></div>
    <!-- end post -->
     <div class="arrowleft"><a href="javascript:void(0)"><img src="images/left.png"  alt="" /></a></div>
    <div class="thumbs">
    </div>
     <div class="arrowright"><a href="javascript:void(0)"><img src="images/right.png"  alt="" /></a></div>
    <div class="break"></div>
      </div>
  <!--end p bbox-->

Saturday, February 9, 2013

Create User In MVC Membership

 if (ModelState.IsValid)
                {
                    MembershipCreateStatus membershipCreateStatus;
                    Membership.CreateUser(userRegistration.userName, userRegistration.password, userRegistration.emailID, userRegistration.securityQuestion, userRegistration.securityAnswer, true, out membershipCreateStatus);

                    if (membershipCreateStatus == MembershipCreateStatus.Success)
                    {
                        Roles.AddUserToRole(userRegistration.userName, "UserRole");
                        return RedirectToAction("Index", "Account");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Registration Unsuccessful, Please Try again");
                        return View(userRegistration);
                    }
                }
                else
                {
                    return View(userRegistration);
                }

List Users In MVC Membership

CommonList commonList = new CommonList();
            commonList.userName = "";
            commonList.userList = Membership.GetAllUsers().Cast().Select(m => new UserList { userName = m.UserName, emailID = m.Email }).ToList();
           

Monday, January 28, 2013

Fill Dropdownlist in mvc

  @Html.DropDownListFor(m => m.categoryList, new SelectList(Model.categoryList, "Value", "Text"))

  public IEnumerable  categoryList { get; set; }
        KochiDealsEntities1 db = new KochiDealsEntities1();
        public IEnumerable fetchCategoryList()
        {
            var cat = (from m in db.ItemCategories
                       select new { m.CategoryID,m.CategoryName }).AsEnumerable().Select(x => new SelectListItem { Value = x.CategoryID.ToString(), Text = x.CategoryName, Selected = true  });
            return cat;
        }

Thursday, January 17, 2013

Login with FaceBook

   <script 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: '198191300293654', // App ID
               channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File
               status: true, // check login status
               cookie: true, // enable cookies to allow the server to access the session
               xfbml: true  // parse XFBML
           });

           // 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
                   FB.api('/me', function (me) {
                       if (me.name) {
                           document.getElementById('auth-displayname').innerHTML = me.name;
                       }
                   })
                   document.getElementById('auth-loggedout').style.display = 'none';
                   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>
<h1>
Facebook Login Authentication Example</h1>
<div id="auth-status">
<div id="auth-loggedout">

<div class="fb-login-button" autologoutlink="true" scope="email,user_checkins">Login with Facebook</div>
</div>
<div id="auth-loggedin" style="display: none">
Hi, <span id="auth-displayname"></span>(<a href="#" id="auth-logoutlink">logout</a>)
</div>
</div>

Tuesday, January 15, 2013

jquery tab

$("#existingCustomersTab").find("#customerDetailsDiv").tabs({
            select: function (event, ui) {
                switch (ui.index) {
                    case 0:
                        //Create Ticket Tab
                        break;
                    case 1:
                        //Ticket History Tab Starts
                        var customerIDVal = $("#existingCustomersTab").find("#customerIDText").val();
                        if (customerIDVal != "") {
                            $.ajax({
                                url: "CallRegister2.aspx/fetchTicketHistory",
                                data: "{customerID:'" + customerIDVal + "'}",
                                dataType: "json",
                                type: "POST",
                                contentType: "application/json; charset=utf-8",
                                dataFilter: function (data) { return data; },
                                success: function (data) {
                                    var $table = $('<table/>').css("border", "1px solid #111111"); ;
                                    var $tr = $('<tr/>').css("border", "1px solid #111111"); ;
                                    $tr.append("<th>").append("Complaint No").append("</th>").append("<th>").append("Subject").append("</th>").append("<th>").append("Status").append("</th>").append("<th>").append("Date").append("</th>");
                                    $table.append($tr);
                                    $.each(data.d, function (i, item) {
                                        var $tr = $('<tr/>').css("border", "1px solid #111111"); ;
                                        var $a = $('<a/>').attr('href', 'javascript:void(0)').text(item.complaintNo).css('color', 'blue');
                                        $tr.append("<td>").append($a).append("</td>").append("<td>").append(item.subject).append("</td>").append("<td>").append(item.status).append("</td>").append("<td>").append(item.date).append("</td>");
                                        $table.append($tr);
                                    });
                                    $("#existingCustomersTab").find("#ticketHistorySubTab").find("#ticketHistoryDiv").html($table);
                                }
                            });
                        }
                        //Ticket History Tab Ends
                        break;
                    case 2:
                        var customerIDVal = $("#existingCustomersTab").find("#customerIDText").val();
                        if (customerIDVal != "") {
                            $.ajax({
                                url: "CallRegister2.aspx/fetchCustomerProfile",
                                data: "{customerID:'" + customerIDVal + "'}",
                                dataType: "json",
                                type: "POST",
                                contentType: "application/json; charset=utf-8",
                                dataFilter: function (data) { return data },
                                success: function (data) {
                                    $table = $("#existingCustomersTab").find("#profileSubTab").find("table").empty();
                                    $table.last().append("<tr><th colspan='2'>Customer Profile</th></tr>");
                                    $table.last().append("<tr><td>Service Provider</td><td>" + data.d[0].serviceProvider + "</td></tr>");
                                    $table.last().append("<tr><td>Service ID</td><td>" + data.d[0].serviceID + "</td></tr>");
                                    $table.last().append("<tr><td>First Name</td><td>" + data.d[0].firstName + "</td></tr>");
                                    $table.last().append("<tr><td>Last Name</td><td>" + data.d[0].lastName + "</td></tr>");
                                    $table.last().append("<tr><td>Email</td><td>" + data.d[0].email + "</td></tr>");
                                    $table.last().append("<tr><td>Telephone</td><td>" + data.d[0].telephone + "</td></tr>");
                                    $table.last().append("<tr><td>Street</td><td>" + data.d[0].street + "</td></tr>");
                                    $table.last().append("<tr><td>City</td><td>" + data.d[0].city + "</td></tr>");
                                    $table.last().append("<tr><td>State</td><td>" + data.d[0].state + "</td></tr>");
                                    $table.last().append("<tr><td>Country</td><td>" + data.d[0].country + "</td></tr>");
                                    $table.last().append("<tr><td>Zip</td><td>" + data.d[0].zip + "</td></tr>");
                                    $table.last().append("<tr><td>Billing Address</td><td>" + data.d[0].billingAddress + "</td></tr>");
                                    $table.last().append("<tr><td>Billing City</td><td>" + data.d[0].billingCity + "</td></tr>");
                                    $table.last().append("<tr><td>Billing Zip</td><td>" + data.d[0].billingZip + "</td></tr>");
                                    $table.last().append("<tr><td>Registered Date</td><td>" + data.d[0].regDate + "</td></tr>");
                                }
                            });
                        }
                        //Customer Profile Block
                        break;
                    default:
                        //code to be executed if n is different from case 1 and 2
                }
            }
        });