Thursday, April 18, 2019

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>

}

Wednesday, March 13, 2019

Html Page Navigator in Visual Studio 2015 / Other Version

Show/Hide Html Page Navigator for .aspx, .cshtml, etc.
Go to
Menu>Tools>Options>Text Editor>HTML>Advanced>Enable Tag Navigator True/False

Tuesday, March 12, 2019

Row number on page/form in Visual Studio 2015 and Other Version

Show/Hide Line/Row number on page/form in Visual Studio 2015 and Other Version

Go to
Menu>Tools>Options>Text Editor>All Languages>General> Line Numbers 

Linq Expression syntax for where condtion in linq

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