Sunday, April 28, 2019

MVC Remove Plural Table Name With DbContext in EF6.0

1. MVC Remove Plural Table Name With DbContext in EF6.0

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}

EF SaveChanges like insert get id value after SaveChanges

1. EF SaveChanges like insert get id value after SaveChanges

Thursday, April 25, 2019

MVC Authorization Custom Error Page 401 and (Not found)404

1. Error 401 Authorization

public class Global : HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);         
        }

        protected void Application_EndRequest()
        {
            var context = new HttpContextWrapper(Context);
            if (context.Response.StatusCode == 401)
            {
                context.Response.Redirect("~/Home/Error2");
            }
        }
    }


2.   Error 404
 <customErrors mode="On">     
      <error statusCode="404" redirect="~/Home/Error"/>
    </customErrors>


Wednesday, April 24, 2019

MVC Layout with ActionResult Method

1. MVC Execute Layout in ActionResult Method

Table Value Post

1. In HTML>

<tbody>
         @for (int i = 0; i < data_list.Count; i++)
                   {

                        <tr>
                             <td class="table-user">
                                            <input type="hidden" name="st_li[@(i)].AdmNo" value="@data_list[i].AdmNo" />                                            
                                            @data_list[i].AdmNo
                                            @*@Html.TextBox("Attedance_Stu[" + @i + "].AdmNo", @data_list[i].AdmNo)*@

                                        </td>
                                        <td class="table-user">
                                            @data_list[i].FIRST_NM
                                        </td>
                                        <td>
                                            <input type="checkbox" name="st_li[@(i)].select_status" value="true" />
                                        </td>
                                    </tr>
                                    }
 </tbody>


2. In C# >

  public bool Post(List<Attedance_Stu> st_li, Attedance status)
{

}

Static DropDown in Razor Fill Normal

 @{
          var list = new SelectList(new[] { "P","H","S","A","M","L","E" });
 }
                         
 @Html.DropDownList("selected", list,  new { @class = "form-control  mb-2", @placeholder = "Selected Attendace" })
                     
@Html.DropDownList("unselected", list, new { @class = "form-control  mb-2", @placeholder = "Unselected Attendace" })
                       

Tuesday, April 23, 2019

MVC Validations

1. MVC validation's server side (on model)  is > Required, Email, Range

2. MVC Server Side (Model) validation with message
3. MVC Client Side validation (on Viewl)

4. MVC Client Side validation (on Viewl) with Strongly Binding
5. MVC Client Side validation (on Viewl) with ValidationSummary

6.A. Define Custom Validation

6.B. Custom Server Validation Apply

7. Remove Validation Text Message from Client on Server Side

8. Define Custom Validation Set Message with Control Name


Monday, April 22, 2019

Routing custome url constraint for int id

Traditional Routing

Attribute Routing

1. Attribute routing define in routeConfig

2. Attribute routing apply in controller

3. Attribute routing apply with RoutePrefix in controller

4. Attribute routing apply with id contraint in controller
                                          asingn one integer

5. Attribute routing with id contraint with min max  apply in controller

6. Attribute routing apply with override with tild sign in controller
                 without routePrefix


Thursday, April 18, 2019

Web Api Login With JQuery

function fn_item_list() {
        $.ajax({
            type: "GET",
            xhrFields: {
                withCredentials: true
            },
            headers: {
                'Authorization': 'Basic ' + 'admin:123'
                //'Authorization': 'Basic ' + btoa('admin:123')
            },
            url: "/api/Customers_",
            data: {
                cust_name: $("#cust_names").val()
            },
            success: function (data) {
                //alert(data);
                $("#div_item1 table tbody").empty();
                //var dt = JSON.parse(data);
                var dt = data;
                //alert(jsonObj.length);
                for (var i = 0; i < dt.length; i++) {
                    var sql = "<tr>";
                    sql += " <td>" + dt[i].cust_code + "</td>";
                    sql += " <td>" + dt[i].cust_name + "</td>";
                    sql += " <td onclick=fn_Edit('" + dt[i].cust_code + "') class='btn btn-success' ><i class='fa fa-trash' aria-hidden='true'></i></td>";
                    sql += " <td onclick=fn_Delete('" + dt[i].cust_code + "') class='btn btn-danger' ><i class='fa fa-trash' aria-hidden='true'></i></td>";
                    sql += "</tr>";
                    $("#div_item1 table tbody").append(sql);
                }
            },
            error: function (data) {
                alert("error : " + data);
            },
            failed: function (data) {
                alert("failed : " + data);
            }
        });
    };

Web Api Authentication

public class ApiBasicAuthenticationAttribute : AuthorizationFilterAttribute
    {
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            if (actionContext.Request.Headers.Authorization == null)
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
            }
            else
            {
                string authenticationToken = actionContext.Request.Headers.Authorization.Parameter;
                string decodedAuthenticationToken = Encoding.UTF8.GetString(Convert.FromBase64String(authenticationToken));
                //string decodedAuthenticationToken = authenticationToken;
                string[] usernamePasswordArray = decodedAuthenticationToken.Split(':');
                string username = usernamePasswordArray[0];
                string password = usernamePasswordArray[1];

                if (user_mas.Login(username, password))
                {
                    Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(username), null);
                }
                else
                {
                    actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
                }
            }

        }
    }

Monday, April 15, 2019

Design

1. Match colour
For background in photoshop
2.  Alt shift ctrl v    for copy with mask
3. Feather 1 for remove edges
4. Ctrl  and select layer    for select all object from png
5. Select circle or oval 》image 》 select clip mask
6. Do Transparent image 》opacity change

Tuesday, April 9, 2019

Change Route of Web Api

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Vidhyalay_Online.Auth;
using Vidhyalay_Online.Models;

namespace Vidhyalay_Online.Controllers_Api
{
    [RoutePrefix("api/users")]
    public class FeeHeadListController : ApiController
    {
        private db_context db = new db_context();
        DataUtility du = new DataUtility();
        string sql = "";

        // GET: api/FeeHeadList
        [Route("data")]
        [HttpGet]
        public List<v_student_wise_fee_WMnCnP> get_feedetail([FromUri] v_student_wise_fee_WMnCnP d)
        {
            var data = from x in db.v_student_wise_fee_WMnCnP
                       where (d.ADM_NO == null || x.ADM_NO == d.ADM_NO)
                       && (d.STUDENTID == null || d.STUDENTID == x.STUDENTID)
                       orderby x.ACT_CODE
                       select x;
            List<v_student_wise_fee_WMnCnP> data_list = data.ToList();
            return data_list;
        }
        [Route("adm_no")]
        [HttpGet]
        public List<v_student_wise_fee_WMnCnP> get_feedetail(string adm_no)
        {
            var data = from x in db.v_student_wise_fee_WMnCnP
                       where (adm_no == null || x.ADM_NO == adm_no)                     
                       orderby x.ACT_CODE
                       select x;
            List<v_student_wise_fee_WMnCnP> data_list = data.ToList();
            return data_list;
        }

        [Route("data3")]
        [HttpGet]
        public List<v_student_wise_fee_WMnCnP> get_feedetail1([FromUri] v_student_wise_fee_WMnCnP d)
        {
            var data = from x in db.v_student_wise_fee_WMnCnP
                       where (d.ADM_NO == null || x.ADM_NO == d.ADM_NO)
                       && (d.STUDENTID == null || d.STUDENTID == x.STUDENTID)
                       orderby x.ACT_CODE
                       select x;
            List<v_student_wise_fee_WMnCnP> data_list = data.ToList();
            return data_list;
        }
       
    }
}

Tuesday, April 2, 2019

Short cut or Hot Key in Visual Studio (VS)

1. Short cut for DataTable or other variable value on debug time
       Shift + f9

2. Short cut for Solution Explorer
       Ctrl + Alt + L

3. Short cut for File Preview in Solution Explorer
       Crtl + [ + S
     
4. Go Back Ward or Or Opposite of  F12
        Ctrl + -

5. Commet
        Ctrl + K + C

6. Un-comment
        Ctrl + K + U

7. Expand All
        Ctrl + M + O

8. Collapse All in C# and Html
        Ctrl + M + A

9.  C# Code preview in VS2015
        Alt + F12

Monday, April 1, 2019

Pass Another Value from ViewBag or Other ino EditorFor

...
@if (d.fee1 > 0)

{

<div class="form-group">

@Html.LabelFor(model => model.fee1, htmlAttributes: new { @class = "control-label col-md-2" })

<div class="col-md-10">

    @Html.EditorFor(model => model.fee1, new { htmlAttributes = new { @class = "form-control",@Value=d.fee1 } })

    @Html.ValidationMessageFor(model => model.fee1, "", new { @class = "text-danger" })

</div>

</div>

}

@if (d.fee2 > 0)

{

<div class="form-group">

@Html.LabelFor(model => model.Fee2, htmlAttributes: new { @class = "control-label col-md-2" })

<div class="col-md-10">

    @Html.EditorFor(model => model.Fee2, new { htmlAttributes = new { @class = "form-control" ,@Value=d.fee2} })

    @Html.ValidationMessageFor(model => model.Fee2, "", new { @class = "text-danger" })

</div>

</div>

}

Linq Expression syntax for where condtion in linq

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