本文整理汇总了C#中System.Objects.ToEntity方法的典型用法代码示例。如果您正苦于以下问题:C# Objects.ToEntity方法的具体用法?C# Objects.ToEntity怎么用?C# Objects.ToEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Objects
的用法示例。
在下文中一共展示了Objects.ToEntity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public int Save(Objects.Company company)
{
if (company.CompanyId == -1)
context.Companies.Add(company.ToEntity());
else
{
Entity.Company cc = context.Companies.Find(company.CompanyId);
if (cc != null)
{
cc.CompanyDescription = company.CompanyDescription;
cc.CompanyIsActive = company.CompanyIsActive;
cc.CompanyLogo = company.CompanyLogo;
cc.CompanyName = company.CompanyName;
}
}
return context.SaveChanges();
}
示例2: Save
public int Save(Objects.Meta meta)
{
if (meta.MetaId == -1)
{
Entity.Meta entity = meta.ToEntity();
context.Metas.Add(entity);
if (context.SaveChanges() > 0)
{
foreach (Objects.MetaOption o in meta.Options)
entity.MetaOptions.Add(o.ToEntity());
return context.SaveChanges();
}
return -1;
}
else
{
Entity.Meta entity = context.Metas.Find(meta.MetaId);
if (entity != null)
{
entity.MetaNameEn = meta.MetaNameEn;
entity.MetaNameEs = meta.MetaNameEs;
context.SaveChanges();
StringBuilder sb = new StringBuilder();
sb.Append("<root>");
foreach (var op in meta.Options)
{
op.MetaId = entity.MetaId;
sb.Append(op.Xml);
}
sb.Append("</root>");
context.Database.ExecuteSqlCommand("EXEC dbo.usp_upd_MetaOptions @x",
new System.Data.SqlClient.SqlParameter("@x", sb.ToString()));
return 1;
}
return -1;
}
}
示例3: Save
public List<string> Save(Objects.Product product, List<Objects.ProductImage> images, List<Objects.ProductMeta> metas)
{
if (product.ProductId == -1)
{
Entity.Product entity = product.ToEntity();
context.Products.Add(entity);
if (context.SaveChanges() > 0)
{
if(images != null)
foreach (var i in images)
{
i.ProductId = entity.ProductId;
entity.ProductImages.Add(i.ToEntity());
}
if(metas != null)
foreach (var m in metas)
{
m.ProductId = entity.ProductId;
entity.ProductMetas.Add(m.ToEntity());
}
int rt = context.SaveChanges();
if (rt == 0)
return new List<string>();
else
return new List<string>(new string[] { "Failed" });
}
}
else
{
Entity.Product entity = context.Products.Find(product.ProductId);
if (entity != null)
{
entity.CategoryId = product.CategoryId;
entity.CompanyId = product.CompanyId;
entity.ProductDescriptionEn = product.ProductDescriptionEn;
entity.ProductDescriptionEs = product.ProductDescriptionEs;
entity.ProductIsActive = product.ProductIsActive;
entity.ProductNameEn = product.ProductNameEn;
entity.ProductNameEs = product.ProductNameEs;
entity.ProductPrice = product.ProductPrice;
entity.ProductRetailPrice = product.ProductRetailPrice;
context.SaveChanges();
//Clear images
entity.ProductImages.Clear();
context.SaveChanges();
if (images != null)
foreach (var i in images)
{
i.ProductId = entity.ProductId;
entity.ProductImages.Add(i.ToEntity());
}
context.SaveChanges();
//Do Metas proc
StringBuilder sb = new StringBuilder();
sb.Append("<root>");
foreach(var m in metas)
{
m.ProductId = entity.ProductId;
sb.Append(m.Xml);
}
sb.Append("</root>");
var value = context.Database.SqlQuery<string>("EXEC usp_upd_ProductMeta @x",
new System.Data.SqlClient.SqlParameter("@x", sb.ToString()));
return value.ToList();
}
}
return new List<string>(new string[] { "Failed" });
}
示例4: SaveOption
public int SaveOption(Objects.MetaOption option)
{
if (option.MetaOptionId == -1)
{
context.MetaOptions.Add(option.ToEntity());
return context.SaveChanges();
}
else
{
Entity.MetaOption entity = context.MetaOptions.Find(option.MetaOptionId);
if (entity != null)
{
entity.MetaOptionNameEn = option.MetaOptionNameEn;
entity.MetaOptionNameEs = option.MetaOptionNameEs;
entity.MetaOptionValue = option.MetaOptionValue;
return context.SaveChanges();
}
return -1;
}
}