Created
June 19, 2013 13:51
-
-
Save sphingu/5d57c6587c1faa276d21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Install-Package EntityFramework | |
Update-Database -Verbose -Force | |
Enable-Migrations -EnableAutomaticMigrations -Force | |
Add-Migration //not compulsory | |
int | |
string | |
DateTime | |
byte[] for binary image | |
Guid | |
bool | |
Nullable<decimal> for money | |
Nullable<int> | |
Nullable<bool> | |
Nullable<DateTime> | |
//Foreign Key In Thins Table(Village Master) | |
public int intTalukaID { get; set; } | |
public virtual tbTalukaMaster tbTalukaMaster { get; set; } | |
//Primary Key Table(Taluka Master) | |
public tbTalukaMaster() | |
{ | |
this.tbVillageMasters = new List<tbVillageMaster>(); | |
} | |
public virtual ICollection<tbVillageMaster> tbVillageMasters { get; set; } | |
using System.ComponentModel.DataAnnotations; | |
[Required(ErrorMessage="Please Enter Village")] | |
[Display(Name="Village")] | |
[RegularExpression("pattern",ErrorMessage="Error in REGEX")] | |
[RegularExpression("^\\d{10}$",ErrorMessage="Please Enter Valid Mobile Number")] | |
[RegularExpression("^([0-9]{6})$",ErrorMessage="Please Enter Valid Pincode")] | |
[RegularExpression("^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$", ErrorMessage = "Please Enter Valid E-mail ID")] | |
[DataType(DataType.Date, ErrorMessage = "Please Enter date in 'DD/MM/YYYY' format")] | |
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)] | |
[DateOfBirth(MinAge = 1, MaxAge = 100, ErrorMessage = "Age Must Between 1 To 100")] | |
[ScaffoldColumn(false)] | |
using System.Data.Entity //use nuget >Install-Package EntityFramework if not available | |
public class EMPContext : DbContext | |
{ | |
public EMPContext(): base("Name=EMPContext") //name of connection string | |
{} | |
public DbSet<tbVillageMaster> tbVillageMasters {get;set;} | |
} | |
//in Web.Config | |
<add name="NPSContext" connectionString="Data Source=sumithingu\sqlexpress;Initial Catalog=NPS;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /> | |
//View | |
@using (Ajax.BeginForm("ChangeLimit", null, new AjaxOptions { UpdateTargetId = "transactionCreate", LoadingElementId = "loadingDiv", OnSuccess = "onSuccess" }, new { id = "transactionForm" })) | |
{} | |
//JS | |
var onSuccess = function (result) { | |
if (result.url) { | |
// if the server returned a JSON object containing an url | |
// property we redirect the browser to that url | |
window.location.href = result.url; | |
} | |
}; | |
//in Controller on success insert | |
return Json(new { url = Url.Action("Index", "Transaction") }); | |
//DropDown Bind | |
@{ | |
IEnumerable<NPS.Models.tbSubscriberMaster> agentList = BindExtension.GetSubscriberList(true); | |
@Html.DropDownListFor(model => model.intID, new SelectList(from o in agentList select new { o.ID, Name = o.strSurnameEN + " " + o.strNameEN }, "ID", "Name"), "-- Select Agent -- ") | |
} | |
//Other Dropdown Bind Way(Make Static class BindExtension in Helpers folder) | |
@Html.DropDownListFor(m => m.PaymentType, new SelectList(BindExtension.BindPaymentType(), "ID", "strType")) | |
//Grid View COlumn | |
grid.Column(format: item => Html.ActionLink("Change Limit", "ChangeLimit", "Transaction", new { id=item.ID }, new {id="linkChangeLimit", @class = "linkcss",@rel="facebox" })) | |
grid.Column("monHolding", "Cash Holding", @<text><div style="max-width: 100px;text-align:right;">@string.Format("{0:n}", item.monHolding)</div> </text>) | |
grid.Column("dtUpdatedOn", "Time", @<text>@item.dtUpdatedOn.ToString("H:mm:ss") </text>), | |
//Required Javascript file for Form | |
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script> | |
//Transfer to perticular url in Javascript | |
location.href="SubDetail/Index/1" | |
//Entity Framework Methods | |
.SingleOrDefault() | |
.First() | |
OrderByDescending() | |
//LINQ | |
From c in List Where !(from o in list2 select id).contains(c.ID) | |
//Important Scripts | |
$.ajax({ | |
url: this.href, | |
cache: false, | |
success: function (html) { | |
$("#mobileItems").append(html); | |
CheckMobileAddLink(); | |
window.setFontSize(); | |
} | |
}); | |
//date Picker Function | |
$(document).on('focus', '.clsDatePiker', function () { | |
$(this).datepicker({ dateFormat: 'dd/mm/yy' }); | |
}); | |
//Dynamic DropDown | |
$("#" + distid + " :selected").val(); | |
$.ajax({ | |
type: "GET", | |
contentType: "application/json; charset=utf-8", | |
url: '@Url.Action("TalukaList", "Subscriber")', | |
data: { "districtCode": id }, | |
dataType: "json", | |
beforeSend: function () { | |
//alert(id); | |
}, | |
success: function (data) { | |
var items = ""; | |
items += '<option value="">Select Taluka</option>'; | |
$.each(data, function (i, city) { | |
items += "<option value='" + city.Value + "'>" + city.Text + "</option>"; | |
}); | |
$('#' + talukaid).html(items); | |
var items = '<option value="">Select Village</option>'; | |
$('#' + villageid).html(items); | |
}, | |
error: function (result) { | |
alert('Service call failed: ' + result.status + ' Type :' + result.statusText); | |
} | |
}); | |
public JsonResult TalukaList(int districtCode) | |
{ | |
if (districtCode != 0) | |
{ | |
IEnumerable<tbTalukaMaster> talukas = BindExtension.BindTaluka(districtCode); | |
return Json(new SelectList(talukas.ToArray(), "ID", "strTalukaNameEN"), JsonRequestBehavior.AllowGet); | |
} | |
return Json(null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment