Friday, 3 June 2016

Validate controller with session and redirect again to left page mvc

No comments
HTML

<body>

    <section class="content" style="width: 50%;margin-left: 25%;margin-top: 50px;">
        <div class="row">          
            @if (TempData["Signup"] == "success")
            {
                <div class="alert alert-success  alert-dismissible" style="margin-top: 5px">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>                            
                    Signup success , please login to continue..
                </div>
            }
            else
            {
                <div class="alert alert-success  alert-dismissible" style="margin-top: 5px;visibility:hidden">                  
                    &nbsp;
                </div>
            }
        </div>
    </section>

    <div class="login-card">
        <h1>Log-in</h1><br>
        <form action="@Url.Action("Login","Home")@(Request.QueryString["ReturnUrl"] != null ? "?"+Request.QueryString : "")" method="post">
            @Html.TextBoxFor(x => x.emailid, new { placeholder = "Email", maxlength = "50", tabindex = "1", @class = "form-control" })
            @Html.TextBoxFor(x => x.password, new { placeholder = "Password", type="password",maxlength = "50", tabindex = "2", @class = "form-control" })          
            <button name="login" class="login login-submit">Login</button>
        </form>
        <div class="login-help">
            <a href="@Url.Action("UserRegistration","Home")">Register</a> • <a href="#">Forgot Password</a>
        </div>
        @if (ViewContext.ViewData.ModelState.ContainsKey("Error") || ViewContext.ViewData.ModelState.ContainsKey("Login"))
        {
            <div class="alert alert-danger alert-dismissible" style="margin-top: 5px">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                @Html.ValidationSummary(false)
            </div>
        }
     
    </div>

</body>



Controller

SessionFactory.cs 

to store session

   public class SessionFactory
    {
        private static SessionFactory _SessionFactory = new SessionFactory();

        public SessionFactory()
        {

        }

        public static SessionFactory Instance
        {
            get
            {
                return _SessionFactory;
            }
        }

        public Users CurrentUsers
        {
            get
            {
                if (HttpContext.Current.Session["Users"] == null)
                {
                    return null;
                }
                return (Users)HttpContext.Current.Session["Users"];
            }

            set
            {
                HttpContext.Current.Session["Users"] = value;
            }
        }
    }


ValidateUserAttribute.cs

attribute to validate

 public class ValidateUserAttribute: ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {          
            if (SessionFactory.Instance.CurrentUsers == null)
                filterContext.Result = new RedirectResult(string.Format("/Home/Login?ReturnUrl={0}",HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.AbsolutePath)));          
        }
    }


Property

to check querystring

 private string ReturnUrl
        {
            get
            {
                if (Request.QueryString["ReturnUrl"] != null)
                {
                    return Request.QueryString["ReturnUrl"];
                }
                return string.Empty;
            }
        }

When Login

if querystring found than redirect to that url

      [HttpPost]
        public ActionResult Login(Users users)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("Error", "");
                return View(users);
            }
         
            SessionFactory.Instance.CurrentUsers = userData;
            if (!string.IsNullOrEmpty(ReturnUrl))
            {
                return RedirectPermanent(ReturnUrl);
            }
            else
                return RedirectToAction("Dashboard", "Dashboard");
        }


Validate controller


  [ValidateUser]
    public class MyController : Controller
    {
    }
read more

Thursday, 2 June 2016

Create keystore and SHA-1 signing-certificate for android app in cordova

No comments
open https://console.developers.google.com

go to credential ---> create credential -->OauthCLientId --> android

enter package name from androidmenifest.xml

for getting SHA-1 signing-certificate

open cmd and type

keytool -genkey -v -keystore C:/CaribeanTaxi/CaribeanTaxi.keystore -alias [CaribeanTaxi] -keyalg RSA -keysize 2048 -validity 10000

here C:/CaribeanTaxi/CaribeanTaxi.keystore is keystore path which ever you pass
RSA is algorithm

now enter password and all fields which it asks for

now open build.json in your cordova project  and add

{
     "android": {
         "release": {
             "keystore": "C:/CaribeanTaxi/CaribeanTaxi.keystore",
             "storePassword": "caribean",
             "alias": "CaribeanTaxi",
             "password" : "caribean",
             "keystoreType": ""
         }
     }
 }

here password is same which asked while creating keystore

no type in cmd

keytool -exportcert -keystore C:\CaribeanTaxi\CaribeanTaxi.keystore -list -v

this will ask you to enter same password 



To Create Release

add new buid.json  in root folder outside of www

build.json


{
     "android": {
         "release": {
              "keystore""C:\\app\\app.keystore",
             "storePassword""app",
             "alias""app",
             "password" : "app",
             "keystoreType"""
         }
     }
 }
 
 
read more

Tuesday, 31 May 2016

Integrate share with facebook,linkedin,twitter,google plus

No comments
HTML

<body>

    <nav>      
        <ul class="clearfix">

            <li>
                <ul>

             
                    <li><a href="javascript:void(0)" id="shareFB"><span class="fontawesome-facebook"></span></a></li>

                    <li><a id="shareTwit" href="http://twitter.com/share"><span class="fontawesome-twitter"></span></a></li>

                    <li><a id="googleLink"><span class="fontawesome-google-plus"></span></a></li>


                    <li>
                        <a id="shareLink" href="#">
                            <span class="fontawesome-linkedin"></span>
                        </a>
                    </li>

                    <li>
                        <a id="mailLink" href="#">
                            <span class="fontawesome-envelope"></span>
                        </a>
                    </li>
                </ul>

            </li>

        </ul>
    </nav>

</body>


JAVASCRIPT

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.js">
</script>
<script src="https://connect.facebook.net/en_US/all.js">
</script>
<script type="text/javascript">
    var url = document.URL;
    var message = 'Healthcare for free';
    $(document).ready(function () {

        FB.init({
            appId: '247708942243803'
        });
        $('#shareFB').click(function (e) {
            e.preventDefault();
            FB.ui(
            {
                method: 'share',
                name: message,
                href: url,
                caption: message,
                description: message,
                message: '',

            });
        });
    });
</script>

<script>
    <!--Twitter-->
    $('#shareTwit').click(function (event) {
        var width = 575,
            height = 400,
            left = ($(window).width() - width) / 2,
            top = ($(window).height() - height) / 2,
            url = this.href,
            opts = 'status=1' +
                     ',width=' + width +
                     ',height=' + height +
                     ',top=' + top +
                     ',left=' + left;

        window.open(url, 'twitter', opts);

        return false;
    });



    //Google Plus

    $('#googleLink').click(function () {
        $('#googleLink').attr('href', 'https://plus.google.com/share?url=' + url + '');
        window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');
        return false;
    });

    //linkedIn


    $('#shareLink').click(function () {
        $('#shareLink').attr('href', 'http://www.linkedin.com/shareArticle?mini=true&url=' + url + '&title=' + message + '&source=' + message + '');
        window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600'); return false;
    });

    //Email

    $('#mailLink').click(function () {
        $('#mailLink').attr('href', 'mailto:?body=' + url + '&subject=' + message + '');

    });

    //Share with friends

    $('.ShareWithFreinds').click(function () {
        ShowDialog('#DivShareWithFreinds', 'Article Share with Freinds');
    });

</script>


CSS


Reset css -   http://meyerweb.com/eric/tools/css/reset/ 



<style type="text/css">
    @charset "utf-8";
    @import url('css/api.css');
    @import url('css/reset.css');

    [class*="fontawesome-"]:before {
        font-family: 'FontAwesome', sans-serif;
    }


    a {
        text-decoration: none;
    }

    .float-left {
        float: left;
    }

    .float-right {
        float: right;
    }

    .clearfix {
        *zoom: 1;
    }

        .clearfix:before, .clearfix:after {
            display: table;
            content: "";
        }

        .clearfix:after {
            clear: both;
        }


    /* ---------- NAVIGATION ---------- */

    nav {
            float: right;
    margin-top: -18px;
    position: fixed;
    margin-left: -17px;
    }

        nav ul {
            background-color: #505664;
            border-radius: 5px;
            -moz-border-radius: 5px;
            -webkit-border-radius: 5px;
            display: inline-table;
            position: relative;
        }

            nav ul li {
                float: left;
            }

                nav ul li a {
                    color: #6daeb0;
                    display: block;
                    height: 45px;
                    line-height: 45px;
                    text-align: center;
                    width: 60px;
                }

                    nav ul li a:hover {
                        color: #fff;
                    }

                nav ul li ul {
                    background-color: #6daeb0;
                    margin-top: 20px;
                    padding: 5px 0;
                    position: absolute;
                }

                    nav ul li ul:before {
                        background-color: #6daeb0;
                        content: "";
                        display: block;
                        height: 8px;
                        left: 26px; /* (nav ul li a { width: 60px; } / 2) - (nav ul li ul:before { width: 8px; } / 2) */
                        position: absolute;
                        top: -4px;
                        transform: rotate(45deg);
                        -ms-transform: rotate(45deg);
                        -moz-transform: rotate(45deg);
                        -webkit-transform: rotate(45deg);
                        width: 8px;
                        z-index: 1000;
                    }

                    nav ul li ul li {
                        float: none;
                    }

                        nav ul li ul li a {
                            color: #fff;
                        }

                            nav ul li ul li a:hover {
                                background-color: #5d9799;
                            }

</style>
read more

Monday, 30 May 2016

Validating Signup form in mvc

No comments
CustomerModel.cs

  public class CustomerModel
    {
        public int UserId { get; set; }
        [StringLength(50)]
        [Required(ErrorMessage="Please enter user name")]
        public string UserName { get; set; }

        [DataType(DataType.Password)]
        [StringLength(100)]
        [Required(ErrorMessage = "Please enter password")]
        public string Password { get; set; }
        [DataType(DataType.Password)]                      
        [System.ComponentModel.DataAnnotations.Compare("Password", ErrorMessage = "Password does not match , please re-enter password")]
        public string RetypePassword { get; set; }


        [Required(ErrorMessage = "Please select security question")]
        public int SecurityQuestionId { get; set; }
        [Required(ErrorMessage = "Please enter security answer")]

        [StringLength(50)]
        public string SecurityQueAnswer { get; set; }
        [StringLength(50)]
        [Required(ErrorMessage = "Please enter first name")]
        [RegularExpression(@"^[a-zA-Z]+[ a-zA-Z-_]*$", ErrorMessage = "Invalid first name , no special characters or numbers allowed")]
        public string FirstName { get; set; }
        [StringLength(50)]
        [RegularExpression(@"^[a-zA-Z]+[ a-zA-Z-_]*$", ErrorMessage = "Invalid last name , no special characters or numbers allowed")]
        [Required(ErrorMessage = "Please enter last name")]
        public string LastName { get; set; }
        [StringLength(200)]
        [EmailAddress(ErrorMessage = "Invalid email address , enter valid email address")]
        [Required(ErrorMessage = "Please enter email")]
        public string Email { get; set; }
        [StringLength(50)]
        [System.ComponentModel.DataAnnotations.Compare("Email",ErrorMessage="Email address does not match , please re-enter email")]
        public string RetypeEmail { get; set; }

        [Required(ErrorMessage = "Please select gender")]
        public string Gender { get; set; }
        [StringLength(40)]
        [RegularExpression(@"^[a-zA-Z]+[ a-zA-Z-_]*$", ErrorMessage = "Invalid company name , no special characters or numbers allowed")]
        [Required(ErrorMessage = "Please enter company name")]
        public string CompanyName { get; set; }
        [StringLength(50)]
        [Required(ErrorMessage = "Please enter address")]
        public string Address1 { get; set; }
        [StringLength(50)]
        public string Address2 { get; set; }
        [Required(ErrorMessage = "Please select country")]
        public int CountryId { get; set; }
        [Required(ErrorMessage = "Please select state")]
        public string StateId { get; set; }
        [StringLength(50)]
        [RegularExpression(@"^[a-zA-Z]+[ a-zA-Z-_]*$", ErrorMessage = "Invalid city name , no special characters or numbers allowed")]
        [Required(ErrorMessage = "Please enter city")]
        public string City { get; set; }

        [StringLength(50)]
        [RegularExpression("^[a-zA-Z0-9]*$", ErrorMessage = "Invalid zipcode")]
        [Required(ErrorMessage = "Please enter zipcode")]
        public string ZipCode { get; set; }
   
        [StringLength(15)]
        [Required(ErrorMessage = "Please enter phone no.")]
        [RegularExpression("([1-9][0-9]*)", ErrorMessage = "Invalid phone no.")]
        public string PhoneNo { get; set; }

        [StringLength(20)]
        [RegularExpression("([1-9][0-9]*)", ErrorMessage = "Invalid Fax")]
        public string Fax { get; set; }

        [StringLength(10)]
        public string Status { get; set; }
        public decimal CreditLimit { get; set; }

        public string ActivationToken { get; set; }
     
                     
        public IEnumerable<SelectListItem> SecurityQuestionList { get; set; }
        public IEnumerable<SelectListItem> CountryList { get; set; }
        public IEnumerable<SelectListItem> StateList { get; set; }
    }
read more

Friday, 27 May 2016

Call function if clicked except perticular class or id

No comments
$(document).click(function (e) {
    if (!$(e.target).is('.addSig')) {
        if ($('.tblSig').css('display') == 'none')
            $('.tblSig').show('slow')
        else
            $('.tblSig').hide('slow')
    }
    else {
        $('.tblSig').hide('slow')
    }
});
read more

Thursday, 19 May 2016

Codding standards

No comments
TEXT to be align left
Date to be align center
Numeric to be align right
PascalCase for class and method name
camelCase for argument and variable

for more Click here


read more

Tuesday, 17 May 2016

drop all tables and sp in sql

No comments
DECLARE @sql NVARCHAR(max)=''

SELECT @sql += ' Drop table [' + TABLE_SCHEMA + '].['+ TABLE_NAME + ']'
FROM   INFORMATION_SCHEMA.TABLES
WHERE  TABLE_TYPE = 'BASE TABLE'

Exec Sp_executesql @sql 
read more