Skip to content

Instantly share code, notes, and snippets.

View sphingu's full-sized avatar
:dependabot:
Focusing

Sumit Hingu sphingu

:dependabot:
Focusing
View GitHub Profile
Install-Package EntityFramework
Update-Database -Verbose -Force
Enable-Migrations -EnableAutomaticMigrations -Force
Add-Migration //not compulsory
int
string
DateTime
byte[] for binary image
Guid
@sphingu
sphingu / Multiple_File_Upload.cs
Last active December 18, 2015 15:39
Multiple File Upload in MVC
http://www.mindstick.com/Articles/518b07f7-3fc8-4b86-8ab9-cab49ecb001a/
//In View
<form action="@Url.Action("UploadPayment")" method="post" enctype="multipart/form-data">
<input type="file" name="FileUploads" id="FileUploads1" />
<input type="file" name="FileUploads" id="FileUploads2" />
//In Model
public IEnumerable<HttpPostedFileBase> FileUploads { get; set; }
@sphingu
sphingu / HtmlPrefixScopeExtensions.cs
Last active December 18, 2015 15:39
Using Same Model for Multiple times in one View using @Html.BeginCollectionItem
using System;
using System.Web.Mvc;
using System.Web;
using System.Collections.Generic;
namespace NPS.Helpers
{
public static class HtmlPrefixScopeExtensions
{
private const string idsToReuseKey = "__htmlPrefixScopeExtensions_IdsToReuse_";
@sphingu
sphingu / MVC_WebGrid.rb
Created June 18, 2013 13:30
WebGrid in MVC
@{
var grid = new WebGrid(Model.Select((item, index) => new { Index = index+1, Element = item }), defaultSort: "First Name", canSort: true, canPage: true, rowsPerPage: ViewBag.PageSize, ajaxUpdateContainerId: "grid");
}
@grid.GetHtml(htmlAttributes: new { id = "grid" }, fillEmptyRows: false, tableStyle: "webGrid", headerStyle: "header", footerStyle: "footer", rowStyle: "rowcss", alternatingRowStyle: "alterrowcss",
selectedRowStyle: "selectedRow",
columns: grid.Columns(
grid.Column(columnName: "Index", header: "Sr No."),
grid.Column("Element.strSurnameEN", "Name", @<text><i data-val='@item.Element.ID'>@Convert.ToString(item.Element.strSurnameEN + " " + item.Element.strNameEN + " " + item.Element.strRelativeEN)</i></text> ),
grid.Column("Element.dtDOB", "DOB", item => item.Element.dtDOB != null ? item.Element.dtDOB.ToString("dd/MM/yyyy") : ""),
gri
@sphingu
sphingu / GetRealErrors.cs
Created June 18, 2013 09:33
How To See Validation Errors Details in MVC
// Get the Real error off the ModelState
var errors = GetRealErrors(ModelState);
private IEnumerable<ModelError> GetRealErrors(IEnumerable<KeyValuePair<string, ModelState>> modelStateDictionary)
{
var errorMessages = new List<ModelError>();
foreach (var keyValuePair in modelStateDictionary)
{
if (keyValuePair.Value.Errors.Count > 0)
{
@sphingu
sphingu / ReadableFileSize.cs
Created June 15, 2013 08:13
Readable File Size
public static String readableFileSized(long size)
{
long bytes = size;
string[] suf = { "B", "KB", "MB", "GB", "TB", "PB" };
int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
double num = Math.Round(bytes / Math.Pow(1024, place), 1);
string readable = num.ToString() + suf[place];
return readable;
}
@sphingu
sphingu / readXML.cs
Created June 15, 2013 07:53
Read Xml and bind to GridView
DataSet ds = new DataSet();
ds.ReadXml(MapPath("MyXML.xml"));
GridView1.DataSource = ds;
GridView1.DataBind();
@sphingu
sphingu / anotherThumbnail.cs
Last active December 18, 2015 13:08
Generate Image Thumbnail
//File Upload
// If file field isn’t empty
if (filUpload.PostedFile != null)
{
// Check file size (mustn’t be 0)
HttpPostedFile myFile = filUpload.PostedFile;
int nFileLen = myFile.ContentLength;
@sphingu
sphingu / NumericComparer.cs
Created June 15, 2013 07:19
Numeric Comparer for Sorting array numerically
public class NumericComparer : System.Collections.IComparer
{
public NumericComparer()
{ }
public int Compare(object x, object y)
{
if ((x is string) && (y is string))
{
return StringLogicalComparer.Compare((string)x, (string)y);
@sphingu
sphingu / BackUp_Restore.cs
Last active December 18, 2015 12:59
Generate Table Create Script Code Behind in C#
private void btnBackupWin_Click(object sender, RoutedEventArgs e)
{
try
{
if (_conSource != null && dgSource.Visibility==Visibility.Visible)
{
var dialog = new System.Windows.Forms.FolderBrowserDialog
{
Description = @"Select Folder to store backup file : "
};