Thursday, December 6, 2018

Using of AllowAnonymous in Login and Register to Secure Method



 [AllowAnonymous]
 public ActionResult Login(string returnUrl)

 [HttpPost]
 [AllowAnonymous]
 [ValidateAntiForgeryToken]
 public ActionResult Login(LoginModel model, string returnUrl)

 [AllowAnonymous]
 public ActionResult Register()

 [HttpPost]
 [AllowAnonymous]
 [ValidateAntiForgeryToken]
 public ActionResult Register(RegisterModel model)

Convert Database Data to JSON Data


public string ConvertDataTabletoString()
{
         DataTable dt = new DataTable();
         using (SqlConnection con = new SqlConnection("Data Source=XXX;Initial Catalog=master;Integrated Security=true"))
         {
               using (SqlCommand cmd = new SqlCommand("select id,name,age from employee", con))
                {
                  con.Open();
                  SqlDataAdapter da = new SqlDataAdapter(cmd);
                  da.Fill(dt);
                  System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                  List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
                   Dictionary<string, object> row;
                               foreach (DataRow dr in dt.Rows)
                                {
                                    row = new Dictionary<string, object>();
                                    foreach (DataColumn col in dt.Columns)
                                    {
                                         row.Add(col.ColumnName, dr[col]);
                                    } 
                                    rows.Add(row);
                                 }
                                return serializer.Serialize(rows);
                      }
                }
           }

Note: You just replace datasource (XXX) then it will take data from your table and covert to JSON. 
Thanks for your comment.

Wednesday, December 5, 2018

Searching Tools supports MVC


Knockout tools

Knockout Tools: Get here

Sample: Click here

JSFiddle: Click Me

Any other tools? Please comment... Thanks


Tuesday, December 4, 2018

Bitmap Combine Multiple Images

public static System.Drawing.Bitmap CombineBitmap(string[] files)
{
    //read all images into memory
    List<System.Drawing.Bitmap> images = new List<System.Drawing.Bitmap>();
    System.Drawing.Bitmap outcomeImage = null;

    try
    {
        int width = 0;
        int height = 0;

        foreach (string image in files)
        {
            //create a Bitmap from the file and add it to the list
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image);

            //update the size of the final bitmap
            width += bitmap.Width;
            height = bitmap.Height > height ? bitmap.Height : height;

            images.Add(bitmap);
        }

        //create a bitmap to hold the combined image
        outcomeImage = new System.Drawing.Bitmap(width, height);

        //get a graphics object from the image so we can draw on it
        using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(outcomeImage))
        {
            //set background color
            g.Clear(System.Drawing.Color.Black);

            //go through each image and draw it on the final image
            int offset = 0;
            foreach (System.Drawing.Bitmap image in images)
            {
                g.DrawImage(image,
                  new System.Drawing.Rectangle(offset, 0, image.Width, image.Height));
                offset += image.Width;
            }
        }

        return outcomeImage;
    }
    catch (Exception ex)
    {
        if (outcomeImage != null)
            outcomeImage.Dispose();

        throw ex;
    }
    finally
    {
        //clean up memory
        foreach (System.Drawing.Bitmap image in images)
        {
            image.Dispose();
        }
    }
}