Skip to content

Instantly share code, notes, and snippets.

View yicone's full-sized avatar

yicone

View GitHub Profile
@yicone
yicone / PagerProduct.cs
Created November 23, 2012 07:51
Do sort and pager for both IQueryable<T> and IEnumerable<T> meanwhile.
public class Foo
{
public virtual IEnumerable<Product> Page(IEnumerable<Product> list, Model.Pager pager)
{
IEnumerable<Product> b;
if (pager == null)
{
throw new ArgumentNullException("pager");
}
var q = list as IQueryable<Product>;
@yicone
yicone / EnumExtensions.cs
Created November 27, 2012 14:51
enum value map to string
/// <summary>
/// http://stackoverflow.com/questions/2787506/cast-string-to-enum-with-enum-attribute
/// todo: http://www.cnblogs.com/smalldust/archive/2006/04/25/384657.html 利用缓存优化
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string GetDescription(this Enum value)
{
if (value == null)
{
@yicone
yicone / Controller.js
Created December 3, 2012 08:27
MVC pattern applied in javascript (like ASP.NET MVC Style) http://www.cnblogs.com/yicone/archive/2010/08/17/1801125.html
/* construct */
function Controller() {
this.viewModel = new ViewModel();
}
/* public methods */
Controller.prototype.index = function () {
var controller = this;
controller._bindEventList();
};

业务人员的愿景

  • 客户在预定过程中会提出更换酒店的需求,由此带来客服人员的沟通成本的增加。
  • 产品经理设定航班时在售价和是否高端方面的两难抉择,希望能由客人来自行选择。

需求描述

客户在预定过程中:

  • 如果行程中的某一天,有可选酒店,客户可以根据偏好和价格进行选择。
  • 如果出发日、中转日、回程日,有可选航班,客户可以根据偏好和价格进行选择。

对领域模型的影响

@yicone
yicone / HtmlExtensions.cs
Created December 4, 2012 08:17
blog-ASP.NET MVC 3系列-引入ASP.NET Bundling and Minification机制
// http://stackoverflow.com/questions/13124218/asp-net-mvc-4-use-bundles-beneficts-for-url-content?rq=1
public static IHtmlString DynamicScriptsBundle( this HtmlHelper htmlHelper, string nombre, params string[] urls)
{
string path = string .Format("~/{0}", nombre);
if (BundleTable.Bundles.GetBundleFor(path) == null)
BundleTable.Bundles.Add(new ScriptBundle(path).Include(urls));
return Scripts .Render(path);
}
function foo(site, content, url, pic) {
var a = {
weibo: 'http://service.weibo.com/share/share.php?url={$url}&title={$content}&pic={$pic}',
tqq: 'http://v.t.qq.com/share/share.php?url={$url}&title={$content}&pic={$pic}',
renren: 'http://share.renren.com/share/buttonshare?link={$url}&title={$content}',
qzone: 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgiqzshareonekey?url={$url}&title={$content}&pics={$pic}'
};
var b = {
content: encodeURIComponent(content),
url: encodeURIComponent(url),
@yicone
yicone / SelectListFactory.cs
Created December 13, 2012 10:46
ASP.NET MVC
public class SelectListFactory
{
public static IEnumerable<SelectListItem> Create<TEnum, T>(bool addAll)
where TEnum : struct
where T : struct
{
if (!typeof(TEnum).IsEnum) throw new ArgumentException("Enum is required.", "TEnum");
if (typeof(T) != Enum.GetUnderlyingType(typeof(TEnum))) throw new ArgumentException("Enum's underlying type is required", "T");
var collection = Enum.GetValues(typeof(TEnum)).Cast<TEnum>();
@yicone
yicone / DateRange.cs
Last active December 10, 2015 22:08
DateRange and IntRange class. DateRange sample contains group "PriceRow" by date!
void Main()
{
List<PriceRow> prs = new List<PriceRow>{
new PriceRow{
BeginDate = DateTime.Now.Date,
EndDate = DateTime.Now.Date.AddDays(5),
Price = 5000,
},
new PriceRow{
BeginDate = DateTime.Now.Date.AddDays(1),
@yicone
yicone / CtripWS.cs
Last active December 11, 2015 21:18
FltIntlSearchFlights
namespace HHTravel.Base.Common.Framework.Web.CtripWSRef
{
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name = "CtripWSSoap", Namespace = "http://tempuri.org/")]
public partial class CtripWS : System.Web.Services.Protocols.SoapHttpClientProtocol
{
@yicone
yicone / gist:5001364
Last active December 14, 2015 00:49
这两段代码哪个好理解,没有if的那个吗
var list = query.ToList();
var list2 = query2.ToList();
List<string> idsWillRemove = new List<string>();
foreach (var p1 in list)
{
var p2 = list2.SingleOrDefault(plan2 => plan2.ShoppingInfoId == p1.ShoppingInfoId);
if (p2 == null)
{
idsWillRemove.Add(p1.ShoppingInfoId);
}