本文整理汇总了C#中Distributr.Core.Data.EF.CokeDataContext.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# CokeDataContext.SaveChanges方法的具体用法?C# CokeDataContext.SaveChanges怎么用?C# CokeDataContext.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Distributr.Core.Data.EF.CokeDataContext
的用法示例。
在下文中一共展示了CokeDataContext.SaveChanges方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateExfactory
private void UpdateExfactory(Guid productId,decimal exf)
{
using (var ctx = new CokeDataContext(Con))
{
var prod = ctx.tblProduct.FirstOrDefault(p => p.id == productId);
if(prod !=null && prod.ExFactoryPrice==0m)
{
try
{
ctx.tblProduct.FirstOrDefault(p => p.id == productId).ExFactoryPrice=exf;
ctx.SaveChanges();
}
catch
{
}
}
}
}
示例2: AddUserGroup
Guid AddUserGroup(string name)
{
using (var ctx = new CokeDataContext(Con))
{
tblUserGroup group=null;
group = ctx.tblUserGroup.FirstOrDefault(p => p.Name.ToLower() == name.ToLower());
if (group == null)
{
group = new tblUserGroup
{
Id = Guid.NewGuid(),
Description = name,
Name = name,
IM_DateCreated = DateTime.Now,
IM_DateLastUpdated = DateTime.Now,
IM_Status = (int) EntityStatus.Active
};
ctx.tblUserGroup.AddObject(group);
ctx.SaveChanges();
AddUserGroupRoles(group.Id);
}
return group.Id;
}
}
示例3: Insert
private void Insert(tblShipToAddress dto)
{
using (var ctx = new CokeDataContext(Con))
{
ctx.tblShipToAddress.AddObject(dto);
ctx.SaveChanges();
}
}
示例4: GetVATClass
private tblVATClass GetVATClass(string vatNameCode)
{
using (var ctx = new CokeDataContext(Con))
{
tblVATClass vatClass = null;
if (!string.IsNullOrEmpty(vatNameCode))
{
vatClass = ctx
.tblVATClass.FirstOrDefault(
p => p.Class != null &&
p.Class.ToLower() == vatNameCode.ToLower() ||
p.Name != null && p.Name.ToLower() == vatNameCode.ToLower());
}
//if (vatClass == null)
// vatClass = ctx.tblVATClass.FirstOrDefault(p => p.Class == "default");
if (vatClass == null)
{
return null;
var item = new tblVATClass()
{
Class = "default",
Name = "default",
id = Guid.NewGuid(),
IM_DateCreated = DateTime.Now,
IM_DateLastUpdated = DateTime.Now,
IM_Status = (int) EntityStatus.Active,
tblVATClassItem = new EntityCollection<tblVATClassItem>()
{
new tblVATClassItem()
{
id = Guid.NewGuid(),
Rate = 0m,
EffectiveDate = DateTime.Now,
IM_DateCreated = DateTime.Now,
IM_DateLastUpdated = DateTime.Now,
IM_Status = (int) EntityStatus.Active
}
}
};
ctx.tblVATClass.AddObject(item);
ctx.SaveChanges();
}
return vatClass;
}
}
示例5: GetOutletType
private tblOutletType GetOutletType(string outlettypeCode)
{
using (var ctx = new CokeDataContext(Con))
{
tblOutletType outletType = null;
if (!string.IsNullOrEmpty(outlettypeCode))
{
outletType = ctx
.tblOutletType.FirstOrDefault(
p => p.Code != null &&
p.Code.ToLower() == outlettypeCode.ToLower() ||
p.Name != null && p.Name.ToLower() == outlettypeCode.ToLower());
}
if(outletType==null)
outletType = ctx.tblOutletType.FirstOrDefault(p => p.Code == "default");
if(outletType==null)
{
var item = new tblOutletType()
{
Code = "default",
Name = "default",
id = Guid.NewGuid(),
IM_DateCreated = DateTime.Now,
IM_DateLastUpdated = DateTime.Now,
IM_Status = (int)EntityStatus.Active
};
ctx.tblOutletType.AddObject(item);
ctx.SaveChanges();
}
return outletType;
}
}
示例6: GetCommodityType
private tblCommodityType GetCommodityType(string name)
{
using (var ctx = new CokeDataContext(Con))
{
tblCommodityType productType = null;
if (!string.IsNullOrEmpty(name))
{
productType = ctx
.tblCommodityType.FirstOrDefault(
p =>
p.Name.ToLower() == name.ToLower() ||
p.Code != null &&
p.Code.ToLower() == name.ToLower());
}
if (productType == null)
{
productType = ctx.tblCommodityType.FirstOrDefault(p => p.Name.ToLower() == "default");
if (productType == null)
{
productType = new tblCommodityType()
{
Id = Guid.NewGuid(),
Name = string.IsNullOrEmpty(name) ? "default" : name,
Description = string.IsNullOrEmpty(name) ? "default" : name,
Code = string.IsNullOrEmpty(name) ? "default" : name,
IM_DateCreated = DateTime.Now,
IM_Status = (int) EntityStatus.Active,
IM_DateLastUpdated = DateTime.Now
};
ctx.tblCommodityType.AddObject(productType);
ctx.SaveChanges();
}
}
return productType;
}
}
示例7: GetPackagingType
private tblProductPackagingType GetPackagingType(string itemName)
{
using (var ctx = new CokeDataContext(Con))
{
tblProductPackagingType pitem = null;
if (!string.IsNullOrEmpty(itemName))
pitem = ctx
.tblProductPackagingType.FirstOrDefault(
p =>
p.name.ToLower() == itemName.ToLower() ||
p.code != null &&
p.code.ToLower() == itemName.ToLower());
if (pitem == null)
{
pitem = ctx.tblProductPackagingType.FirstOrDefault(p => p.name.ToLower() == "default");
if (pitem == null)
{
pitem = new tblProductPackagingType()
{
id = Guid.NewGuid(),
name = string.IsNullOrEmpty(itemName) ? "default" : itemName,
code = string.IsNullOrEmpty(itemName) ? "default" : itemName,
IM_DateCreated = DateTime.Now,
IM_Status = (int) EntityStatus.Active,
IM_DateLastUpdated = DateTime.Now,
};
ctx.tblProductPackagingType.AddObject(pitem);
ctx.SaveChanges();
}
}
return pitem;
}
}
示例8: GetProductBrand
private tblProductBrand GetProductBrand(string itemName)
{
using (var ctx = new CokeDataContext(Con))
{
tblProductBrand pitem = null;
if (!string.IsNullOrEmpty(itemName))
pitem = ctx
.tblProductBrand.FirstOrDefault(
p =>
p.name.ToLower() == itemName.ToLower() ||
p.code != null &&
p.code.ToLower() == itemName.ToLower())??ctx
.tblProductBrand.FirstOrDefault(
p =>
p.name.ToLower()=="default");
if(pitem==null)
{
var date = DateTime.Now;
var supp = ctx.tblSupplier.FirstOrDefault(p => p.Code == "default");
if(supp==null)
{
supp=new tblSupplier()
{
Name = "default",
Code = "default",
Description = "default",
IM_Status = (int)EntityStatus.Active,
id = Guid.NewGuid(),
IM_DateCreated = date,
IM_DateLastUpdated = date
};
ctx.tblSupplier.AddObject(supp);
ctx.SaveChanges();
}
pitem = new tblProductBrand()
{
IM_Status = (int) EntityStatus.Active,
id = Guid.NewGuid(),
name = string.IsNullOrEmpty(itemName) ? "default" : itemName,
description = string.IsNullOrEmpty(itemName) ? "default" : itemName,
code = string.IsNullOrEmpty(itemName) ? "default" : itemName,
SupplierId = supp.id,
IM_DateCreated = date,
IM_DateLastUpdated = date
};
ctx.tblProductBrand.AddObject(pitem);
ctx.SaveChanges();
}
return pitem;
}
}
示例9: GetProductFlavour
private tblProductFlavour GetProductFlavour(string itemName,tblProductBrand brand)
{
using (var ctx = new CokeDataContext(Con))
{
tblProductFlavour pitem = null;
if (!string.IsNullOrEmpty(itemName))
{
pitem = ctx
.tblProductFlavour.FirstOrDefault(
p =>
p.name.ToLower() == itemName.ToLower() ||
p.code != null &&
p.code.ToLower() == itemName.ToLower()) ?? ctx.tblProductFlavour.FirstOrDefault(
p => p.name.ToLower() == "default");
}
if(pitem==null)
{
var date = DateTime.Now;
pitem = new tblProductFlavour()
{
BrandId = brand.id,
id = Guid.NewGuid(),
code = string.IsNullOrEmpty(itemName) ? "default" : itemName,
description = string.IsNullOrEmpty(itemName) ? "default" : itemName,
IM_DateCreated = date,
IM_DateLastUpdated = date,
name = string.IsNullOrEmpty(itemName) ? "default" : itemName,
};
ctx.tblProductFlavour.AddObject(pitem);
ctx.SaveChanges();
}
return pitem;
}
}
示例10: AdjustInventory
private void AdjustInventory()
{
string conn = ConfigurationManager.AppSettings["pzcussons_inventory"];
using (var ctx = new CokeDataContext(conn))
{
using (var c = NestedContainer)
{
Using<IAdjustInventoryWindow>(c).ShowAdjustDialog();
if(AdjustQuantity>0m)
{
try
{
var products = ctx.tblProduct.Select(p => p.id).ToList();
if(products.Any())
{
DateTime date = DateTime.Now;
var wareHouse = ctx.tblCostCentre.FirstOrDefault(p => p.Cost_Centre_Code == "PZ Cussons EA");
if(wareHouse==null)
{
const string error = "Something bad has happened while adjusting inventory..there is no warehouse";
MessageBox.Show(error);
FileUtility.LogError(error);
return;
}
foreach (var productId in products)
{
var inventory = ctx.tblInventory.FirstOrDefault(p => p.ProductId == productId);
if(inventory==null)
{
inventory = new tblInventory()
{
id=Guid.NewGuid(),
IM_DateCreated = date,
IM_DateLastUpdated = date,
IM_Status = (int)EntityStatus.Active,
};
ctx.tblInventory.AddObject(inventory);
}
inventory.Balance += AdjustQuantity;
inventory.ProductId = productId;
inventory.WareHouseId = wareHouse.Id;
inventory.Value = 0;
}
ctx.SaveChanges();
}
MessageBox.Show(string.Format("Inventory adjustment success=>{0} product adjusted with{1}",products.Count,AdjustQuantity));
}
catch (Exception e)
{
var error = e.Message
+
(e.InnerException == null
? ""
: "\n" + e.InnerException);
MessageBox.Show("Something bad has happened while adjusting inventory..see logs for details");
FileUtility.LogError(error);
}
}
}
}
}