Saturday, February 5, 2022

MS Sql server

1. Execute output param in procedure in sql server 


declare @RecordCount int=1

exec [Getcustomers_pager] @topup='0',@RecordCount=@RecordCount output

print @RecordCount


2. Define out parametered in procedure in sql server


CREATE PROCEDURE [dbo].[Getcustomers_pager] @SearchTerm  VARCHAR(100) = '', 

@PageIndex   nvarchar(max) = 1, 

@PageSize    nvarchar(max) = 100,

@mobile      NVARCHAR(max)='', 

@search      INT=0,

@fromdate   nvarchar(max)='',

@todate      nvarchar(max)='',

@topup varchar(10)= '',

@RecordCount INT output 

AS 

BEGIN 

SET nocount ON; 


declare @query nvarchar(max)='',@query1 nvarchar(max)=''

set @query = 'select row_number() over(order by m.id desc) as RowNumber,

case m.status when 1 then ''Active'' else ''Block'' end as blockstatus,

case m.status when 1 then ''success'' else ''danger'' end as blockclass,

case m.status when 1 then ''Block'' else ''Active'' end as blockbtn,

case m.status when 1 then ''danger'' else ''success'' end as blockbtnclass,

format(m.edate,''dd/MM/yyyy'') as date,format(m.top_update,''dd/MM/yyyy'') as top_update1,

(select  max(remark) from cto_achievers where status=1 and uid=m.uid) rank_name,

m.*,l.password,l.trans_password

from Joinnow m with(nolock) inner join login l on m.uid=l.uid 

where l.block=0'


set @query1='select @count= count(m.id) from Joinnow m with(nolock) inner join login l on m.uid=l.uid where l.block=0'


IF(@topup != '')

BEGIN

set @query=@query+' and m.top_up='''+@topup+''''

set @query1=@query1+' and m.top_up='''+@topup+''''

END

ELSE IF(@SearchTerm !='')

BEGIN

set @query=@query+' and m.user_id='+@SearchTerm+' OR l.password ='''+@SearchTerm+''''

set @query1=@query1+' and m.user_id ='+@SearchTerm+' OR l.password='''+@SearchTerm+''''

END

 

ELSE IF(@fromdate !='' or @todate != '')

BEGIN

if(@fromdate != '')

begin

set @query=@query+' and cast(m.edate as date) >= cast('''+@fromdate+''' as date)'

set @query1=@query1+' and cast(m.edate as date) >= cast('''+@fromdate+''' as date)'

end

if(@todate != '')

begin

set @query=@query+' and cast(m.edate as date)<= cast('''+@todate+''' as date)'

set @query1=@query1+' and cast(m.edate as date)<= cast('''+@todate+''' as date)'

end 

END


set @query=@query+' order by m.id desc offset ('+@PageIndex+'-1)*'+@PageSize+' rows fetch next '+@PageSize+' rows only'

exec(@query)

exec sp_executesql @query1,N'@count int output',@count=@RecordCount output


END 





Angular Js Utility

1.  ng-init in Angular Js

@if (Request.QueryString["a"] != null)

{

           <input type="hidden" ng-init="p.user_type='@Request.QueryString["a"]'" />

}

                                        

2. ng-model

<input type="text" id="txtname" ng-model="p.name" class="form-control" placeholder="Enter User Address" maxlength="100" />


3.  ng-click

<input type="button" id="btnsearch" ng-click="getEmployeeList()" class="btn btn-sm btn-success" value="Search" />


4.  ng-change

<select class="form-control" ng-change="getEmployeeList()" ng-model="p.user_type" ng-init="p.user_type=''">

         <option value="">All</option>

         <option value="1">Paid</option>

         <option value="0">UnPaid</option>

</select>


5. Pass value in angular function 


 $scope.p = {};

        var status = null;


        $scope.getIncomeList = function () {

            $('.loader').show();

            if (status == null) {

                status = "2";

            }

            $http.get('/Admin/getReward_Income', $scope.p).then(function (res) {

                $('.loader').hide();

                $scope.getIncome = res.data.IncomeList;

            });

        };




Monday, January 10, 2022

All Capital

1.  All capital in jquery

<script>

$(function () {

        $("input[type='text']").keyup(function () {

            this.value = this.value.toUpperCase();

        });

    });

</script>

Thursday, January 6, 2022

Dependency Injection in .net core 5

There are three of dependency injection executer, we will she their life time cycle

1. Scoped  > It does not go to life time

2. Transient >  It does not go to life time

3. Singleton > It goes to life time




https://www.youtube.com/watch?v=0x2KW-dJDQU


https://www.youtube.com/watch?v=3nnESO6I3iE

 


Monday, January 3, 2022

Angular Get Post in MVC

Angular Js or 1 : Get Post Request

1. Model


public class admin_support_model
{
    public int? id { get; set; }
    public string name { get; set; }
    public string ed_code { get; set; }
    public string email { get; set; }
    public string phone { get; set; }
    public string remark { get; set; }

}
public class education
{
    public string ed_code { get; set; }
    public string ed_name { get; set; }
}
public class admin_news_letter_model
{
    public int? id { get; set; }
    public string email { get; set; }
    public Nullable<DateTime> edate { get; set; }
}

2. Views


@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>

    <script src="/Scripts2/jquery-3.3.1.min.js"></script>
    <script src="/Scripts2/angular.js"></script>
    <script src="/AngularCtrls/CommonFiles/myApp.js"></script>
</head>
<body  ng-app="MyApp">
    <script src="~/AngularCtrls/Admin/supportToAdminCtrl.js"></script>
    <div  ng-controller="supportToAdminCtrl">
        <form id="contact" ng-submit="af_SupportPost();" autocomplete="off">
            <div class="heading-title left">
                <small class="iq-font-green">Support With Us</small>
                <h2 class="title iq-tw-6">Support</h2>

            </div>
            <div class="contact-form">
                <div class="section-field">
                    <br />
                    <input class="require" id="cname" type="text" ng-model="p.name" placeholder="Name*" name="cname" required>
                </div>
                <div class="section-field">
                    Education
                    <select  id="ed_code" name="ed_code" ng-model="p.ed_code" required>
                        <option>
                        </option>
                        <option ng-repeat="m in educationList" value="{{m.ed_code}}" style="width:100px;">
                            {{m.ed_name}}
                        </option>
                        <input type="search" id="ed_name" ng-model="p.ed_name" ng-change="af_Education_List()" style="width:40px;"  />
                    </select>
                </div>
                <div class="section-field">
                    <input class="require" id="cemail" type="email" ng-model="p.email" placeholder="Email*" name="cemail" required>
                </div>
                <div class="section-field">
                    <input class="require" id="cphone" type="number" ng-model="p.phone" placeholder="Phone*" name="cphone" required>
                </div>
                <div class="section-field textarea">
                    <textarea id="cmessage" class="input-message require" ng-model="p.remark" placeholder="Comment*" rows="5" name="cmessage" required></textarea>
                </div>
                <div class="d-block text-center">
                    <button id="btnsupport" type="submit" value="Send" class="button iq-mt-15">Send Message</button>
                </div>
            </div>
        </form>


        <form id="contact" ng-submit="af_WeeklyNews()" autocomplete="off">
            <div class="heading-title text-center">
                <h2 class="title iq-tw-6" style="margin-bottom: 15px;">
                    Weekly newsletter
                </h2>
            </div>

            <div class="contact-form">
                <div class="row">
                    <div class="col-md-12">
                        <div class="section-field">
                            <input class="require" id="contact_email" type="email" ng-model="p.email" placeholder="Email*" name="contact_email" required>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-4">
                        <div class="d-block text-center">
                            <input id="Subscribesubmit" name="submit" type="submit" value="Subscribe" class="button" />
                        </div>
                    </div>
                </div>
            </div>            
        </form>
        <br />
        <table>
            <tr>
                <th>Srno</th>
                <th>Name</th>
                <th>Mobile</th>
                <th>Email</th>                
            </tr>
            <tr ng-repeat="m in supportList">                
                <td>{{m.id}}</td>
                <td>{{m.name}}</td>
                <td>{{m.phone}}</td>
                <td>{{m.email}}</td>                
            </tr>
        </table>

    </div>
</body>
</html>


    JsDownload Link

    https://drive.google.com/file/d/1cRFTMjag3x_fFTRPdPKoArRwDnzHo89z/view?usp=sharing

3. MVC Controller

public class HomeController : Controller
{
    // GET: Home
        public ActionResult Index()
        {
            return View();
        }
        string sql = "";    
        public ActionResult WeeklyNews(admin_news_letter_model d)
        {
            msg msg = new msg() { message = "News Letter Success submitted.", priority = "success", title = "Message" };            
            return Json(new { msg = msg }, JsonRequestBehavior.AllowGet);
        }
        public ActionResult SupportPost(admin_support_model d)
        {
            msg msg = new msg() { message = "Your Query Successfully submitted.", priority = "success", title = "Message" };            
            return Json(new { msg = msg }, JsonRequestBehavior.AllowGet);
        }
        public ActionResult SupportList(admin_support_model d)
        {
            admin_support_model_mvv mvv = new admin_support_model_mvv();

            msg msg = new msg() { message = "Your Query Successfully submitted.", priority = "success", title = "Message" };
            mvv.msgs = msg;

            List<admin_support_model> list = new List<admin_support_model>();
            list.Add(new admin_support_model { id = 1, name = "Rinkesh Gola", phone = "789475897", email = "abc@gmail.com", remark = "aass" });
            list.Add(new admin_support_model { id = 2, name = "Ramesh Sing", phone = "7894712345", email = "abc2@gmail.com", remark = "aass" });
            list.Add(new admin_support_model { id = 3, name = "Ajay Saagar", phone = "789476789", email = "abc3@gmail.com", remark = "aass" });
            list.Add(new admin_support_model { id = 4, name = "Manoj AAAA", phone = "7894711111", email = "abc32@gmail.com", remark = "aass" });
            list.Add(new admin_support_model { id = 5, name = "Sanjay Sharma", phone = "7894744444", email = "abca@gmail.com", remark = "aass" });

            mvv.admin_support_models_list = list;

            return Json(new { modelData = mvv }, JsonRequestBehavior.AllowGet);
        }
        public ActionResult ed_code_list(education d)
        {
            List<education> list = new List<education>();
            list.Add(new education { ed_code = "ED01", ed_name = "Illiterate " });
            list.Add(new education { ed_code = "ED02", ed_name = "Hight School" });
            list.Add(new education { ed_code = "ED03", ed_name = "Intermedeate" });
            list.Add(new education { ed_code = "ED03", ed_name = "Bachelor Degree" });
            list.Add(new education { ed_code = "ED05", ed_name = "Post Graduate" });

            var list2 = (from x in list
                         where (d.ed_name == null || x.ed_name.Contains(d.ed_name))
                         select x).ToList();

            return Json(new { list_data = list2 }, JsonRequestBehavior.AllowGet);
        }       

}


Sunday, January 2, 2022

Remote Validation in MVC

Remote Attributes is used in Remote Validation

1. Model : Remote Validating is used on emp_name, Rirst fill the appropriate Action Method and Error message in the Remote Attribute

public class Employee
{      
    [Key]
    public string emp_code { get; set; }
    [Remote("checkEmpName", "Home", ErrorMessage = "User name already exists")]
    public string emp_name { get; set; }
    public string emp_mobile { get; set; }
}

2. Controller : Pass  same property varibale name (emp_name) into Method checkEmpName


public class HomeController : Controller
{
    public ActionResult Create()
    {
        return View();
    }
    public JsonResult checkEmpName(string emp_name)
    {
        List<Employee> list = new List<Employee>();
        list.Add(new Employee { emp_code = "E001", emp_name = "Rinkesh", emp_mobile = "9027581975" });
        list.Add(new Employee { emp_code = "E002", emp_name = "Rakesh", emp_mobile = "9027581975" });
        list.Add(new Employee { emp_code = "E003", emp_name = "Ajay", emp_mobile = "9027581976" });

        bool st = (!list.Any(x => x.emp_name == emp_name));

        return Json(st, JsonRequestBehavior.AllowGet);
    }
}

3. View :  Required jquery is 

jquery-3.3.1.min.js, 

jquery.validate.min.js, 

jquery.validate.unobtrusive.min.js


@model Angular1Test.Models.Employee
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Create</title>
</head>
<body>
    <script src="~/Scripts/jquery-3.3.1.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="row">
            <div class="col-md-3">
                @Html.LabelFor(model => model.emp_code, htmlAttributes: new { @class = "control-label" })
                @Html.EditorFor(model => model.emp_code, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.emp_code, "", new { @class = "text-danger" })
            </div>

            <div class="col-md-3">
                @Html.LabelFor(model => model.emp_name, htmlAttributes: new { @class = "control-label" })
                @Html.EditorFor(model => model.emp_name, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.emp_name, "", new { @class = "text-danger" })
            </div>
            <div class="col-md-3">
                @Html.LabelFor(model => model.emp_mobile, htmlAttributes: new { @class = "control-label" })
                @Html.EditorFor(model => model.emp_mobile, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.emp_mobile, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <br>
                <input type="submit" value="Create" class="btn btn-default" />
                @Html.ActionLink("Back to List", "Index", new { }, new { @class = "btn btn-default" })
            </div>
        </div>
    }

    <div>
    </div>
</body>
</html>


A link to video

https://www.youtube.com/watch?v=DUej0Z8gDnA

Saturday, January 1, 2022

Edit Scaffold Templates for mvc

Edit Scaffold Templates for MVC  in Visual Studio 2019, for Create, Edit, Delete, List etc.

1. If you installer Visual Studio 2019 Enterprise Edition

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates\MvcView


2. If you installer Visual Studio 2019 Professional Edition 

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates\MvcView

Linq Expression syntax for where condtion in linq

(Expression<Func<T, bool>> filter)