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)