Friday 18 May 2018

File DownLoader in Controller


File DownLoader in Controller

 public ActionResult Download(string Document_Name )
  {
            string Driver_ID = Request.UrlReferrer.ToString();         
             byte[] fileBytes = System.IO.File.ReadAllBytes(@"D:\Projects\SampleHariMVC\SampleHariMVC\Documents\"+Driver_ID+"\DAILY WORKSHEET.xlsx");
             string fileName = "DAILY WORKSHEET.xlsx";           
             return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);         
 }

Thursday 17 May 2018

File Upload In MVC



File Upload In MVC :

 <script type="text/javascript">
        var image = {};
        $(document).ready(function () {
            var file_names = "";
            var doc_nos = "";
        $('#file').change(function () {
            debugger;
           var formData = new FormData();
           var totalFiles = document.getElementById("file").files.length;
           for (var i = 0; i < totalFiles; i++)
           {
               var file = document.getElementById("file").files[i];
               formData.append("file", file);
           }
           $.ajax({
               type: "POST",
               url: '/Driver/Upload',
               data:  formData,
               dataType: 'json',
               contentType: false,
               processData: false,
               success: function (response) {
                   image = response;
                   alert('File Uploaded.....!!');
               },
               error: function (error) {
                   alert("errror");
               }
           });
           var doc_no = $('#Document_Name').val();
           doc_nos  += doc_no+':';
           var file_name = $('#file').val();
           file_name = file_name.substring(12, file_name.length);
           file_names += file_name + ':';         
           var extension = file_name.substr((file_name.lastIndexOf('.') + 1));
           $('#Document_Details').append('<tr><td>' + i + '</td><td>' + doc_no + '</td><td>' + file_name + '</td> </tr>');
           var i = "";
           i = addSerialNumber();
           $('#Document_Name').val("");
           $('#file').val("");
        });
        $('#btn_submit').click(function () {
            debugger;
            var sa = doc_nos;
            var a = $('#expiry_date').val();
            var b = $('#Entry_date').val();
            $.ajax({
                type: "POST",
                url: "/Driver/Driver_Registration_post",
                dataType: "json",
                data: {
                    Driver_Entry_Date: $('#Entry_date').val(),
                    Emp_Id: $('#Emp_Id').val(),
                    Driving_Years_Exp: $('#Driving_Years_Exp').val(),
                    Driver_License_Type: $('#Driver_License_Type').find(":selected").val(),
                    Driver_License_Number: $('#Driver_License_Number').val(),
                    Driver_Expiry_Date: $('#expiry_date').val(),
                    Driving_Licence_Issue_Authority: $('#Driving_Licence_Issue_Authority').val(),
                    Document_Details: file_names,
                    Document_Name: doc_nos
                },
                success: function (data) {
                    alert("Successfully  Registered..........");
                }
            });
        });
   });

  </script>

Generating Serial No in table using JQuery:

 <script type="text/javascript">
        var addSerialNumber = function () {
            var i = 1;
            $('table tr').each(function (index) {
                $(this).find('td:nth-child(1)').html(index++);
                i++;
            });
        };     
    </script>

Controller Method:
[HttpPost]
        public JsonResult Upload()
        {
           string Driver_id = OBJ_DA_Driver_Details.get_Driver_id();
            string str="";
            if (!(Directory.Exists("Documents" + Driver_id + "/")))
                Directory.CreateDirectory(Server.MapPath("~/Documents/" + Driver_id + "/"));
            for (int i = 0; i < Request.Files.Count; i++)
            {
                var file = Request.Files[i];
                var fileName = Path.GetFileName(file.FileName);
                str = file.FileName;
                var path = Path.Combine(Server.MapPath("~/Documents/" + Driver_id + "/"), fileName);
               file.SaveAs(path);
            }
            return Json(str, JsonRequestBehavior.AllowGet);

        }

Wednesday 16 May 2018

<script>
        $.noConflict();
        jQuery(document).ready(function ($) {
            $('#Entry_date').datepicker({
                autoclose: true,
                dateFormat: 'yy-mm-dd',
                showtime: true
            });
            $('#expiry_date').datepicker({
                autoclose: true,
                dateFormat: 'yy-mm-dd',
                showtime: true
            });
        });
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#Department').change(function () {
                var options = "";
                $.ajax({
                    url: "Bind_Designations",
                    type: "post",
                    dataType: "json",
                    data: { Dept_id: $('#Department').val() },
                    success: function (data) {
                        $.each(data, function (index, item) {
                            options += '<option value=' + item.Value + '>' + item.Text + '</option>'
                        });
                        $('#Des_Id').append(options);
                    },
                    error: function () {
                        alert("error");
                    }
                });
            });
        });
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#Des_Id').change(function () {
                debugger;
                var options = "";
                $.ajax({
                    url: "Bind_Employees",
                    type: "post",
                    dataType: "json",
                    data: { Des_id: $('#Des_Id').val() },
                    success: function (data) {
                        debugger;
                        $.each(data, function (index, item) {
                            options += '<option value=' + item.Value + '>' + item.Text + '</option>'
                        });
                        $('#Emp_Id').append(options);
                    },
                    error: function () {
                        alert("error");
                    }
                });
            });
        });
    </script>

Top Agile Interview Questions & Answers

Top Agile Interview Questions & Answers 1. What is Agile Testing? The first question of agile interview question tests your k...