public static void Add(ResPriceType respricetype) { using (pm2Entities entities = new pm2Entities()) { Res_PriceType type = bindEntity(respricetype, true); entities.AddToRes_PriceType(type); entities.SaveChanges(); } }
public static void Upadate(ResPriceType respricetype) { using (pm2Entities entities = new pm2Entities()) { if ((from m in entities.Res_PriceType where m.PriceTypeId == respricetype.Id select m).FirstOrDefault <Res_PriceType>() == null) { throw new Exception("找不到需要更新的价格类型"); } Res_PriceType type = bindEntity(respricetype, false); entities.SaveChanges(); } }
private static Dictionary <ResPriceType, decimal?> GetPrices(string id) { Dictionary <ResPriceType, decimal?> dictionary = new Dictionary <ResPriceType, decimal?>(); using (pm2Entities entities = new pm2Entities()) { foreach (Res_Price price in from p in entities.Res_Price where p.ResourceId == id select p) { ResPriceType byId = ResPriceType.GetById(price.PriceTypeId); dictionary.Add(byId, new decimal?(price.PriceValue)); } } return(dictionary); }
private static Res_PriceType bindEntity(ResPriceType respricetype, bool isAdd) { Res_PriceType type = new Res_PriceType { PriceTypeName = respricetype.Name, Note = respricetype.Note }; if (isAdd) { type.PriceTypeId = respricetype.Id; type.PriceTypeCode = respricetype.Code; type.InputUser = respricetype.InputUser; type.InputDate = respricetype.InputDate; type.UserCodes = JsonHelper.Serialize(respricetype.UserCodes.ToArray <string>()); } return(type); }
public static IList <ResPriceType> GetAll() { IList <ResPriceType> list = new List <ResPriceType>(); using (pm2Entities entities = new pm2Entities()) { foreach (Res_PriceType type in (from m in entities.Res_PriceType select m).ToList <Res_PriceType>()) { ResPriceType item = new ResPriceType { Id = type.PriceTypeId, Code = type.PriceTypeCode, Name = type.PriceTypeName, Note = type.Note, InputUser = type.InputUser, InputDate = type.InputDate, UserCodes = JsonHelper.GetListFromJson(type.UserCodes) }; list.Add(item); } } return(list); }
public static ResPriceType GetById(string id) { ResPriceType type = null; using (pm2Entities entities = new pm2Entities()) { Res_PriceType type2 = (from m in entities.Res_PriceType where m.PriceTypeId == id select m).FirstOrDefault <Res_PriceType>(); if (type2 != null) { type = new ResPriceType { Id = type2.PriceTypeId, Code = type2.PriceTypeCode, Name = type2.PriceTypeName, Note = type2.Note, InputUser = type2.InputUser, InputDate = type2.InputDate, UserCodes = JsonHelper.GetListFromJson(type2.UserCodes) }; } } return(type); }