#For configuring SSL in apache sudo apt-get install openssl sudo apt-get install libssl-dev openssl x509 Details…
Author: akash073
Dynamic from upload with angular js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
@*@model ERPSales.Web.Areas.Settings.ViewModels.CategoryViewModel*@ @{ ViewBag.Title = "Create Category"; } <div ng-app="createCatgeoryApp" ng-controller="createCategoryController"> <div class="panel panel-info"> <div class="panel-heading clearfix"> Catgeory page </div> <div class="panel-body"> <!-- Button trigger modal --> <button class="btn btn-primary" data-toggle="modal" data-target="#myModal" data-backdrop="static" data-keyboard="false"> Add Category </button> </div> </div> <div> <table class="table table-bordered"> <tr> <th style="width: 20%"> Name </th> <th> Description </th> <th> Action </th> </tr> <tr ng-repeat="cat in categories"> <td> {{cat.Name}} </td> <td> {{cat.Description}} </td> <td> <span ng-click="editCategory(cat)" class="btn btn-success" data-toggle="modal" data-target="#myModal" data-backdrop="static" data-keyboard="false">Edit</span> <span ng-click="deleteCategory(cat)" class="btn btn-danger">Delete</span> </td> </tr> </table> </div> <!-- Modal --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> × </button> <h4 class="modal-title" id="myModalLabel"> This Modal title </h4> </div> <div class="modal-body"> <form name="categoryForm" ng-submit="submitForm()" novalidate> <!-- Id --> <div class="form-group" > <label>Id</label> <input type="text" name="Id" class="form-control" ng-model="category.Id" disabled> </div> <!-- NAME --> <div class="form-group" ng-class="{ 'has-error' : categoryForm.Name.$invalid && !categoryForm.Name.$pristine }"> <label>CatgeoryName</label> <input type="text" name="Name" class="form-control" ng-model="category.Name" required> <p ng-show="categoryForm.Name.$invalid && !categoryForm.Name.$pristine" class="help-block">You name is required.</p> </div> <!-- DESCRIPTION --> <div class="form-group" ng-class="{ 'has-error' : categoryForm.Description.$invalid && !categoryForm.Description.$pristine }"> <label>Description</label> <textarea name="Description" class="form-control" ng-model="category.Description" ng-minlength="3" ng-maxlength="800" required></textarea> <p ng-show="categoryForm.Description.$error.minlength" class="help-block">Description is too short.</p> </div> <button type="submit" class="btn btn-primary" ng-disabled="categoryForm.$invalid" > Submit changes </button> <button type="button" class="btn btn-default" data-dismiss="modal"> Close </button> </form> </div> @*<div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal"> Close </button> <button type="button" class="btn btn-primary"> Submit changes </button> </div>*@ </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div><!-- /.modal --> </div> <script> // create angular app var createCatgeoryApp = angular.module('createCatgeoryApp', []); // create angular controller and inject service createCatgeoryApp.controller('createCategoryController', function ($scope, categoryService) { //List all caetgory categoryService.getCategories().then(function (data) { $scope.categories = data.data; console.log($scope.categories); }, function () { alert('error'); }); // function to submit the form after all validation has occurred $scope.submitForm = function () { // check to make sure the form is completely valid if ($scope.categoryForm.$valid) { var category = $scope.category; console.log(category); categoryService.addCategory(category).then(function (data) { console.log(data); if (data.data.result == true) { //Update Scope to reflect dynamic changes $scope.categories.unshift(category); alert('Category Saved Successfully'); //Clear angular form $scope.categoryForm.$setPristine(); document.getElementById('myModal').modal('hide'); } }, function (error) { alert('Oops'); }); } }; $scope.editCategory = function(category) { $scope.category = category; }; $scope.deleteCategory = function(category) { console.log(category); categoryService.deleteCategory(category).then( function (data) { console.log(data); $scope.categories = $scope.categories.filter(function (item) { return item.Id !== category.Id; }); }, function() { alert('error'); } ); }; }); createCatgeoryApp.service("categoryService", function ($http) { this.getCategories = function () { var response = $http({ method: "GET", url: "/Settings/Category/CategoryList" }); return response; }; // Add Category this.addCategory = function (category) { // console.log(category); var response = $http({ method: "post", url: "/Settings/Category/CreateCategory", data: JSON.stringify(category), dataType: "json" }); return response; }; //Delete Employee this.deleteCategory = function (category) { var response = $http({ method: "POST", url: "/Settings/Category/DeleteCategory", data: JSON.stringify(category), dataType: "json", headers: { "Content-Type": "application/json" } //params: { // employeeId: JSON.stringify(employeeId) // } }); return response; }; }); </script> |
Add category like row with dynamic update with jQuery and ajax begin form
Model:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
public class CategoryViewModel { public long Id { get; set; } [Required] [StringLength(100, MinimumLength = 2, ErrorMessage = "Category Name cannot be longer than 100 characters and less than 2 characters")] [ValidateCategoryName(ErrorMessage = "Invalid name")] //Action result in controller which return Json object true while validation failed //[Remote("IsCategoryNameExists", "Category", "Settings", HttpMethod = "POST", ErrorMessage = "Catgory Name already exists")] public string Name { get; set; } [Required] public string Description { get; set; } //Edit Pupose //[ScaffoldColumn(false)] //public string PreviousName { get; set; } } |
and commonJqueryAjax
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
function commonJqueryAjax(myUrl, myData) { $.extend({ xResponse: function (url, data) { // local var var theResponse = null; // jQuery ajax $.ajax({ url: url, type: 'POST', data: JSON.stringify(data), async: false, contentType: 'application/json', success: function (respText) { theResponse = respText; }, error: function (jqXhr, textStatus, errorThrown) { alert('error ..Check log for details'); console.log(textStatus, errorThrown); var msg = ''; if (jqXhr.status === 0) { msg = 'Not connect.\n Verify Network.'; } else if (jqXhr.status == 404) { msg = 'Requested page not found. [404]'; } else if (jqXhr.status == 500) { msg = 'Internal Server Error [500].'; } else if (errorThrown === 'parsererror') { msg = 'Requested JSON parse failed.'; } else if (errorThrown === 'timeout') { msg = 'Time out error.'; } else if (errorThrown === 'abort') { msg = 'Ajax request aborted.'; } else { msg = 'Uncaught Error.\n' + jqXhr.responseText; } console.log(msg); } }); // Return the response text return theResponse; } }); // set ajax response in var var xData = $.xResponse(myUrl, myData); return xData; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
@model ERPSales.Web.Areas.Settings.ViewModels.CategoryViewModel @{ ViewBag.Title = "CategoryList"; //Layout = null; } <h2>CategoryList</h2> <button class="btn btn-primary" onclick="addCategory()">Add</button> <table class="table table-bordered" id="tbl"> <thead> <tr> <th> @Html.DisplayNameFor(model => model.Id) </th> <th> @Html.DisplayNameFor(model => model.Name) </th> <th> @Html.DisplayNameFor(model => model.Description) </th> <th> Action </th> </tr> </thead> <tbody> @foreach (var item in (List<ERPSales.Web.Areas.Settings.ViewModels.CategoryViewModel>)ViewBag.CategoryViewModels) { <tr> <td> @Html.DisplayFor(modelItem => item.Id) </td> <td> @Html.DisplayFor(modelItem => item.Name) </td> <td> @Html.DisplayFor(modelItem => item.Description) </td> <td> <button class="btn btn-success edit">Edit</button> <button class="btn btn-danger delete">Delete</button> </td> </tr> } </tbody> </table> <div id="result"> </div> <div> @{ AjaxOptions options = new AjaxOptions(); options.HttpMethod = "POST"; options.OnSuccess = "OnSuccessRequest"; options.OnFailure = "OnFailureRequest"; options.UpdateTargetId = "result"; options.InsertionMode = InsertionMode.Replace; } @using (Ajax.BeginForm("CreateCategory", "Category", new { area = "Settings" }, options, new { id = "formId" })) { <div class="modal fade" id="detailsModal"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Modal title</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <div class="form-horizontal"> <div class="form-group"> @Html.LabelFor(model => model.Id, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.TextBoxFor(model => model.Id) @Html.ValidationMessageFor(model => model.Id) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Name, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.TextBoxFor(model => model.Name) @Html.ValidationMessageFor(model => model.Name) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Description, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.TextBoxFor(model => model.Description) @Html.ValidationMessageFor(model => model.Description) </div> </div> </div> <div class="modal-footer"> <input type="submit" class="btn btn-success" value="Save" /> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> </div> </div> </div> </div> </div> } </div> <script> var currentRow; $(document).on('click', '.edit', function () { currentRow = $(this).closest('tr'); // currentRow.remove(); var id = $(this).parent().siblings(":first").text(); var url = '@Url.Action("CategoryById", "Category", new { area = "Settings" })'; var obj = {}; obj.id = id; var result = commonJqueryAjax(url, obj); $('#Id').val(result.Object.Id); $('#Name').val(result.Object.Name); $('#Description').val(result.Object.Description); addCategory(); }); $(document).on('click', '.delete', function () { // Do something on an existent or future .dynamicElement var id = $(this).parent().siblings(":first").text(); var url = '@Url.Action("DeleteCategory","Category",new{ area = "Settings" })'; var obj = {}; obj.id = id; var result = commonJqueryAjax(url, obj); //console.log(result); if (result.result == true) { alert('Deleted successfully'); $(this).closest('tr').remove(); } }); function OnSuccessRequest(result) { console.log(result); if (result.Errored == true) { alert(result.ErrorMessage); } else { //If edited remove the old row if (result.Edited == true) { alert('Edited Category'); currentRow.remove(); } else { alert('Added Category'); } var tr = '<tr>'; tr = tr + '<td>' + result.Object.Id + '</td>'; tr = tr + '<td>' + result.Object.Name + '</td>'; tr = tr + '<td>' + result.Object.Description + '</td>'; tr = tr + '<td>' + ' <button class="btn btn-success edit">Edit</button> <button class="btn btn-danger delete">Delete</button>' + '</td>'; tr = tr + '</tr>'; $('#tbl > tbody:first').prepend(tr); $('#detailsModal').modal('hide'); $('#formId')[0].reset(); } } function addCategory() { $('#detailsModal').modal({ show: true, backdrop: 'static' }); } function OnFailureRequest(jqXhr, textStatus, errorThrown) { alert('error ..Check log for details'); console.log(textStatus, errorThrown); var msg = ''; if (jqXhr.status === 0) { msg = 'Not connect.\n Verify Network.'; } else if (jqXhr.status == 404) { msg = 'Requested page not found. [404]'; } else if (jqXhr.status == 500) { msg = 'Internal Server Error [500].'; } else if (errorThrown === 'parsererror') { msg = 'Requested JSON parse failed.'; } else if (errorThrown === 'timeout') { msg = 'Time out error.'; } else if (errorThrown === 'abort') { msg = 'Ajax request aborted.'; } else { msg = 'Uncaught Error.\n' + jqXhr.responseText; } console.log(msg); } </script> |
and final updated version
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
@model ERPSales.Web.Areas.Settings.ViewModels.CategoryViewModel @{ ViewBag.Title = "CategoryList"; } <button class="btn btn-primary" onclick="addCategory()">Add</button> <table class="table table-bordered" id="tbl"> <thead> <tr> <th> @Html.DisplayNameFor(model => model.Id) </th> <th> @Html.DisplayNameFor(model => model.Name) </th> <th> @Html.DisplayNameFor(model => model.Description) </th> <th> Action </th> </tr> </thead> <tbody> @foreach (var item in (List<ERPSales.Web.Areas.Settings.ViewModels.CategoryViewModel>)ViewBag.CategoryViewModels) { <tr> <td> @Html.DisplayFor(modelItem => item.Id) </td> <td> @Html.DisplayFor(modelItem => item.Name) </td> <td> @Html.DisplayFor(modelItem => item.Description) </td> <td> <button class="btn btn-success edit">Edit</button> <button class="btn btn-danger delete">Delete</button> </td> </tr> } </tbody> </table> <div> @{ AjaxOptions options = new AjaxOptions(); options.HttpMethod = "POST"; options.OnSuccess = "OnSuccessRequest"; } @using (Ajax.BeginForm("CreateCategory", "Category", new { area = "Settings" }, options, new { id = "formId" })) { <div class="modal fade" id="detailsModal"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" onclick="closeModal()" aria-hidden="true"> × </button> <h4 class="modal-title" id="myModalLabel"> Category Add or Edit </h4> </div> <div class="modal-body"> <div class="form-horizontal"> <div class="form-group"> @Html.LabelFor(model => model.Id, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.TextBoxFor(model => model.Id, new { @class = "form-control", @disabled = "disabled" }) @Html.ValidationMessageFor(model => model.Id) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Name, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.TextBoxFor(model => model.Name, new { @class = "form-control"}) @Html.ValidationMessageFor(model => model.Name) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Description, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.TextAreaFor(model => model.Description, new { @class = "form-control"}) @Html.ValidationMessageFor(model => model.Description) </div> </div> </div> <div class="modal-footer"> <input type="submit" class="btn btn-success" value="Save" /> <button type="button" class="btn btn-info" onclick="closeModal()">Close</button> </div> </div> </div> </div> </div> } </div> <script> function closeModal() { //Hide the modal $('#detailsModal').modal('hide'); //Reset the form to previous state $('#formId')[0].reset(); } var currentEditedRow = false; //Edit // Do something on an existent or future .dynamicElement $(document).on('click', '.edit', function () { currentEditedRow = $(this).closest('tr'); // currentRow.remove() will be called after successfully edited the row //Get the form data and append it to form var id = $(this).parent().siblings(":first").text(); var url = '@Url.Action("CategoryById", "Category", new { area = "Settings" })'; var obj = {}; obj.id = id; var result = commonJqueryAjax(url, obj); console.log(result); $('#Id').val(result.Object.Id); $('#Name').val(result.Object.Name); $('#Description').val(result.Object.Description); addCategory(); }); //Delete $(document).on('click', '.delete', function () { var confrimDelete = confirm("Do you really want to delete?"); if (confrimDelete == true) { var id = $(this).parent().siblings(":first").text(); var url = '@Url.Action("DeleteCategory", "Category", new {area = "Settings"})'; var obj = {}; obj.id = id; var result = commonJqueryAjax(url, obj); if (result.result == true) { alert('Deleted successfully'); $(this).closest('tr').remove(); } } }); //Successful AJAX request will return _CategoryRow partial view and this method will prepend it to table id="tbl" function OnSuccessRequest(result) { console.log(result); if (currentEditedRow != false) { currentEditedRow.remove(); currentEditedRow = false; } var tr = result; $('#tbl > tbody:first').prepend(tr); } //POP up the modal function addCategory() { $('#detailsModal').modal({ show: true, backdrop: 'static' }); } //Failure request if any function OnFailureRequest(jqXhr, textStatus, errorThrown) { alert('error ..Check log for details'); console.log(textStatus, errorThrown); var msg = ''; if (jqXhr.status === 0) { msg = 'Not connect.\n Verify Network.'; } else if (jqXhr.status == 404) { msg = 'Requested page not found. [404]'; } else if (jqXhr.status == 500) { msg = 'Internal Server Error [500].'; } else if (errorThrown === 'parsererror') { msg = 'Requested JSON parse failed.'; } else if (errorThrown === 'timeout') { msg = 'Time out error.'; } else if (errorThrown === 'abort') { msg = 'Ajax request aborted.'; } else { msg = 'Uncaught Error.\n' + jqXhr.responseText; } console.log(msg); } </script> |
and controller
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using ERPSales.Core.Helpers; using ERPSales.Models.Settings; using ERPSales.Service.Settings.Interfaces; using ERPSales.Service.Settings.Services; using ERPSales.Web.Areas.Settings.ViewModels; using ERPSales.Web.Models; using Newtonsoft.Json; namespace ERPSales.Web.Areas.Settings.Controllers { public class CategoryController : Controller { private readonly ICategoryService _categoryService; public CategoryController(CategoryService categoryService) { _categoryService = categoryService; } public ActionResult CategoryList() { var categoryViewModel = new CategoryViewModel(); List<Category> categories = _categoryService.GetCategories(); var categoryViewModels = GenericMapper<Category, CategoryViewModel>.GetDestinationList(categories); //For showing category ViewBag.CategoryViewModels = categoryViewModels.OrderByDescending(x => x.Id).ToList(); return View(categoryViewModel); } [HttpPost] public PartialViewResult CreateCategory(CategoryViewModel categoryViewModel) { Category category = GenericMapper<CategoryViewModel, Category>.GetDestination(categoryViewModel); if (category.Id == 0) { //Add catgeory _categoryService.SaveCategory(category); categoryViewModel.Id = category.Id; } else { _categoryService.UpdateCategory(category); } return PartialView("~/Areas/Settings/Views/Category/Partial/_CategoryRow.cshtml", categoryViewModel); } [HttpPost] public JsonResult CategoryById(long id) { Category category = _categoryService.GetCategoryById(id); var categoryViewModel = GenericMapper<Category, CategoryViewModel>.GetDestination(category); var response = new Response<CategoryViewModel>(); response.Object = categoryViewModel; return Json(response, JsonRequestBehavior.AllowGet); } [HttpPost] public JsonResult DeleteCategory(CategoryViewModel categoryViewModel) { _categoryService.DeleteCategory(categoryViewModel.Id); return Json(new { result = true }, JsonRequestBehavior.AllowGet); } } } |
and Details…
All about css from lynda
C01. Div/h1 is a element which is start ans end tag and it is non-replaceable Details…
Generic Repository Pattern implementation with laravel
Create a database in mysql
1 2 3 4 5 |
drop table test; create table test( id int(11) AUTO_INCREMENT PRIMARY KEY, name text ); |
or create model by artisan command
1 |
php artisan make:model Test |
or create Details…
Add Menu in Drupal
1.To Add menu go to Structure->Menus->Add Menu (My First Menu) 2.Add links for pages 3.Show Details…
Chapter 2:Creating and Managing Content
content is any combination of text, pictures, video, audio, and graphics. An individual piece of Details…
01.My Personal Introduction to Drupal
The standard release of Drupal, known as Drupal core, contains basic features that can be Details…
Some Useful Tips For Clean Coding
First of all coding is a art…There are some rule to follow .. 1.Naming of Details…
Asynchronous Programming in asp.net core with an example
#ConectionString from startup public static string ConnectionString { get; private set; } ConnectionString = Configuration.GetValue(“Data:DefaultConnection:ConnectionString”); Details…